[flagged]
John Carmack on mutable variables
111–120 of 663 posts
Re: John Carmack on mutable variables
#112> 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, lis…
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.
Re: John Carmack on mutable variables
#113> 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, lis…
private static void blah()
{
final int abc = 3;
for (int def = 7; def
The variable 'def' is underlined. Mouse-over hint shows: 'Reassigned local variable'. To be clear, 'abc' is not underlined. When I write Java, I try to use the smallest variable scopes possible with as much final (keyword) as possible. It helps me to write more maintainable code, that is easier to read.Re: John Carmack on mutable variables
#114Re: John Carmack on mutable variables
#115Constant is by definition immutable.
Why can't people get it through their heads in 2025? (I'm looking at you, Rust)
Re: John Carmack on mutable variables
#116The principle of reducing state changes and side-effects feels a good one.
Re: John Carmack on mutable variables
#117I know it's irrelevant to his point, and it's not true of C, and it doesn't have the meaning he wants, but the pedant in me is screaming and I'm surprised it hasn't been said in the comments:
In C++ mutable is a keyword.
Re: John Carmack on mutable variables
#118> Making almost every variable const at initialization is good practice. I wish it was the default, and mutable was a keyword. It's funny how functional programming is slowly becoming the best practice for modern code (pure functions, no side-effects), yet functional programming languages are still considered fringe tech for some reason. If you want a language where const is the default and mutable is a keyword, try…
Re: John Carmack on mutable variables
#119Earlier quoted context omitted.
Eh, Rust is kind of "immutable by default" but not really enforcing that + "constants" in the way I think Carmack advocates for. Other languages does better in that regard. Examples: https://play.rust-lang.org/?version=stable&mode=debug&editio...
Yeah the encouragement of shadowing is a little weird (learning Rust coming from Go where it is sort of discouraged)
Clippy offers lints for (three?) distinct ways of shadowing because in most cases it turns out people who don't like shadowing only had problems with typically one specific kind of shadowing (e.g. same type unrelated shadowing, or different type same value shadowing) and since that varies why not offer to diagnose the specific problem this programmer doesn't like.
To be concrete some people are worried about things like:
let sparrows = get_a_list_of_sparrows();
// ....
let sparrows = sparrows.len() + EXTRA_SPARROWS;
Whereas for some people that seems fine but they're worried about: let sparrows = find_wild_sparrows();
// ....
let sparrows = find_farmed_sparrows();
These are both shadowing the name sparrows, and Rust is fine with either but Clippy can provide different lints so that you can ban one of them while using the other freely in your codebase.Re: John Carmack on mutable variables
#120> Making almost every variable const at initialization is good practice. I wish it was the default, and mutable was a keyword. It's funny how functional programming is slowly becoming the best practice for modern code (pure functions, no side-effects), yet functional programming languages are still considered fringe tech for some reason. If you want a language where const is the default and mutable is a keyword, try…
I once mentioned both these concepts to a room of C# developers. Two of them were senior to me and it was a blank expression from pretty much everyone.
> yet functional programming languages are still considered fringe tech for some reason.
You can use the same concepts in non-functional programming languages without having to buy into all the other gumpf around functional programming languages. Also other programming languages have imported functional concepts either into the language itself or into the standard libraries.
Past that. It is very rare to be able to get a job using them. The number of F# jobs I've seen advertised over the last decade, I could count on one hand.