PEP 308: Discussion Summary

Bengt Richter bokr at oz.net
Sat Feb 22 10:58:38 EST 2003


On Thu, 20 Feb 2003 07:48:52 -0800, David Eppstein <eppstein at ics.uci.edu> wrote:

>In article <m2znorz2td.fsf at mycroft.actrix.gen.nz>,
> Paul Foley <see at below.invalid> wrote:
>
>> I made a similar suggestion: [cond1 -> expr1; cond2 -> expr2; ...] a
>> week or so ago.
   IMO '->' is easy to read and understand, but I would change semicolon to
something else, like a 2-dot ellipsis, e.g.,

    [cond1 -> expr1 .. cond2 -> expr2 .. cond3 -> expr3]

A default can be handled by ".. True -> default" at the end, and I think
the ".. True" part of that could be implicit if desired, so that you
could write the ternary concisely as

    [cond1 -> expr1 -> default]

instead of

    [cond1 -> expr1 .. True -> default]

Of course, the square brackets would be syntactic sugar in many cases,
so perhaps they could be optional parens instead.

    (cond1 -> expr1 -> default)

>> 
>> I think using commas to separate the clauses is a bad idea; semicolons
>> work much better, and "->" is more a obvious choice than ":".  There's
>> no need for a "default" value (I'd raise an exception if none of the
>> conditions are met)
>
>Semicolons are overloaded.  If you're going to do something like this, 
>|| (double vertical bar) might be better for expressing the disjunctive
It's disjunctive, but it's also a sequence of condition->expression pairs,
and IMO a 2-dot ellipsis can suggest the sequence aspect.

>nature of the expression while having some visual similarity to Hoare's 
>CSP notation.  Also while Hoare used square brackets I think that would 
>be a mistake here, just use parens (don't make them part of the 
>notation, but set precedence of the operators low enough that they'd be 
>necessary in most contexts).
>
>I'd vote against this, anyway, by the way: from an elegance of design 
>point of view I like CSP but from a readability point of view I don't 
>think it works.
>
Sometimes minor details make a big difference in readability. I.e.,
'..' kind of lies low .. and makes the rest more visible ;-)

Regards,
Bengt Richter




More information about the Python-list mailing list