[Python-ideas] global and nonlocal with atributes

Steven D'Aprano steve at pearwood.info
Sun May 5 18:09:17 CEST 2013


On 06/05/13 01:45, João Bernardo wrote:
> (posting to the list)
>
> Your description of the problem that this new syntax will fix is based on
> two design flaws:
>
> Sorry, but I think you're missing the point... People write bad code and
> other people read it.

You are correct, people do write bad code, and a good programming language should encourage them to write good code, and discourage them from writing bad code. Changing "global x" to "global.x" will not make bad code less bad, it will still be bad. This proposal does not encourage people to write better code. All it does is give them a second way to write bad code.


> This is just an example and there are many other use cases.

Great! Let's hear what those other use-cases are. Maybe some of them are more compelling.


> > Even though here global looks like it is an object, it isn't, since this
>> will cause a SyntaxError:
>>
>> y = global  # global what?
>
>
> Well, I didn't proposed them to become objects... There's nothing wrong
> with some keywords behaving *partially* like objects.

Of course there is something wrong with keywords behaving partially like objects. It is bad design that makes it harder to reason about what code does. It makes it harder to learn the language. It complicates the execution model. It complicates the parser.

Good programming languages must be consistent. Things which are similar should look similar. Things which are different should look different. In your proposal, things which are different (the global keyword, and objects) look similar. That makes Python less consistent, which makes it a worse language.



-- 
Steven



More information about the Python-ideas mailing list