mut is now optional. Thank you!
#26880
Replies: 15 comments 28 replies
-
|
Thank you for letting us know. I never liked the v rule about all variables being read-only by default. |
Beta Was this translation helpful? Give feedback.
-
|
I will be very UNhappy if this is made the default. 👎🏼 |
Beta Was this translation helpful? Give feedback.
-
|
Agree with JalanSolov. This turn is very disappointing. It gives people the impression that the language is backtracking on safety features. Furthermore, it looks very conflicted or even arbitrary, because on the one hand there was a turn to enforcement of no unused parameters. Yet, we can disregard default immutability at will. Where is the flag for turning off unused parameters enforcement? In fact, what are we doing? There does not seem to be enough communication as to goals and direction. The unused parameter turn looks to have unleashed havoc on many modules interacting with C libraries (edit: problems caused by long uncaught bugs that were recently revealed), as they no longer work. VUI and GUI, which are supposedly supported, their examples do not work anymore. There are also many 3rd party libraries that are not working properly with the new version. They all need updating. Many perceive vlang as striving to be a better golang and safer alternative to C. Removal or waffling with safety features arguably lowers the value of vlang as an alternative. The direction, vision, and goals of vlang need to be more coherent. And what that is, should be clearly communicated to its community and the general public. More so, as the language creeps up in age. |
Beta Was this translation helpful? Give feedback.
-
|
Gonzalo Chumillas escribió/skribis/wrote/scrit (2026-04-15T10:24:49-0700):
```bash
% v -disable-explicit-mutability run hello.v
```
```v
msg := "Hello, World" // not `mut` needed
msg = "Hello, World!"
```
a drawback of "changing" the language by a compiler option is that the
code becomes harder to understand out of context, i.e. you need to know
how the code is compiled in order to be sure you understand its
behaviour. perhaps the default mutability does not affect so much in
that matter, but still…
|
Beta Was this translation helpful? Give feedback.
-
|
mut system is just inconsistent in current implementation struct Host {
cached []int = [0,0,0]
}
fn (mut self Host) numbers() []int {
return self.cached // Can be mutated by caller
//return self.cached.clone() // Expensive
}
fn main()
{
mut h := Host{}
mut numbers := h.numbers()
numbers[0] = 1
h.cached[0] = 1 //code.v:15:4: error: field `cached` of struct `Host` is immutable
println(h.cached) // [1,0,0]
}In a logical system, everything should be logical. |
Beta Was this translation helpful? Give feedback.
-
|
Moreover, the vast majority of real tasks don’t require mut at all. It’s only needed by less than 1% of programmers — for the rest, it just hinders readability. |
Beta Was this translation helpful? Give feedback.
-
|
The I'd rather see V become stricter than weaken security for the sake of illusory convenience. |
Beta Was this translation helpful? Give feedback.
-
|
Mut becomes an optional keyword, which in itself should be a throwback to the V language.Will you consider mut as a mandatory option in the future? |
Beta Was this translation helpful? Give feedback.
-
|
Personally I prefer original V fn main() {
not_mut := 1
unsafe{
not_mut = 2 // hold my beer
}
assert not_mut == 2
}Saving time in Golang without needing |
Beta Was this translation helpful? Give feedback.
-
It is merely an optional feature, and it should not affect the development direction of v |
Beta Was this translation helpful? Give feedback.
-
|
Given it has to be turned on with a command line flag I am ok with it as It may be useful in some initial code conversion from another language. Once the translated code works, you can remove the flag and fix up all mutability errors. Provided a file so compiled can be used with files/libraries compiled without this flag. |
Beta Was this translation helpful? Give feedback.
-
|
Jengro escribió/skribis/wrote/scrit (2026-04-18T19:43:07-0700):
It is merely an optional feature, and it should not affect the
development direction of v
it shoud not, but it may, because it's an optional feature that changes
the behaviour of the language.
besides, without knowing the compilation options (say, which "dialect"
the program is written in), the code may be confusing or more difficult
to understand.
|
Beta Was this translation helpful? Give feedback.
-
|
Bakul Shah escribió/skribis/wrote/scrit (2026-04-18T20:22:53-0700):
It may be useful in some initial code conversion from another
language. Once the translated code works, you can remove the flag and
fix up all mutability errors.
yes, it may be useful in certain cases.
but the feature also opens the door to programs with a different
mutability default, depending on a command-line option, i.e. on
something which is not explicit in the code itself.
it would be clearer if such an option would be explicit in the code, for
example with a file-scope directive. then the "dialect" the file is
written in would be explicit in any context.
|
Beta Was this translation helpful? Give feedback.
-
|
I was just guessing at the reason. Better justification should be provided. If deemed useful, then yes, a file scope directive would be better. |
Beta Was this translation helpful? Give feedback.
-
|
mut, ownership, and other code constraints are merely artificial disciplines for projects accessed by many low-level programmers. When you're programming alone, you don't need such protections against yourself because you know exactly how the code works. You clearly understand that your code is divided into several independent modules, each performing narrow, well-defined tasks, so mut safeguards are essentially unnecessary. Moreover, with the advancement of AI, projects are increasingly being developed by single developers. In the AI era, programming languages with such excessive restrictions are no longer needed—they will only slow down both the AI and the human programmer. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Wonderful!
% v -disable-explicit-mutability run hello.v Hello, World!This simple change will allow the user to
Beta Was this translation helpful? Give feedback.
All reactions