4 ms·
> most explicit declarations would be boring and pointless Not pointless - in similar languages (e.g. JavaScript's `let` and Lua's `local`), although declarati
by 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.