←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 #
estimator7292 ◴[] No.45768166[source]
Your IDE probably supports this as an explicit action. JetBrains has a feature that can find all reads and writes to a variable
replies(1): >>45769329 #
Denvercoder9 ◴[] No.45769329[source]
It also has the ability to style mutated variables differently.
replies(1): >>45769672 #
1. greenicon ◴[] No.45769672[source]
Yes, depending on your highlighting scheme. Not every highlighting scheme shows this by default, unfortunately.

To me, this seems initially like some very minor thing, but I find this very helpful working with non-trivial code. For larger methods you can directly discern whether a not-as-immutable-declared variable behaves immutable nonetheless.