Live data from Hacker News

John Carmack on mutable variables

twitter.com

141–150 of 663 posts

Re: John Carmack on mutable variables

#141
post #60
post #30

Earlier quoted context omitted.

Rust is not very suitable for functional programming because it is aggressively non-garbage-collected. Any time Rustaceans want to do the kind of immutable DAG thing that gives functional languages so much power, they seem to end up either taking the huge performance and concurrency hit of fine-grained reference counting, or they just stick all their nodes in a big array.

Using a big array has good performance though?

Yeah, but now logic bugs can cause memory leaks, doing use-after-frees, etc, without any kind of tooling to prevent it (nothing like valgrind to catch them). Sure, they won't crash the program, but sending money from a wrong account is worse than a segfault, imo.

Re: John Carmack on mutable variables

#142
post #41

Earlier quoted context omitted.

one thing I've learned in my career is that escape hatches are one of the most important things in tools made for building other stuff. dropping down into the familiar or the simple or the dumb is so innately necessary in the building process. many things meant to be "pure" tend to also be restrictive in that regard.

Functional languages are not necessarily pure though. Actually outside Haskell don't most functional first languages include escape hatches? F# is the one I have the most experience with and it certainly does.

For what it's worth, Haskell has plenty of escape hatches itself as well.

Re: John Carmack on mutable variables

#143
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)

What about the result of a computation within a giant algorithm that I decided to name, and don't plan on rewriting it anymore?

That's surely not a constant like PI, is it?

Re: John Carmack on mutable variables

#144

Earlier quoted context omitted.

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?

There is a huge amount of syntactic sugar that has been added over the years that doesn't do whole lot IMO. It is often imported from other languages (usually JavaScript and/or Python).

e.g. Just a very simple example to illustrate the point

    if (customer != null)
    {
        customer.Order = GetCurrentOrder();
    }
vs

    if (customer is not null)
    {
        customer.Order = GetCurrentOrder();
    }
Is there really any benefit in adding "is/is not"? I would argue no. So I categorise that as being of "dubious benefit" and there are many similar small features, keywords etc. that get added each release where they might save a few lines of code somewhere but I've never seem them used that often.

Re: John Carmack on mutable variables

#145
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`?

Re: John Carmack on mutable variables

#147

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`?

There was a proposal in Java a few years back to introduce "val".

I think it never gained traction but it would have been nice to have this in Java

    val firstName = "Bob";
    val lastName = "Tables";
    var fullName = "";

    fullName = firstName + " " + lastName;

Re: John Carmack on mutable variables

#148
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…

Agreed, and Carmack as always was ahead of the curve here.

In case anyone here hasn’t seen it, here’s his famous essay, Functional Programming in C++:

http://sevangelatos.com/john-carmack-on/

He addresses your point:

> I do believe that there is real value in pursuing functional programming, but it would be irresponsible to exhort everyone to abandon their C++ compilers and start coding in Lisp, Haskell, or, to be blunt, any other fringe language. To the eternal chagrin of language designers, there are plenty of externalities that can overwhelm the benefits of a language, and game development has more than most fields.

Re: John Carmack on mutable variables

#149

Earlier 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?

I find there are some environments where you have a positive feedback loop while working in them. PHP is one of them, Go is another at least for me.

I find many of languages I am constantly fighting with dependency managers, upgrades and all sorts of other things.

Re: John Carmack on mutable variables

#150
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)

A constant is a variable that _always_ has the same value on all lifecycles, e.g.

    const int a{10};
An immutable variable well ... does not

   void some_function(const int a);
Can you tell me what is the value of `a` on both cases?
Post reply on HN