Live data from Hacker News

John Carmack on mutable variables

twitter.com

121–130 of 663 posts

Re: John Carmack on mutable variables

#121
post #115

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)

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.

Re: John Carmack on mutable variables

#122
post #109
post #84

Earlier quoted context omitted.

Exactly this! I’d love a modern C++ like syntax with the expressiveness of python and a mostly functional approach. C# is not that far I suppose from what I want

Everybody's mileage will vary, but I find contemporary C# to be an impressively well rounded language and ecosystem. It's wonderfully boring, in the most positive sense of the word.

I can't stand modern C#. They've bung in a bunch of new keywords and features that are of dubious benefit every release.

Re: John Carmack on mutable variables

#123
post #7

Earlier quoted context omitted.

> If you want a language where const is the default and mutable is a keyword, try F# for starters. I switched and never looked back. Rust is also like this (let x = 5; / let mut x = 5;). Or you can also use javascript, typescript and zig like this. Just default to declaring variables with const instead of let / var. Or swift, which has let (const) vs var (mutable). FP got there first, but you don't need to use F# to…

In typescript and js you get immutable references, but the data is mutable. Definitely not the same thing

You have `as const`. Yes I know it's not enforced at runtime, but the type system does support it.

Re: John Carmack on mutable variables

#126
post #115

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)

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.

Re: John Carmack on mutable variables

#129

After a 2 year Clojure stint I find it very hard to explain the clarity that comes with immutability for programmers used to trigger effects with a mutation. I think it may be one of those things you have to see in order to understand.

[dead]
Post reply on HN