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
@ID_AA_Carmack Am I the only person that reads this and thinks, "your methods are probably way too big"?
@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
@ID_AA_Carmack Wish someone would invent a better C++ that is almost the same except no macros, no hidden allocations, and default immutability as you suggest.
@ID_AA_Carmack deep. If you had python back then, with doom, would you have chosen python over C?
@ID_AA_Carmack You can freeze things in python, such as frozenset. That said, this is something you enforce with patterns in python.
@ID_AA_Carmack Use rust , all variables are immutable by default and all other symbols private .
@ID_AA_Carmack Oh wait 'til you learn about Rust... you would really like Rust.
@ID_AA_Carmack How about for shaders, where: 1) you cannot step through debug 2) register pressure may have a large impact on occupancy 3) compilers are less trustworthy
@ID_AA_Carmack This seems to be a core principle in Rust. I rarely have mutable variables in Rust.
@ID_AA_Carmack It's not lazy, it's seeing the SSA IR at a higher level :)
@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).
@ID_AA_Carmack So I can't do x = int(x) Just kidding... good observation
@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.
@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?
@ID_AA_Carmack U could always kotlin or 😅 go full haskell
@ID_AA_Carmack My Java is 50% the „final“ keyword. 😬
@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?
@ID_AA_Carmack Python is a completely different paradigm, you need to be careful when you get used to scoped languages. Some people see as a benefit but the rolling context is one of the weaknesses of python IMHO.
@ID_AA_Carmack It quickly becomes a nightmare to name variables if you can't reuse the names of the no longer used ones.
@ID_AA_Carmack "I wish it was the default, and mutable was a keyword." the reason i love working in rust
@ID_AA_Carmack Never vary your variables. Got it.
@ID_AA_Carmack That was one of my favorite things about Erlang. It really does eliminate a ton of bugs thinking variables that way.
@ID_AA_Carmack And use frozen dataclasses and enforce readonly typing!
@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.
@ID_AA_Carmack Rust got this right, everything const by default, and you can reuse the name of a variable, that prevents the use of the partial computation and helps you avoid thinking about names (like foo, foo_filtered, foo_filtered_in_another_unit...).
@ID_AA_Carmack Sir, I don't think you are ready for vibe coding 🙂
@ID_AA_Carmack Sounds like you want Rust 😎
@ID_AA_Carmack Totally agree. Making const the default would push C++ closer to functional safety without sacrificing control immutability by default, mutability by intent.
@ID_AA_Carmack In my first program with 1000+ lines of C code, I've had a global variable called i. It was the 80s, simpler times...
@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.
@ID_AA_Carmack FWIW, Rust defaults make this incredibly easy
@ID_AA_Carmack This is so true. Everyone starts out writing clean code. Then the project gets big and you just start tweaking variables everywhere, which is a bad habit that's hard to break.
@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.
@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
@ID_AA_Carmack doom the og, we have it easy now, not sure how you build the game engine back in the day
@ID_AA_Carmack > I wish it was the default, and mutable was a keyword This 100x over
