Division considered un-Pythonic (Re: Case-sensitivity: why -- or why not? (was Re: Damnation!))

Martijn Faassen m.faassen at vet.uu.nl
Tue May 30 07:04:50 EDT 2000


Greg Ewing <greg at cosc.canterbury.ac.nz> wrote:
[snip]
> I assume that no-one would disagree with the following statements:

> 1. Integer division and real (or rational, if you prefer) division
>    are different operations.

Question: why does nobody complain about the overloading of the '+' 
operator? After all, it works on both strings and numbers; and presumably
your code will fall apart at unsuspected points as well if you assume it
only deals with numbers. :)

Perhaps the difference is that it falls apart with an *exception*, instead
of silently creating the wrong thing (an int). This would indicate that
perhaps we need an exception raised _as soon as_ you try to divide a 
float with an integer or an integer with a float. So raising an exception
could be an alternative solution, it seems (but also not a solution one
could easily introduce without breaking backwards compatibility).

> 2. Whenever you write a division operation into your code, you
>    always know which one you want.

Perhaps not, if you're writing generic code. Though it's hard to come up
with an example, I must admit. :)

Regards,

Martijn
-- 
History of the 20th Century: WW1, WW2, WW3?
No, WWW -- Could we be going in the right direction?



More information about the Python-list mailing list