Skip to content

Comment on Scala: the Case for Correctnessparent

Comments

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.

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

So 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"?

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

AboutSource Built by g1lg1l

Hackerly is an independent reader for Hacker News, built on the public HN API. Not affiliated with Y Combinator.