for -- else: what was the motivation?

Chris Angelico rosuav at gmail.com
Sun Oct 9 12:29:00 EDT 2022


On Mon, 10 Oct 2022 at 03:22, Avi Gross <avi.e.gross at gmail.com> wrote:
>
> Smallest code blocks first may be a more modern invention.
>
> Some would argue for a rule related to efficiency of execution. When you
> have multiple blocks as in an if-else or case statement with multiple
> choices, that you order the most common cases first. Those shorten
> execution more often than the rarer cases especially the ones that should
> never happen.
>

Seems fairly dubious and full of special-cases. If you want to follow
that rule, it should be easy enough to still permit for-else clauses.
It's an extremely weak argument against for-else.

ChrisA


More information about the Python-list mailing list