PEP-xxx: Unification of for statement and list-comp syntax
Edward Elliott
nobody at 127.0.0.1
Sun May 21 18:10:31 EDT 2006
George Sakkis wrote:
> Em Dom, 2006-05-21 às 17:11 +0200, Heiko Wundram escreveu:
>> for node in tree if node.haschildren():
>> <do something with node>
>>
>> as syntactic sugar for:
>>
>> for node in tree:
>> if not node.haschildren():
>> continue
>> <do something with node>
[snip]
>
> 2) "There should be one and preferably only one way to do it."
You mean like this:
s = "foo" + "bar"
s = 'foo' + 'bar'
s = 'foo' 'bar'
s = '%s%s' % ('foo', 'bar')
This one and only one way stuff is overrated. I don't care how many ways
there are as long as:
1. at least one way is intuitive
2. every way is easily comprehendible (readable, no side effects, etc)
Now 'one way to do it' is a good mantra for keeping language complexity down
and achieving the second goal. But it needs to be flexible. The proposed
syntax is short, intuitive, and consistent with comprehension/generator
syntax. I'd say it's entirely in keeping with a number of rules which
trump 'one way':
Beautiful is better than ugly.
Flat is better than nested.
Readability counts.
Special cases aren't special enough to break the rules. (proposal eliminates
the current special case for comprehensions/generators)
--
Edward Elliott
UC Berkeley School of Law (Boalt Hall)
complangpython at eddeye dot net
More information about the Python-list
mailing list