On Sun, May 1, 2016, at 21:02, Steven D'Aprano wrote:
Now imagine that you are a beginner, trying to understand this code block. What would you think it does? Might you not be surprised that the two references to ".attr" refer to different variables?
And of course there is always the objection that the barrier to adding a new keyword is quite high. Somewhere out there, somebody is using "using" as a variable name (perhaps a decorator?) and making this a keyword will break her code. Is it worth it?
Or you could make it context-sensitive, with it being an identifier unless it's used in this construction. Not saying it's a good idea, just that it's technically an option.
Despite these objections, I'm cautiously interested in this. I don't think the objections are insurmountable, and if there is a significant gain in readability and performance, it may be worth while.
A cautious and tentative +1.
It may be worth you doing a survey of other languages and seeing if they have anything similar.
Javascript's deprecated "with" statement is superficially similar, but it doesn't use the dot, instead it basically turns the scope for non-local variables into a chained map. Visual Basic has something (also called "with") that is much more similar to what's being proposed. Is there any reason not to simply implement a performance optimization for the normal syntax? Is the behavior of code which reaches into the parent frame and modifies its local variables guaranteed?