←back to thread

498 points azhenley | 1 comments | | HN request time: 0s | source
Show context
hyperhello ◴[] No.45767863[source]
> I wish it was the default, and mutable was a keyword.

I wish the IDE would simply provide a small clue, visible but graphically unobtrusive, that it was mutated.

In fact, I end up wishing this about almost every language feature that passes my mind. For example, I don't need to choose whether I can or can't append to a list; just make it unappendable if you can prove I don't append. I don't care if it's a map, list, set, listOf, array, vector, arrayOf, Array.of(), etc unless it's going to get in my way because I have ten CPU cores and I'll optimize the loop when I need to.

replies(8): >>45768027 #>>45768166 #>>45768207 #>>45768240 #>>45768356 #>>45769342 #>>45769717 #>>45770340 #
nielsbot ◴[] No.45768207[source]
I use Swift for work. The compiler tell you this. If a mutable variable is never mutated it suggests making it non-mutable. And vice versa.
replies(2): >>45769302 #>>45769704 #
qmmmur ◴[] No.45769302[source]
As will Typescript, at least using Biome to lint it does.
replies(2): >>45773283 #>>45774260 #
1. nielsbot ◴[] No.45774260[source]
My very minor complaint about TypeScript is you use to use `const` which is 2 additional letters.

Seriously though, I do find it slightly difficult to reason about `const` vars in TypeScript because while a `const` variable cannot be reassigned, the value it references can still be mutated. I think TypeScript would benefit from more non-mutable values types... (I know there are some)

Swift has the same problem, in theory, but it's very easy to use a non-mutable value types in Swift (`struct`) so it's mitigated a bit.