A Suggestion (please read and respond)
s713221 at student.gu.edu.au
Tue Oct 31 13:59:03 CET 2000
> Hi all!
> Python is a great language and has many great features. I especially like the dynamic typing and the flexibility it allows, in addition to its aid in distributed objects (CORBA).
> However, I think the total lack of declaration of variables reduces readability and can be an issue for new programmers. For example:
> >>> MyLongVariableName = 1
> >>>#somewhere farther down in the code
> >>>MyLongVAriableName = MyLongVariableName + 1
> This is a problem! (ok, so this example can be "fixed" with the new '+=' operator but other examples could be formed)
> I think it can also be helpful for new programmers if variables must be declared first.
> My proposal is to make a new keyword "var" (or some similar, but short and sweet word). Variable names would have to be declared before they are used, but can be declared anywhere in the code. Since the variable name is declared, it would then exist; a value of "None" seems appropriate here. I would like to see an exception to the declaration, however, in for loops.
> >>> var MyLongVariableName
> >>> var AnotherVariable = 1
> >>> for x in range( 10 ) :
> .. pass
> >>> AVar = 1 # error, AVar doesn't exist
> Ok, so this would break existing code. To solve this, some sort of compatibility switch could be added to the interpreter (for either way, to require declaration or to set compatibility).
If you really need to put in variable declarations to improve readability, python actually has a compatibility switch you can use. You just have to preceed every variable delaration with a hash symbol. Eg.
>>> # var MyLongvariableName
Unfortunatly, because so many people find the automatic creation of variables so convenient, Guido decided not to enforce variable declaration.
More information about the Python-list