3 ms·
In 1.6: > Dynamic typing combined with mutable variables is flexible but also dangerous. You can unintentionally change the type of a variable with a wayward a
by kazinator 10y ago
In 1.6:
> Dynamic typing combined with mutable variables is flexible but also dangerous. You can unintentionally change the type of a variable with a wayward assignment that might crash your program much later. Or you can inadvertently reuse a variable name and wipe out any data in the variable. An undetected typo can result in data being sent to a black hole.
That is not a characteristic of dynamic typing, but of a spartan interpreter implementation and possibly language design aspects not related to dynamic typing.
If a language doesn't distinguish variable binding from assignment, that is a poor design choice which interferes with the ability to trap an assignment to a nonexistent variable and promotes the silly variable re-use alluded above.
If binding is distinct from assignment, we can diagnose the situation when a symbol is assigned that was not instantiated previously by binding.
Moreover, we can use lexical binding to introduce new variables wherever we need them, rather than re-using. We can still choose to write long functions in which variables are re-used for different purposes in different sections, but the language isn't foisting this bad design on us.