Thought: local declarations

scleary at jerviswebb.com scleary at jerviswebb.com
Tue May 29 10:08:52 EDT 2001


All right, Python developers:

Python has a lot of attributes that make it harder for programmers to make
errors -- use of indentation and chaining comparision operators come to
mind.  However, it does allow a new (to me, coming from C++) simple type of
error - variable misspelling.  I think we've all done it at one time or
another, and the interpreter silently smiles and creates a new local
variable -- and then (at least most of the time with me) the error doesn't
show up until near the end of the computation, or sometimes you just get the
wrong result...

So, why not an *optional* "local declaration statement", something like:
  local x, y
Then if any variable is written to that is not local or global, it would be
flagged as an error (but *only* if a local decl stmt exists for that block).

This becomes more complicated when trying to do the same thing for member
functions:
  local self.x, self.y, self.func  # ?

I don't really like declarations myself -- but I'd like to be able to flag
misspellings as an error, though, and I can't think of any other way to do
it.

Ideas?  Thoughts?  Has this been discussed before?

	-Steve




More information about the Python-list mailing list