2 ms·
> Students have enough trouble mentally separating the concepts of declaration and usage I wonder if this is an argument in favour of Python’s implicit declara
by pansa2 5y ago
> Students have enough trouble mentally separating the concepts of declaration and usage
I wonder if this is an argument in favour of Python’s implicit declarations (“there are no declarations, only usages”) or against them (“there are still declarations, but they’re invisible”)?
- anyfoo 5y agopython is dynamically typed though, so most explicit declarations would be boring and pointless (hence the easy omission). More to the point is probably type inference in statically typed languages, e.g. in Haskell you can often omit the type, or in C++ you can just call it "auto". I'd say to learn a language it's better to explicitly specify your types in order to understand them, but I'm not sure it's necessarily "confusing" to omit them. I.e., "it has a type but I don't know it" is much easier to deal with than "what in the world is that type supposed to be".
- pansa2 5y ago> most explicit declarations would be boring and pointless Not pointless - in similar languages (e.g. JavaScript's `let` and Lua's `local`), although declarations don't indicate a variable's type, they do indicate its scope. Without explicit declarations, Python needs to make an assumption about scope - specifically, that each variable's scope is the innermost containing function. This makes the language easier for beginners, but more complex overall because it requires special features to support closures.
- codeflo 5y agoIt's also a lot more error prone in large programs because misspellings introduce new variables instead of causing an error.
- macintux 5y agoThe fact that you can “declare” variables inside logic branches also leads to runtime exceptions when the code flow doesn’t touch any of those branches, but still expects the variable to exist later.