[Python-ideas] No implicit variable declarations

James Nelson retrobanana.jn at gmail.com
Sat Apr 12 19:14:18 CEST 2014


There are several problems with Python's implicit variable declaration.
Just one tiny mistake, like assigning to SpamEggs instead of spamEggs will
create a new variable SpamEggs, and spamEggs will hold a stale value.

Two statements should be added to Python: (1) a statement that specifies
that implicit declaration by assignment should be disabled, like Fortran's
"implicit none", and (2) a variable declaration statement, a la "var
spamEggs". Trying to assign to a non-existent variable would, of course,
cause an error. If the non-existent variable's name is close enough to an
existing variable's name, the interpreter might suggest the correct name:
"Did you mean "spamEggs"?".

This idea could even open Python to static typed variables, declared like
"var spamEggs as int". This would prevent the stupid but very possible
error of assigning "clientName" (a string) to "doorStatus" (a boolean).

-rb
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20140412/3a3e21c9/attachment.html>


More information about the Python-ideas mailing list