[Python-ideas] for/else statements considered harmful
jeanpierreda at gmail.com
Thu Jun 7 14:01:52 CEST 2012
On Thu, Jun 7, 2012 at 6:50 AM, Stephen J. Turnbull <stephen at xemacs.org> wrote:
> There was a long thread about a year ago on this list, where a couple
> of less experienced programmers and even a couple of people who have
> long since proven themselves reliable, gave code examples that
> obviously hadn't been tested.<wink/>
This is disappointing. for-else is simple, even if it has an ambiguous name.
> The reason they make such mistakes is that there's a strong
> association of "else" with "if-then-else", and for many people that
> seems to be somewhere between totally useless and actively misleading.
I know it's really bad form to shift goalposts, but I can't help but
offer an alternative hypothesis: What if it isn't that else is
confusing, but that use of else is rare? People have lots of silly
beliefs about things they never use, or haven't used in a very long
> For me, there are a number of reasonable mnemonics, a couple given in
> this thread, but IIRC the only idiom I found really plausible was
I think of "else" as a collective/delayed else to the if statement in
the body of the loop (which is almost always present). This only works
for for loops though.
Pretty much every single for-else has almost exactly the same form,
though, so... it's pretty easy to use specialized models like that. :)
More information about the Python-ideas