[Python-ideas] No implicit variable declarations
Ethan Furman
ethan at stoneleaf.us
Sat Apr 12 19:23:39 CEST 2014
On 04/12/2014 10:14 AM, James Nelson wrote:
> 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.
This is why you should have unit tests.
> 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"?".
And also linters [1].
> 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).
-1 on the whole thing.
--
~Ethan~
[1] http://stackoverflow.com/q/5611776/208880
More information about the Python-ideas
mailing list