If designing your hypothetical ideal language, what are some intuitive/cute keywords you would choose for mutables/immutables? `let` is so 2020. `const` is too long. `static` makes me fall asleep at the keyboard. `con` sounds bad. How about `law`? law pi = 3.142 (heh typing on Mac autocompleted this) law c = 29979245 law law = "Dredd" or `set` or `once` or `make`?
John Carmack on mutable variables
221–230 of 663 posts
Re: John Carmack on mutable variables
#222Re: John Carmack on mutable variables
#223Earlier quoted context omitted.
whats the difference between immutable and constant, which has been in use far longer? why are you calling it mutable?
Immutable and constant are the same. rendaw didn't use the word mutable. One reason someone might use the word "mutable" is that it's a succinct way of expressing an idea. Alternative ways of expressing the same idea are longer words (changeable, non-constant).
They are very, very different semantically, because const is always local. Declaring something const has no effect on what happens with the value bound to a const variable anywhere else in the program. Whereas, immutability is a global property: An immutable array, for example, can be passed around and it will always be immutable.
JS has always hade 'freeze' as a kind of runtime immutability, and tooling like TS can provide for readonly types that provide immutability guarantees at compile time.
Re: John Carmack on mutable variables
#224I like the idea of immutable-by-default, and in my own musings on this I've imagined a similar thing except that instead of a mutable keyword you'd have something more akin to Python's with blocks, something like: # Immutable by default x = 2 items = [1,2,3] with mutable(x, items): x = 3 items.append(4) # And now back to being immutable, these would error x = 5 items.append(6) I have put almost zero thought into the…
This is in essence a mutable borrow - by looking at Rust's borrow checker, one can see the complexities of the concept.
Re: John Carmack on mutable variables
#225Earlier quoted context omitted.
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
#226Re: John Carmack on mutable variables
#227Why loops specifically? Why not conditionals? A lot of code needs to assemble a result set based on if/then or switch statements. Maybe you could add those in each step of a chain of inline functions, but what if you need to skip some of that logic in certain cases? It's often much more readable to start off with a null result and put your (relatively functional) code inside if/then blocks to clearly show different l…
There’s no mutating happening here, for example: if cond: X = “yes” else: X = “no” X is only ever assigned once, it’s actually still purely functional. And in Rust or Lisp or other expression languages, you can do stuff like this: let X = if cond { “yes” } else { “no” }; That’s a lot nicer than a trinary operator!
Re: John Carmack on mutable variables
#228Earlier quoted context omitted.
Much like PHP, you can actually get stuff done unlike a lot of other programming languages.
Oh? Which “lot of” other programming languages can’t you “actually get stuff done” in? Are you sure the problem lies with the programming language?
Re: John Carmack on mutable variables
#229How fast this got to the top, you would think John Carmack just invented nuclear fusion.
Re: John Carmack on mutable variables
#230After 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.
I think it's simply the difference between the curious mind, who explores stuff like Clojure off the job (or is very lucky to get a Clojure job) and the 9 to 5 worker, who doesn't know any better and has never experienced writing a FP codebase.