for / while else doesn't make sense

Jon Ribbens jon+usenet at unequivocal.co.uk
Sun May 22 10:15:35 EDT 2016


On 2016-05-21, Chris Angelico <rosuav at gmail.com> wrote:
> On Sat, May 21, 2016 at 10:35 AM, Jon Ribbens
><jon+usenet at unequivocal.co.uk> wrote:
>> To be fair, I'm very sympathetic to that argument. I think programming
>> languages should never magically produce floats out of nowhere unless
>> the programmer has explicitly done "import float" or "float('3.23')"
>> or somesuch. They're misunderstood so often that any convenience
>> they provide is outweighed by the danger they bring.
>>
>> "(1/10) * (1/10) * 10 != (1/10)" anyone? I was distinctly unhappy with
>> the Python 3 "2/3 ~= 0.6666" thing and regard it as a very retrograde
>> change.
>
> The trouble is, what SHOULD 2/3 return?
>
> * An integer? Makes a lot of sense to a C programmer. Not so much to
> someone who is expecting a nonzero value. This isn't terrible (hey,
> Python 2 managed with it no problem), but will definitely confuse a
> number of people.

Yes, it should return an integer - and not because I think Python
should behave like C on principle, but because:

        Explicit is better than implicit.
        Simple is better than complex.
        Complex is better than complicated.

and floats are complicated.

> * A float? That's what we currently have. Not perfect, but it's going
> to confuse less people than 0 will.

That's a trap for those people though - it lulls them into thinking
that they understand what's going on, when in fact they don't,
because they don't understand floats, because almost nobody
understands floats. So they don't understand their program, and
- even worse - they don't know that they don't understand it.

Programming languages should do what they are told, and very little
more. They should not wander off on surprising jaunts of their own
invention out of the control of the programmer. It should be possible
to know and understand the language, or at least the subset of it
that you are likely to need for your everyday purposes. Floats are
generally not understood, so they shouldn't be suddenly turning up
un-called for.

Python generally sticks to this idea very well, which is one of the
things that I think make it an excellent programming language, so it
is a shame that in the Python 2 to Python 3 change when mistakes were
being rectified, a new one was introduced.



More information about the Python-list mailing list