3 ms·
Betz should fix his terminology to align with the industry. There is nothing implicit about x = 42 in Python. You wrote it explicitly. The language is not pre
by kazinator 3y ago
Betz should fix his terminology to align with the industry.
There is nothing implicit about x = 42 in Python. You wrote it explicitly.
The language is not pretending that you invisibly defined x somewhere at the top and are now assigning it.
The most familiar "implicit declaration" to everyone is the feature in traditional C (that any good C compiler warns about and was banished in C++ early). Like that you can call a function without declaring it:
puts("Hello"); /* no <stdio.h> included */
The compiler looks at the argument types and deduces a declaration. The return type is assumed to be int, and since the "Hello" expression decays to char * type, the implicit declaration is int puts(char *).
Python actually doesn't have declarations at all (except when we consider the new typing features).
When we introduce something into a scope without giving any attributes about it like type, that's a definition. A declaration is something which makes facts known about an identifier: like whether it is a constant, does it have a type, and such. It doesn't necessarily make it exist.
In Lisp declarations can be added about an existing identifier:
(let ((x 3)) ;; definition of x
(declare (type (integer x))) ;; declaration about x
...)
In languages focused on static type, definitions declare. E.g. in C, all definitions (other than of macros) are declarations; not all declarations are definitions.
In Python, a variable must be visibly defined before it is used, quite clearly; it doesn't have implicit definition. Untyped Python has no declarations.
- IshKebab 3y ago> There is nothing implicit about x = 42 in Python. You wrote it explicitly. You wrote the assignment explicitly. You did not write any declaration that "a variable x should already exist" anywhere did you? > Betz should fix his terminology to align with the industry. His terminology is aligned with the industry. Google it. Here are the top two results for me: * https://www.quora.com/What-does-the-explicit-and-implicit-declaration-of-variables-in-python-mean https://www.quora.com/What-does-the-explicit-and-implicit-de... * https://stackoverflow.com/questions/56999347/variable-declaration-implicit-and-explicit-and-advantages-disadvantages https://stackoverflow.com/questions/56999347/variable-declar... > Like that you can call a function without declaring it: That's exactly the same as your Python example!! "There's nothing implicit about `puts("Hello");`. You wrote it explicitly." > When we introduce something into a scope without giving any attributes about it like type, that's a definition. A declaration is something which makes facts known about an identifier: like whether it is a constant, does it have a type, and such. It doesn't necessarily make it exist. No. A declaration can only declare that a variable exists. Consider this in Javascript: let foo; Not "having" declarations and declarations being implicit are exactly the same thing. You're getting tripped up over your language.
- kazinator 3y ago> A declaration can only declare that a variable exists. Yes; that's the only correct thing in your comment. A declaration can declare that a variable exists, and nothing more, which is useful in some language that has a strict rule that variables must have been indicated as existing before they can be used. If a declaration causes the variable to exist, then it's a definition. However, about that specific example, "let foo;" in Javascript is actually a definition. It causes foo to exist in the scope where it appears, with a value of undefined.