[Numpy-discussion] Re: numpy, overflow, inf, ieee, and rich comparison

Marcin 'Qrczak' Kowalczyk qrczak at knm.org.pl
Fri Oct 27 13:50:31 EDT 2000


Fri, 27 Oct 2000 17:41:18 +1300, Greg Ewing <see at my.signature> pisze:

> Whenever I write a division in my code, I know which one I want.
> But the only way I can tell Python which one to use is indirectly,
> by manipulating the types of operands I feed to the / operator.
> 
> To me, this is so obviously wrong that I can't understand
> how any serious programmer could think it was right.

I agree. A coincidence of Python's features makes this especially bad:

Integers are promoted to floats implicitly. There are almost no places
when such explicit conversion changes the result, so people learn that
it is not necessary. This applies both to conversion of expressions
and to using integer literals as floating point constants. Division
is one of these places where it is necessary.

Variables don't have types. That's why the above feature is not as
bad in languages like C, where the conversion is often done by passing
the value through a variable of a floating point type.

gnuplot is a program which does this like Python and it is IMHO bad and
confusing. It draws plots of real number functions. Usually the user
may ignore the fact that integers are treated in a different way. But
    11/4*x + 2*x*log(2/(5*x))
is wrong and he has to write 11.0/4.0*x. Other constants here do
work. It's easy to forget that constant divisions must be explicitly
floatified, because integers work well as floating point values in
other places.

It's bad to have a rule that something works almost always.

-- 
 __("<  Marcin Kowalczyk * qrczak at knm.org.pl http://qrczak.ids.net.pl/
 \__/
  ^^                      SYGNATURA ZASTĘPCZA
QRCZAK



More information about the Python-list mailing list