Variable is by definition mutable. Constant is by definition immutable. Why can't people get it through their heads in 2025? (I'm looking at you, Rust)
John Carmack on mutable variables
121–130 of 663 posts
Re: John Carmack on mutable variables
#122Earlier quoted context omitted.
Exactly this! I’d love a modern C++ like syntax with the expressiveness of python and a mostly functional approach. C# is not that far I suppose from what I want
Everybody's mileage will vary, but I find contemporary C# to be an impressively well rounded language and ecosystem. It's wonderfully boring, in the most positive sense of the word.
Re: John Carmack on mutable variables
#123Earlier quoted context omitted.
> If you want a language where const is the default and mutable is a keyword, try F# for starters. I switched and never looked back. Rust is also like this (let x = 5; / let mut x = 5;). Or you can also use javascript, typescript and zig like this. Just default to declaring variables with const instead of let / var. Or swift, which has let (const) vs var (mutable). FP got there first, but you don't need to use F# to…
In typescript and js you get immutable references, but the data is mutable. Definitely not the same thing
Re: John Carmack on mutable variables
#124Then, suddenly, the enlightenment
Re: John Carmack on mutable variables
#125How fast this got to the top, you would think John Carmack just invented nuclear fusion.
Re: John Carmack on mutable variables
#126Variable is by definition mutable. Constant is by definition immutable. Why can't people get it through their heads in 2025? (I'm looking at you, Rust)
A true constant won't change between runs of the code. I.e. it is essentially a symbolic name for a literal.
A constant variable OTOH, varies in different executions of the code. So, its invariance is linked to an execution context.
Re: John Carmack on mutable variables
#127For example in Dart you make everything `final` by default.
Re: John Carmack on mutable variables
#128I think it may be one of those things you have to see in order to understand.
Re: John Carmack on mutable variables
#129After a 2 year Clojure stint I find it very hard to explain the clarity that comes with immutability for programmers used to trigger effects with a mutation. I think it may be one of those things you have to see in order to understand.