Top
Best
New

Posted by azhenley 4 days ago

John Carmack on mutable variables(twitter.com)
509 points | 620 commentspage 8
gethly 4 days ago|
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)

mirpa 4 days ago||
That depends on your definition. Programming languages often deviate from mathematics when it comes to definition of variables, functions etc. That is by choice, Haskell tried to be as close to mathematical definition as possible.
latexr 4 days ago||
You don’t need to make a mathematical argument, “variable” and “constant” have clear meanings in colloquial use which match the definitions of your parent comment.
devnullbrain 4 days ago||
So does 'parent'.
witx 4 days ago|||
A constant is a variable that _always_ has the same value on all lifecycles, e.g.

    const int a{10};
An immutable variable well ... does not

   void some_function(const int a);
Can you tell me what is the value of `a` on both cases?
gethly 4 days ago|||
> A constant is a variable...

No, it is not. A constant is the direct opposite of a variable.

> An immutable variable..

There is no such thing. You can decide not to mutate it but variable is by definition mutable.

If you want to argue mutability, then you have to talk about the data structure or memory footprint of the constant or variable that it points to or represents, not the concept of variable or constant itself.

In other words, we can have var foo = 5 and const bar = 5. foo can be changed by being reassigned another value with simple foo = 6, whereas bar cannot as bar = 6 should cause panic/exception/... On the other hand, we can have var foo = {value: 5} and const bar = {value: 5} and now it depends on the language how it handles complex types like a struct/object as the operation now bypasses the guards on the variable/constant assignment itself. Will it guard against mutation or not? It should, but that is rarely the case. Hence, in most languages, we will be able to do foo.value = 6 and also bar.value = 6, even though we should not. But again, now we are arguing about the mutability of the data type or memory representation and not the variable/constant itself. Most languages don't care about mutability, so we have this flawed thinking where we are simply unable to strictly define what data is actually mutable and what data is not. Rust uses the borrow checker, that is one approach, but generally this should be properly handled by the language spec and compiler itself and we should not even have this conversation where programmers simply cannot make a distinction between variables and constants, let alone comprehend what those terms mean in the first place, as those meanings have been thrown out of the window by the folks designing the languages.

pasteldream 4 days ago|||
I’m not sure why witx’s comment was downvoted. This is absolutely the standard usage in math and computer science.
m000 4 days ago|||
Depends on how you look at it.

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.

gf000 4 days ago||
What about the result of a computation within a giant algorithm that I decided to name, and don't plan on rewriting it anymore?

That's surely not a constant like PI, is it?

cfontes 4 days ago||
He will like RUST very much.
galangalalgol 4 days ago|
Carmack had said he likes rust, he just isn't a language zealot. In rust though, the idiom would be to shadow intermediate variables often, which removes the debugger benefit.
metaltyphoon 4 days ago||
> the idiom would be to shadow intermediate variables often

There is no idiom about this. Do it if you like but clipply doesn't warn about any of it.

galangalalgol 4 days ago||
There isn't an enforced one, and the opinion is bifurcated, but I regularly find crates that clearly treat this as idiomatic practice.
reverseblade2 4 days ago||
Use F#, compile it to .net, rust, JavaScript, typescript and python. Problem solved.
KaiserPro 4 days ago||
I don't mean to start a holy war, thats not the point, but isn't this a side effect of C++ footguns rather than python allowing you to be lazy?

I mean there is good reason to keep variables well scoped, and the various linters do a reasonable job about scope.

But I've only really know C++[1] people to want everything as a const.

[1] Yes, you functional people also, but, lets not get into that.

GTP 4 days ago||
In other words, he wishes he used Rust.
andsoitis 4 days ago||
Is there another programming language that comes close to Clojure’s persistent data structures?
throwaway984393 4 days ago||
[dead]
fallat 4 days ago||
[flagged]
EdwardKrayer 4 days ago||
John Carmack is my spirit animal. I like reading his thoughts because they give me strange insight into the way he thinks "sideways" sometimes - even if I disagree with them, I always enjoy an outside perspective.
embedding-shape 4 days ago|||
I don't think this is the first time Carmack been talking about functional programming and against mutability, here is some of his thoughts from 2014: http://number-none.com/blow/john_carmack_on_inlined_code.htm...

Just because someone is expressing a thought after you or others have already thought about it, doesn't mean they're trying to push it as something new and exciting, it's just another perspective.

kins 4 days ago|
[flagged]
JanneVee 4 days ago||
Because he showed the action fps was possible on limited hardware. Also he has had some good ideas in the software- design and architecture of Wolfenstein, Doom and Quake, that where apparent when he open sourced their engines.
ottah 4 days ago||
I mean, he's very accomplished, with most of it being well known by the average user.
More comments...