integer >= 1 == True and integer.0 == False is bad, bad, bad!!!

Chris Kaynor ckaynor at zindagigames.com
Mon Jul 12 23:16:47 EDT 2010


On Mon, Jul 12, 2010 at 7:14 PM, Paul Rubin <no.email at nospam.invalid> wrote:

> Ian Kelly <ian.g.kelly at gmail.com> writes:
> > I don't think it's any more egregious than automatic conversions of
> > mixed-type expressions, such as 3 + 4.5.
>
> That could also be explicit: float(3) + 4.5, or 3 + int(4.5).
>
> > If you don't want your ints automatically converted to floats on
> > division, then use the integer division operator.  1 // 2 is still 0
> > in Python 3.
>
> Sure, I do that, but the issue was that 1/2 was confusing newbies who
> don't understand the different characteristics of int and floating
> types.  If the idea is to change Python to fix this problem in a
> newbie-friendly way, the right fix is to create enlightment by raising
> an exception that points out the problem, not sweep it under the rug
> with an automatic conversion.
>

Behind this automatic conversion is the concept that there is really one
type: Number. The fact that the language has both int and float is merely as
there is no good, solid way of storing the Number type, and thus we have
float, Decimal, Rational, and probably other less common types. Calculating
1/2 does not give you 0, 1/10 won't give you 0.100000001 (or whatever the
number stored in float is). The fact that integers and real numbers
are separate in the language is an optimization and intended to improve
functionality while providing a simple default (you can choose to use
Decimal instead of float if you know you will be dealing with decimal
numbers).

Chris


> --
> http://mail.python.org/mailman/listinfo/python-list
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20100712/88c1a15f/attachment-0001.html>


More information about the Python-list mailing list