[Python-ideas] stealing "var" from javascript

Aaron Watters aaron.watters at gmail.com
Thu Apr 10 16:13:57 CEST 2008


I know it's too late but as long as
py3k will break everything, why not
add explicit introduction of local variables?

This is one place where Perl actually
gets something right with "use strict;" and
"my variable=...;"

In particular there is a big conceptual difference
between creating a new variable and changing
a binding to an existing variable.

You could make this difference explicit by saying

   # create local myvariable (error if exists) and assign value
   var myvariable=value;

   # rebind local myvariable (error if doesn't exist)
   myvariable = value;

This would allow catching a lot of nameerrors at
compile time, and also name mistakes which don't
show up as nameerrors (like accidentally typing a
variable name wrong in such a way that it doesn't
fail the test cases, but only fails after deployment...).
Any assignment with no associated "my" declaration
would automatically be an error at compile time.

As I say, I know it's too late.  I also know it's probably
not a new idea, but I couldn't locate it in a brief attempt.
I also know that various python lint tools catch most name
problems like the above...

hmmm... I actually wouldn't mind the "my" keyword
instead of "var" since it is shorter and probably less
frequently used in existing code... (btw, "yield" broke
every existing financial application :( ).

Just a thought.
   -- Aaron Watters
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20080410/4d074a97/attachment.html>


More information about the Python-ideas mailing list