3 ms·
> It's easy for a parser or a person to scan the local scope and see if a variable is ever possibly mutated or not. "what the parser figured out" != "what the
by frowaway001 12y ago
> It's easy for a parser or a person to scan the local scope and see if a variable is ever possibly mutated or not.
"what the parser figured out" != "what the author intended"
> this is a straightforward syntactic property
Not for the reader.
- StefanKarpinski 12y agoNo, seriously, it's easy: Is there exactly one assignment location that's not in a loop or a conditional? yes => constant ; no => non-constant This is neither hard nor unintuitive.
- frowaway001 12y agoSo you are recommending to create a special case just for declarations in local scope? So "var" in global places means "variable", but "var" in local places means "variable or value"?
- StefanKarpinski 12y agoI'm not recommending anything. I'm wondering what the point of declaring something that's obvious from a simple syntactic analysis is. The author of this post makes a big deal of it and I don't see why it's useful. If the motivation is that constness is the right default in global scope and you want to make local and global scope more similar (even though they are still radically different), that's cool, but then don't make it out like local variables defaulting to const is the best thing ever invented.