4 ms·
Isn't that common for all/most languages that don't require explicit typing?
by voltagedivider 5y ago
Isn't that common for all/most languages that don't require explicit typing?
- samhw 5y agoIt would be impossible in any language that requires either explicit typing or some kind of 'let' keyword. (Or, in the fringe case, a language like Go which uses a different operator for initialisation-plus-assignment.)
- voltagedivider 5y agoExactly. That's why I asked about languages that don't require explicit typing. My point is that it's a feature of many languages rather than a Python idiosyncrasy.
- xigoi 5y agoJavaScript (strict mode) doesn't have explicit typing, but it still requires variables to be declared.
- dragonwriter 5y agoDeclaration and explicit typing are logically orthogonal, but few if any languages require typing but not declaration. Lots require declaration but not typing.
- wruza 5y agoThis is a scoping rule, not typing. Scoping is a mechanism of symbol resolution, i.e. what do you mean by `foo` at line N. Is it a local, an argument, a global, or addresses a symbol defined in an enclosing scope? Most languages use explicit local definitions, searching implicit ones in outer scopes bottom-up, ending at the global scope. Python was the first popular non-basic language which made implicit assignments to be local and shadowing and function-scoped: global x = 1 def setx(): if True: x = 2 # completely different x print x # prints 2, visible outside of `if` setx() print x # prints 1 This led to a funny keyword 'nonlocal', because you can't simply ignore scoping and pretend that you're BASIC in any serious program. (To my opinion, python had a good start, but lost in the woods for no clear reason. It's a movie mutant of a language, which tried to appeal to non-programmers and somehow succeed, and then realized that non-programmers eventually become ones, and it's not hard. Now it's too late to fix this mess. End of opinion.)
- bjoli 5y agoIt is common tonall languages that have the same syntax for definitions and mutation. In Scheme, for example, this is not an issue.