Live data from Hacker News

John Carmack on mutable variables

twitter.com

131–140 of 663 posts

Re: John Carmack on mutable variables

#131
Meh... I agree where he comes from (when working on large projects, muttability can introduce bugs), but many languages have solved it, similar by having two types, 'let' and 'var', or 'const' in front of a variable.

But, there is practicality in the ability of being able to change a var, and not having to create a new object every time you change one of its members.

It models real nature/physics better.

It looks like He is asking that 'const' be the default, and 'var' should be explicit, which makes sense.

Re: John Carmack on mutable variables

#132
post #109

Earlier quoted context omitted.

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.

I'm interested what are those new keywords and features that are of dubious benefit?

Re: John Carmack on mutable variables

#133
post #130

Good point. Had never occurred to me that keeping steps help debug. Obvious in hindsight

For the same reason almost all my functions end with this:

  const result = ... ;
  return result;
I know debuggers can show return values, but that doesn't help when you're just doing a quick console log inspection.

Re: John Carmack on mutable variables

#134
post #56
post #9

Immutability was gaining huge traction with Java... then large parts of the industry switched to golang and we hardly make anything immutable.

Go is the new PHP.

Much like PHP, you can actually get stuff done unlike a lot of other programming languages.

Re: John Carmack on mutable variables

#135
In JetBrains editors it's possible to highlight mutable variables, at least in the languages where the distinction exists. My go to setting in Kotlin is to underscore all `var`'s, for two reasons:

- this makes them really stand out, much easier to track the mutation visually,

- the underscore effect is intrusive just-enough to nudge you to think twice when adding a new `var`.

Nothing like diving into a >3k lines PR peppered with underscores.

Re: John Carmack on mutable variables

#136
post #2

> Making almost every variable const at initialization is good practice. I wish it was the default, and mutable was a keyword. It's funny how functional programming is slowly becoming the best practice for modern code (pure functions, no side-effects), yet functional programming languages are still considered fringe tech for some reason. If you want a language where const is the default and mutable is a keyword, try…

It's because you want a tasteful mix of both.

I believe Scala was pretty ahead here by building the language around local mutability with a general preference for immutable APIs, and I think this same philosophy shows up pretty strongly in Rust, aided by the borrow checker that sort of makes this locality compiler-enforced (also, interior mutability)

Re: John Carmack on mutable variables

#137
post #96

Yeah I wish variables were immutable by default and everything was an expression Oh well continues day job as a Clojure programmer that is actively threatened by an obnoxious python take over

As a Python programmer at day job, that is Clojure-curious and sadly only gets to use it for personal projects, and is currently threatened by an obnoxious TypeScript take over, I feel this.

Re: John Carmack on mutable variables

#138
post #32
post #26

Earlier quoted context omitted.

> come with the baggage of foreign looking syntax Maybe they're right about the syntax too though? :)

Which one, Erlang, Lisp, or ML?

Lisp syntax is objectively superior because you can write a predicate like thus:

  (
Instead of having to do the awful ampersand dance.

Re: John Carmack on mutable variables

#139
post #10
post #2

> Making almost every variable const at initialization is good practice. I wish it was the default, and mutable was a keyword. It's funny how functional programming is slowly becoming the best practice for modern code (pure functions, no side-effects), yet functional programming languages are still considered fringe tech for some reason. If you want a language where const is the default and mutable is a keyword, try…

Functional programming languages (almost always?) come with the baggage of foreign looking syntax. Additionally, imperative is easier in some situations, so having that escape hatch is great. I think that's why we're seeing a lot of what you're describing. E.g. with Rust you end up writing mostly functional code with a bit of imperative mixed in. Additional, most software is not pure (human input, disk, network, etc)…

Foreign looking is just a person's biases/experience. C is just as foreign looking to a layperson, you just happened to start programming with C-family languages. (Also, as a "gotcha" counterpoint, I can just look up a Haskell symbol in hoogle, but the only language that needs a website to decipher its gibberish type notation is C https://cdecl.org/ )

Nonetheless, I also heavily dislike non-alphabetical, library-defined symbols (with the exception of math operators), but this is a cheap argument and I don't think this is the primary reason FPs are not more prevalent.

Re: John Carmack on mutable variables

#140
post #56

Earlier quoted context omitted.

Go is the new PHP.

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?
Post reply on HN