[Python-ideas] No implicit variable declarations
James Nelson
retrobanana.jn at gmail.com
Sat Apr 12 20:14:04 CEST 2014
Markus Unterwaditzer <markus at ...> writes:
>
> Hello James,
>
> I see how this would help with avoiding a whole class of errors, but then
i
> also think your two suggestions -- the var and implicit keywords -- would
take
> a great deal of flexibility and expressiveness from the language. Also,
Python
> was never meant to be statically typed, so suggesting static typing so
many
> years after its creation is IMO pointless, even though you're suggesting
it to
> be optional. OTOH I like your idea of suggesting variable names when
NameError
> is raised, but i don't know how easy this is to implement in CPython.
>
> I also want to say that the kind of error you're describing never occured
to me
> in practice. The mistake of assigning to the wrong variable name (and not
> noticing it immediately through an exception) seems to me like something
that
> only occurs when deliberately writing huge cludges of spaghetti-code, or
when
> you're simply not using enough namespaces.
>
I don't believe that having var and implicit keywords would make the
language less flexible -- they are completely optional, remember. If you
omit "implicit none" from the beginning of your program you can write your
program like you do now, implicit variable declarations and all.
In retrospect, statically typed variables does contradict Python's duck
typing: it shouldn't matter if it's a float or an integer, as long as you
multiply or divide, you're fine, and if you need a specific type, you just
check with type().
- JN
More information about the Python-ideas
mailing list