[Python-3000] Python 3000 Status Update (Long!)

Jean-Paul Calderone exarkun at divmod.com
Fri Jun 22 22:50:01 CEST 2007


On Fri, 22 Jun 2007 14:13:39 -0600, Neil Toronto <ntoronto at cs.byu.edu> wrote:
>Andrew McNabb wrote:
>> On Fri, Jun 22, 2007 at 01:32:42PM -0600, Neil Toronto wrote:
>>
>>>> (imap is faster in this case because the built-in name 'abs' is looked
>>>> up only once -- in the genexp, it's looked up each time, sigh --
>>>> possibly the biggest "we should REALLY tweak the language to let this
>>>> be optimized sensibly" gotcha in Python, IMHO).
>>>>
>>> What is it about the language as it stands that requires abs() to be
>>> looked up each iteration?
>>>
>>
>> Calling abs() could change locals()['abs'], in which case a different
>> function would be called the next time through.  You lookup 'abs' each
>> time just in case it's changed.
>>
>
>I can't think of a reason to allow that outside of something like an
>obfuscated Python code contest. I'm sure there exists someone who thinks
>differently...

The perfectly good reason to allow it is that it is a completely
predictable, unsurprising consequence of how the Python language
is defined.

Making a special case for the way names are looked up in a genexp
means making it harder to learn Python and to understand programs
written in Python.

Keeping this simple isn't about letting people obfuscate code,
it's about making it _easy_ for people to understand Python
programs.

If the goal is to make it easier to write obscure code, _that_
would be a valid motivation for changing the lookup rules here.
Preventing people from writing obfuscated programs is _not_.

Jean-Paul


More information about the Python-3000 mailing list