by coldpizza · 9y ago · 0 comments
I wonder why they decided on these very mistakable names. Why not const/constant/cons/whatever else just as long it's distinguishable from each other?
let (mut x, y) = (1, 2);
x is mutable, y isn't.That is, let is the way that you introduce a new binding, always.
But this most likely is because Scala uses val/var.
val/var/const/whatever only describe the reference, not the value. It doesn't really make sense for that annotation to, say, swivel a collection between ImmutableList and MutableList.
Now, you might be right that it's confusing, this difference between reference mutability and value mutability. I see beginners struggle with it in Javascript's new let vs const all the time.
It does; if you don't use `let mut`, you can't mutate the variable at all, which includes the contents of a collection.
(Given that someone will mention RefCell if I don't, I'll add: "barring unusual trickery".)
That's nonsense.
1. You cannot implement immutable collections without `let` / `final`
2. The Java Memory Model has special visibility guarantees for `final` (which does propagate), making it really, really useful
3. Having the guarantee that a certain reference won't change is still useful even if the object referenced is a mutable ArrayList; e.g. ref = null
2. Java does a lot with the keyword 'final'. I guess here you're talking about the concurrency behaviors of it? Does it bother you that you can remove 'final' via reflection?
3. It's still useful (e.g. not needing to use yoda-style ifs in languages where you can assign inside an if expression Just In Case you forget an =), but not very. That's my whole point.
Remember recently on the Java mailing list there was a lot of bikeshedding concerning this point. I don't think it matters near as much as the discussion surrounding it thinks.
Oh, and finally, "const" has a specific meaning: compile time constants.
Maybe other people's brains work differently than mine, but I'm sure I will be slightly slowed down by this.
I'm happy to be dependent on my IDE.
It might have appeared in earlier MLs as an extension.
I will echo what the others have said; it's not what I would choose, but in practice it's never been a problem when I'm writing Scala.
As a bit of an unreformed code golfer and a fan of ML-style syntax, I actually kinda like it myself; I was just listing a few things that are "considered questionable" (by some people) and present in both languages.
val array = new Array[String](10)
array.update(7, "hello")
array(7) = "hello" // simply calls out to updateval = value (constant)
What can be mistaken?
l => let
v => var
You can argue that it's really not much extra work but it all adds up. Especially when you try to code on a tablet, which I find myself doing occasionally.