Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.Sign up
Alternative syntax for declaring mutable values #836
Title of Suggestion
I propose we support a slightly more consistent (and, thus, simpler) syntax for declaring mutable values. Specifically:
let someVar <- 3
The existing way of approaching this problem in F# is to use the
let mutable someVar = 3
Pros and Cons
The advantages of making this adjustment to F# are ...
The disadvantages of making this adjustment to F# are ...
I realize this is a purely cosmetic suggestion. But feels no less trite than #168.
Also note, I'm not proposing to replace the existing syntax. Although one hopes it becomes deprecated over time (if not formally, than at least casually... c.f.
Estimated cost (XS, S, M, L, XL, XXL): M (only because I'm not familiar enough with the compiler to make a decent estimate).
Affidavit (please submit!)
Please tick this by placing a cross in the box:
Please tick all that apply:
I think that having to type out “mutable” to make something mutable is a good thing, as it’s one of the things that helps F# as a language favor immutability over mutability. I’m a fan of it being a little more work to make something mutable.
It’s also more discoverable via search engines the way it is now. Imagine being a new user and seeing:
let x = 42
It would be confusing and difficult to figure out what the difference is between the two is. You can’t easily Google or Bing that.
This is probably one of those parts of the language where people feel very strongly one way or the other, as a personal preference.
I find that I use
And before they got syntax highlighting, I found it rather hard to spot what happened in
One time I had to find a bug. Issue turned out to be a race condition due to globally mutable state. Being able to grep for usages of
I wouldn't consider
I do agree that using
I do not agree with making mutable implicit, when we write a language it's important that we make the opinionated path simple, and there be some amount a friction on others. If you work with a team, it's really useful that they have guiding friction on doing things in a more standard way. If you make nonstandard things too easy people will come to rely on that as a primary way of doing things. Since .NET does not have any guards on ownership of mutability I personally do not think it's particularly easy to use well and actually think that some friction is preferable, even though sometimes I use mutable.