for / while else doesn't make sense

Jon Ribbens jon+usenet at unequivocal.co.uk
Sun May 22 11:52:40 EDT 2016


On 2016-05-22, Steven D'Aprano <steve at pearwood.info> wrote:
> On Mon, 23 May 2016 12:15 am, Jon Ribbens wrote:
>> 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.
>
> How is this any better though? Complicated or not, people want to divide 1
> by 2 and get 0.5. That is the functional requirement. Furthermore, they
> want to use the ordinary division symbol / rather than having to import
> some library or call a function.

That's a circular argument. You're defining the result as the
requirement and then saying that proves the result is necessary.
Clearly, people managed when 1/2 returned 0, and continue to do so
today in Python 2 and other languages.

> Having 1/2 return 0 (as Python 2 does by default) doesn't make the
> language any less complicated. It doesn't avoid the complexity of
> floats, it merely breaks the principle of least surprise,

No, it *adheres* to the principle of least surprise. Floats appearing
out of nowhere is surprising. Python 2's behaviour adhered to the
principle, and Python 3's breaks it.

>> 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.
>
> And how does forcing them to write 1.0/2 solve that?

Because it forces them to consciously address the fact that they are
asking for, and getting, floats, and that floats are not something
the language is willingly to silently foist upon them.

>> Programming languages should do what they are told, and very little
>> more.
>
> Okay, now I'm confused. How is 1/2 returning 0.5 the language not doing what
> you've told it to do?

I didn't ask for floats, I got floats. That's how.

>> 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.
>
> How are they uncalled for? 

By... not being called for? I must admit I don't entirely understand
your question.



More information about the Python-list mailing list