Top
Best
New

Posted by azhenley 10/31/2025

John Carmack on mutable variables(twitter.com)
515 points | 627 commentspage 6
mr_mitm 10/31/2025|
Is there a ruff rule for this?
maleldil 10/31/2025|
There are [1] and [2] for function arguments and loop variables, respectively, but nothing for the general case. Note that a type checker will complain if you re-assign with a different type. Pylint also has [3] for redefining variables from an outer scope, but Ruff doesn't implement that yet.

[1] https://docs.astral.sh/ruff/rules/redefined-argument-from-lo...

[2] https://docs.astral.sh/ruff/rules/redefined-loop-name/

[3] https://pylint.pycqa.org/en/latest/user_guide/messages/warni...

WalterBright 10/31/2025||
I'm curious where this fits in with single assignment semantics:

    int x = 3;
    x = 4; // error!
    int* p = &x;
    *p = 4; // is that an error?
taf2 10/31/2025||
At least with clang it's a warning:

    f.c:4:8: warning: initializing 'int *' with an expression of type 'const int     *' discards qualifiers [-Wincompatible-pointer-types-discards-qualifiers]
    4 |   int* p = &x;
      |        ^   ~~
    1 warning generated.
wicharek 10/31/2025||
Yes, because line 3 would implicitly be: const int * p
halo 10/31/2025||
On a similar note, I’ve always liked the idea of being able to mark functions as pure (for some reasonable definition of pure).

The principle of reducing state changes and side-effects feels a good one.

jlmcgraw 10/31/2025|
For what it's worth, I was experimenting with this idea for Python (in an almost completely vibe-coded fashion) here: https://github.com/jlmcgraw/pure-function-decorators

Whether it's of any actual utility is debatable

MrNet32823 10/31/2025||
Jonathan Blow had strong objection with const keyword. I forgot because i did not understand at that time. Does anyone with jai experience have a counter point to that.
JonChesterfield 10/31/2025||
I believe the standard counterargument goes:

- either it's transitive, in which case your type system is very much more complicated

- or it isn't, in which case it's a near useless liability

Naturally C++ runs with the latter, with bonus extra typing for all the overloads it induces.

maleldil 10/31/2025||
How isn't it transitive in C++? If the variable/reference is const, you can't modify fields, and you can only call const methods. What else do you need?
dude250711 10/31/2025||
He also stopped shipping things.
moi2388 11/1/2025||
I agree. I mainly write c# nowadays, but even there I try to make everything as immutable as possible.

Makes everything so much easier to reason about.

groby_b 10/31/2025||
It is really amazing in how many ways C/C++ made the wrong default/implicit choices, in retrospect.

Hindsight's 20/20, of course. But still.

bmitc 10/31/2025||
> I wish it was the default, and mutable was a keyword.

Well yea, that's what sane languages that aren't Python, C, and C++ do. See F# and Rust.

xd1936 10/31/2025||
Wouldn't this allocate wasteful amounts of RAM unnecessarily for every step in a calculation?
beeflet 10/31/2025|
not if it gets optimized out
avadodin 10/31/2025||
We're all already doing this as the compiler turns everything into SSA form, silly goose.
jodleif 10/31/2025|
This Carmack guy knows his stuff.
More comments...