for -- else: what was the motivation?
dn
PythonList at DancesWithMice.info
Wed Oct 12 22:00:20 EDT 2022
On 11/10/2022 02.13, Grant Edwards wrote:
> On 2022-10-10, Chris Angelico <rosuav at gmail.com> wrote:
>> On Mon, 10 Oct 2022 at 11:52, MRAB <python at mrabarnett.plus.com> wrote:
>>>
>>> On 2022-10-10 00:40, dn wrote:
>>>> On Sun, 9 Oct 2022 at 15:39, Axy via Python-list
>>>> <python-list at python.org> wrote:
>>>>
>>>>> "shortest block first"
>>>>
>>>> Have never heard this advice before. Kind-of rankled with me, as it did
>>>> for others.
>
> I've followed that advice for several decades. I find it much easier
> to read code that's organized that way -- particularly when the
> difference in block sizes is large (e.g. the first block is one line,
> and the second is a a hundred).
Makes sense. Keep the 'cause' and 'effect' close together. In other
words, making it easy to look 'up' from one of the 'suites' to see the
if-statement/condition which directs that logic-branch.
Contrarily, (see @Karsten, earlier) the preference to bundle the
"hundred" into one or more functions, rather than present as a 'wall of
text'. Added advantage: well-chosen function names(!) will remind the
reader of the purposes(!) of the "hundred".
Once both suites are short[ened], visibility improves (readability), and
the above contention goes-away. Thus the sense of the condition becomes
the most worthy consideration.
--
Regards,
=dn
More information about the Python-list
mailing list