for -- else: what was the motivation?

Axy axy at declassed.art
Sun Oct 9 01:04:12 EDT 2022


On 09/10/2022 05:47, Chris Angelico wrote:
> On Sun, 9 Oct 2022 at 15:39, Axy via Python-list <python-list at python.org> wrote:
>> Got it, thanks!
>>
>> Actually the reason I never used "else" was the violation of the rule of
>> beauty "shortest block first". With if--else you can easily follow this
>> rule by inverting "if" expression, but with for--else you can't. The
>> loop body of the simplest example is already three lines, in real life
>> things are much worse.
>>
> That's not a rule I've ever been taught; how important is it?
>
> ChrisA

It gets important if the lifetime of your project is more than three 
months and is extremely important if more than 10 years. But, it depends.

I also might be wrong in terminology, anyway, there are many rules that 
make programmer's life easier, described in the literature from the old 
good "How to write unmaintainable code" to "The Art of Readable Code". 
And I hope there are a lot of recent books on this subject I did not 
track and read yet.

Axy.


More information about the Python-list mailing list