Top
Best
New

Posted by azhenley 4 days ago

John Carmack on mutable variables(twitter.com)
509 points | 618 commentspage 6
jdthedisciple 4 days ago|
This is almost standard in modern languages:

For example in Dart you make everything `final` by default.

croes 4 days ago|
A real default doesn’t need a keyword.
mr_mitm 4 days ago||
Is there a ruff rule for this?
maleldil 3 days ago|
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 3 days ago||
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 3 days ago||
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 3 days ago||
Yes, because line 3 would implicitly be: const int * p
halo 4 days ago||
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 4 days ago|
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 4 days ago||
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 4 days ago||
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 3 days ago||
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 4 days ago||
He also stopped shipping things.
groby_b 3 days ago||
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 4 days ago||
> 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.

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