seeking deeper (language theory) reason behind Python design choice

Mikhail V mikhailwas at gmail.com
Thu May 10 14:41:23 EDT 2018


On Wed, May 9, 2018 at 8:50 AM, Chris Angelico <rosuav at gmail.com> wrote:
> On Wed, May 9, 2018 at 3:36 PM, Ian Kelly <ian.g.kelly at gmail.com> wrote:
>>
>> while True:
>>     if we_are_done():
>>         break
>>     # do some stuff
>>     ...
>>     if error_occurred():
>>         break
>> notify_user()
>>
>>
>> Fixed, using idiomatic Python and without needing to use assignment in
>> an expression.
>
> Why is it that "while True" is idiomatic Python for a non-infinite
> loop? Is it merely because Python currently has no other way to spell
> certain loops? Surely it would be more idiomatic to encode the loop's
> termination condition in the header, if it were possible.

Don't know about 'idiomatic', but the above spelling is exactly what i
tend to use lately for almost all loops. It noticeably reduces cognitive load.
Though lately more often i prefer "while 1:" so it makes
the nodes more lightweight and distinct from the rest lines.
And not even official declaration of "idiomatic" as something else will
make me switch back.



More information about the Python-list mailing list