One-liner blocks (was Re: accessing a functions var from a subfunction.)

Alex Martelli aleax at aleax.it
Thu Apr 17 12:58:58 EDT 2003


Courageous wrote:

> 
>>Having MTOWTDI ain't Pythonic.  The ability to write either:
>>
>>    if finished: break
>>
>>OR quite equivalently
>>
>>    if finished:
>>        break
>>
>>is therefore a wart.
> 
> Hrm. Conceputalization? I consider these two equivalent. I suppose

They ARE -- I DID say "quite equivalently" in the snippet you
just quoted.  But, ones can be seen as conceptualizing the
"guarded break" as a single unit, the other twists the knife
in the wound of the fact that there IS no such single unit, so
that the if and the break are, alas, separate statements.

> it's bias. Years of using languages where WSDM (white spaces don't
> matter), allows me to elide away some under some circumstances. :)

Sure -- that's just like saying that:

    if x > 23:

and

    if 23 < x:

are fully equivalent at a reasonable level of abstraction.  Of
course they are.  But most people are more used to the first form
(variable-operator-constant appears to be a more ofter used
sequence than constant-operator-variable) so they may read it
more smoothly, while the second form requires a fraction of a
second's worth of attention -- just because it's very slightly
less usual, not because of any intrinsic difference.


> BTW, there's a thing I do in some programming environments, that
> I personally really like to do, but I see few other people do. I'll
> show you:
> 
> if (alpha)       { DoSomething();        return x; }
>     if (beta)        { DoSomethingElse();    return y; }
>     if (delta)       { DoOtherThing();       return z; }
> 
> I like to use *columns*, in other words. I find this to be neat and
> readible, and considerably superior to what would otherwise pass as
> the defacto alternative.
> 
> I think you'll see how the example applies to the thread's subject...

Of course (though it definitely doesn't apply to Python!-).


Alex





More information about the Python-list mailing list