"also" to balance "else" ?

Terry Hancock hancock at anansispaceworks.com
Wed Jun 15 14:30:40 EDT 2005


On Wednesday 15 June 2005 03:57 am, Fredrik Lundh wrote:
> where your "abnormal behaviour" is, of course, the expected
> behaviour.  if you insist on looking at things the wrong way,
> things will look reversed.

Unfortunately, the converse is true, too: no matter how twisted
an idea is, you can make it seem logical with the right point
of view. ;-)

I think the OP is correct in saying that for-else is non-intuitive.

Your use case is the only one in which "else" makes sense, IMHO,
and that's only because it reflects the overall meaning of the
algorithm, not because it actually reflects what's going on in
the syntax.

If "finally" is wrong (and I see your point there), then maybe
"normally" is the right thing to call it?  After all, it's the opposite
of the "exception" case, which is probably the "normal" case.

The fact that, in a search algorithm, the exception case is the
normal result, and the syntactically normal case is the exception
just confuses the issue.  The question is, how difficult is it for
the person reading the code to understand what was written?

Now of course, a person skilled in language X will understand
the syntax even if all the keywords are unintelligible
gibberish, and from that PoV, it will surely make sense. But
I get the impression that Python is *trying* to use words with
the right inuitive meaning in the interest of helping newbies.

I *personally* can get my head around "for-else" and use it
if I really need it, but I agree that it could be spelled better.

OTOH, I see no reason for an opposite construct, since, as you
and others have pointed out, that can be handled by the if
in the loop or by an exception handler.

--
Terry Hancock ( hancock at anansispaceworks.com )
Anansi Spaceworks  http://www.anansispaceworks.com




More information about the Python-list mailing list