Hacker News new | past | comments | ask | show | jobs | submit login

> 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”)?




python 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".


> 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.


It's also a lot more error prone in large programs because misspellings introduce new variables instead of causing an error.


The 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.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: