When I started working in python, I got lazy with “single assignment”, and I need to nudge myself about it. You should strive to never reassign or update a variable outside of true iterative calculations in loops. Having all the intermediate calculations still available is helpful in the debugger, and it avoids problems where you move a block of code and it silently uses a version of the variable that wasn’t what it originally had. In C/C++, making almost every variable const at initialization is good practice. I wish it was the default, and mutable was a keyword.

Oct 29, 2025 · 5:55 PM UTC

Replying to @ID_AA_Carmack
SSA for the win!
49
Replying to @ID_AA_Carmack
> I wish it was the default, and mutable was a keyword Rust ftw
12
Replying to @ID_AA_Carmack
Would be nice if we could make a variable const as part of an assignment. It's often the case that I need to modify it in a few branches, after which it should be frozen.
1
6
Replying to @ID_AA_Carmack
It surprising that C++ (or any language) doesn’t have explicit directives for scoping this kind of style request. Closest examples I can think of are async and yield, which usually code-gen a function into a different form. Why not allow fine grained policy?
3
Replying to @ID_AA_Carmack
Pretty sure that’s what rust does, you have to specify mut to make a variable mutable, otherwise it defaults to an unmutable variable
3
Replying to @ID_AA_Carmack
Similar situation with noalias. Back in the 1980s when the ANSI C standard was being created, they were going to have a keyword "noalias". Dennis wrote a letter to the committee saying he wouldn't endorse the standard if they included it. Very short sighted.
2
Replying to @ID_AA_Carmack
Immutable value holders are a goodness that usually only functional programmers appreciate.
2
Replying to @ID_AA_Carmack
This is Rust ser. I think you'll like it.
1
Replying to @ID_AA_Carmack
Use Rust.
1
Replying to @ID_AA_Carmack
FWIW, Rust defaults make this incredibly easy
Replying to @ID_AA_Carmack
yea can use frozenset and frozendict and such but have to be so careful, more cachable, yep the mutability is a real problem like you forget df.copy() and you accidentally update some kind of dict or something and its like a global so its like cache poisoning really, can mean some server just permanently stops working and when you deploy it seems to fix for a while lol untill it get cache poisoned again... arg... the mutable default way is pretty nice youll much more likely find that you need to set something as mutable via say the compiler or debugging process in these explicit mutable requirement languages pytorch is kind of nice because in place operations you need a _ so its uncommon eg add_, mul_, copy_ etc but yea idk if thats like super explicit but yea atleast its opt in ish
Replying to @ID_AA_Carmack
run a type checker and use the Final annotation :)
Replying to @ID_AA_Carmack
Variables being mutable by default in nearly all mainstream languages should be considered one of the greatest sins of PL design of all time. If I could keep one thing from Rust, it might just be variable immutability by default (w/ mut keyword for mutability).
6
4
89
Replying to @ID_AA_Carmack
Default const and nice syntax for initializing with result of a block are things that made me think Rust designers have good taste
95
Replying to @ID_AA_Carmack
Rusts “default immutable” has definitely grown on me since being introduced to it
91
Replying to @ID_AA_Carmack
Oh wait 'til you learn about Rust... you would really like Rust.
5
61
Replying to @ID_AA_Carmack
For TypeScript, `no-shadow` and `prefer-const` are some of the best ESLint rules out there. `prefer-const` forces you to use constants and `no-shadow` prevents you from reusing a variable name that's already been declared in the outer scope.
1
3
53
Replying to @ID_AA_Carmack
Erlang (all data is read only) and rust ( default to immutable) ♥️
38
Replying to @ID_AA_Carmack
This is also my pet peeve with people who().chain().functions().like().this() and then good luck debugging this!
9
1
1
36
Replying to @ID_AA_Carmack
I wish C++ had a kind of deferred const system where a variable did not have to be initialized at declaration as long as it was inited once and only once before use. For instance: const int x; if (cond) x = 1; else x = 2; You can do some of this with the ternary operator, but not with anything too complex.
12
37
Replying to @ID_AA_Carmack
I don’t understand the utility of a variable being const by default. If I want a variable to be a constant I’ll const it, but probably 70% of my variable declarations are done because I want the contents to change. Mind you I also dislike declare-and-assign statements.
22
17
Replying to @ID_AA_Carmack
In JS, we now have `const` and `let`, which at least during initialization helps to understand their usage. Everything used to be `var`, luckily these days are in the past.
1
14
Replying to @ID_AA_Carmack
funny enough, mypy can kind of catch this, if the variables are of incompatible type.
1
10
Replying to @ID_AA_Carmack
I've tried to learn Python a couple of times and it was when you were on Lex Fridman that I finally said, "Dammit if Carmack thinks it's the one language someone should pick up then I'm going to do it". I'm now giving it a second go!
9
Replying to @ID_AA_Carmack
I don't get this one, mister Carmack. Do you mean to only have constants, i.e not "variables" but data that never changes? What about stuff that actually changes e.g HP in a game?
6
8
Replying to @ID_AA_Carmack
Sir, I don't think you are ready for vibe coding 🙂
8
Replying to @ID_AA_Carmack
Mr Carmack I hope your coding skills didn't become rusty
7
Replying to @ID_AA_Carmack
"I wish it was the default, and mutable was a keyword." the reason i love working in rust
6
Replying to @ID_AA_Carmack
"I wish it was the default, and mutable was a keyword", why does that sound familiar?
Replying to @ID_AA_Carmack
preached these points for so long. No changing semantic meaning is part of why I push it but yea resequencing of code with less surprises is part of that. And const as default with mutable as optout, definitely wish it went this way.
5
Replying to @ID_AA_Carmack
Am I the only person that reads this and thinks, "your methods are probably way too big"?
6
5
Replying to @ID_AA_Carmack
U could always kotlin or 😅 go full haskell
1
3
Replying to @ID_AA_Carmack
What I typically do in C++ is to create the mut<T> type, where T is const. For instance, using u8 = const uint8_t; template<typename T> using mut = typename std::remove_const<T>::type;
2
5
Replying to @ID_AA_Carmack
Many things great about Kotlin and Haskell: FP and built-in, immutability with explicit mutability. Can’t really ever go back to C or C++. That ship has sailed and capsized years ago.
5
Replying to @ID_AA_Carmack
It's not lazy, it's seeing the SSA IR at a higher level :)
2
4
Replying to @ID_AA_Carmack
Functional Programming, baaaaaby!
4