really the immutable reference should be the shortest one to type so that it's default. too late for java, of course. this is something i think rust got right. let vs mut let.
Java is not a functional programming language; making immutability the default here, but not everywhere else, would be a jarring inconsistency.
(And imagine 10 years later when they've added a bunch more features, and you have to remember which half of the language features immutability by default, and which half features mutability by default.)
I don't see why being a functional programming language would be a requirement for making variables immutable by default. Well over 70% of the variables I use are never changed – it would be nice if I could get this guaranteed by the compiler.
You can get it guaranteed by the compiler easily, with final. The question is whether it should be the default.
And it's more general than final - in general, should the most restrictive thing be the default?
Should variables and fields be final by default?
Should methods and classes be final by default?
Should lambdas capture nothing by default?
Should methods be pure by default?
Should global variables be prohibited (making everything into an instance variable by default)?
(By the way, var/val/whatever makes type checking less restrictive by default, since it's easier to type var/val than the actual type, which is one less chance to confirm you didn't make a mistake)
Rust isn't exactly functional either. And even in C++ the recommendation is to use const as much as possible. Most variables that you use are not mutable, in most languages.
And imagine 10 years later when they've added a bunch more features, and you have to remember which half of the language features immutability by default, and which half features mutability by default.
Are you talking about Rust here? We don't have anything that's mutable by default, and that's not going to change. Why would it?
Well, because your point applies to Java with default immutability now, not just in ten years :) It could apply to Rust in 10 years if we made silly design decisions.
(I agree with that point, tacking default immutability to a language that doesn't have it in a backcompat way will lead to confusing things)
19
u/danneu Mar 09 '16
really the immutable reference should be the shortest one to type so that it's default. too late for java, of course. this is something i think rust got right.
letvsmut let.javascript fucked it up too.
letvsconst.