[Python-ideas] 'where' statement in Python?
Andrey Popp
8mayday at gmail.com
Wed Jul 21 08:23:40 CEST 2010
Hello,
On Wed, Jul 21, 2010 at 2:48 AM, Antoine Pitrou <solipsis at pitrou.net> wrote:
> I'll add another issue:
>
> - currently, lexical blocks (indentation following a colon) are used
> for control flow statements; this proposal blurs the line and makes
> visual inspection less reliable
Do class definitions or with-statements represent control flow
structures? I think, no (with-statement maybe).
> I also disagree with the rationale which states that the motivation
> is similar to that for decorators or list comprehensions. Decorators
> and list comprehensions add value by making certain constructs more
> concise and more readable (by allowing to express the construct at a
> higher level through the use of detail-hiding syntax); as for
> decorators, they also eliminate the need for repeating oneself. Both
> have the double benefit of allowing shorter and higher-level code.
Consider the following:
...
value = a*x*x + b*x + c given:
a = compute_a()
b = compute_b()
c = compute_c()
...
which is roughly equivalent to
...
a = compute_a()
b = compute_b()
c = compute_c()
value = a*x*x + b*x + c
...
with two differences:
- It emphasizes that `value` is a target of this computation and `a`,
`b` and `c` are just auxiliary.
- It states that `a`, `b` and `c` are only used in statement, before
the `given` keyword, that would help future refactorings.
Due to the second point, it can't be considered as syntactic sugar.
Is is more readable? I think yes.
--
Andrey Popp
phone: +7 911 740 24 91
e-mail: 8mayday at gmail.com
More information about the Python-ideas
mailing list