Top
Best
New

Posted by azhenley 5 days ago

John Carmack on mutable variables(twitter.com)
509 points | 622 commentspage 9
Pxtl 4 days ago|
[flagged]
swiftcoder 4 days ago|
[flagged]
bitwize 4 days ago||
[flagged]
veltas 4 days ago||
I hope this experimental language becomes usable eventually, all I hear is how you have to continuously rewrite to work around the borrow checker, accept worse performance to make everything message based, or just ignore the type system and write VB6-style code where everything is indexes in arrays to obfuscate ownership and paste 'unsafe' when it moans.
embedding-shape 4 days ago||
Eh, Rust is kind of "immutable by default" but not really enforcing that + "constants" in the way I think Carmack advocates for. Other languages does better in that regard. Examples: https://play.rust-lang.org/?version=stable&mode=debug&editio...
jasonthorsness 4 days ago||
Yeah the encouragement of shadowing is a little weird (learning Rust coming from Go where it is sort of discouraged)
tialaramex 4 days ago||
Discouraging shadowing in languages with unclear lifetimes makes plenty of sense.

Clippy offers lints for (three?) distinct ways of shadowing because in most cases it turns out people who don't like shadowing only had problems with typically one specific kind of shadowing (e.g. same type unrelated shadowing, or different type same value shadowing) and since that varies why not offer to diagnose the specific problem this programmer doesn't like.

To be concrete some people are worried about things like:

  let sparrows = get_a_list_of_sparrows();
  // ....
  let sparrows = sparrows.len() + EXTRA_SPARROWS;
Whereas for some people that seems fine but they're worried about:

   let sparrows = find_wild_sparrows();
   // ....
   let sparrows = find_farmed_sparrows();
These are both shadowing the name sparrows, and Rust is fine with either but Clippy can provide different lints so that you can ban one of them while using the other freely in your codebase.
LeoPanthera 4 days ago||
[flagged]
tomhow 4 days ago||
Please don't post off-topic flamebait on HN. https://news.ycombinator.com/newsguidelines.html
Pxtl 4 days ago||
How is it offtopic on a Twitter post by John Carmack to remark on the fact that John Carmack posts to Twitter?
tomhow 4 days ago||
Because it has nothing to do with the content and it's the kind of comment that is only made for the sake of stirring up feelings people have about Twitter and its owner, a topic that has been done to death for years on HN, and about which there is nothing new or interesting to say.

HN is a site that's specifically designed to focus on the new and interesting aspects of topics.

Pxtl 4 days ago||
That Carmack still posts to Twitter (and QTs Curtis Yarvin) was news to me.
tomhow 4 days ago||
The guidelines specifically ask:

Please don't pick the most provocative thing in an article or post to complain about in the thread. Find something interesting to respond to instead.

This has been in the guidelines for many years and it’s long been routine moderation that we ask people to avoid that kind of thing.

loeg 4 days ago|||
No Twitter clone has supplanted the original. Bluesky is a joke. Federation doesn't work. Threads isn't close. Musk's ownership isn't such a negative that it outweighs everything else.
Pxtl 4 days ago||
> Musk's ownership isn't such a negative that it outweighs everything else.

If it was just his ownership that would be one thing but his aggressive support for turning the site into /pol/ has ruined it.

whimsicalism 4 days ago|||
at least in ML, no other social media forum has comparably technical depth - would love for people to point me to others
bigstrat2003 4 days ago||
That is not really a reasonable take. Judging people for what website they use is extremely shallow.
Pxtl 4 days ago||
[flagged]
oulipo2 4 days ago||
Can we stop linking the racist website that twitter has become?
GPerson 4 days ago||
Kinda curious on what jblow would say about this.
kragen 4 days ago|
blojo? Ask him and report back.
GPerson 4 days ago||
[flagged]
kragen 4 days ago||
No, he's a competent programmer.
swiftcoder 4 days ago||
> > Lol what a loser

> No, he's a competent programmer.

I don't think these are mutually exclusive

smallstepforman 4 days ago||
There are languages nobody uses, and languages people complain about. Computing is about change, otherwise there is nothing to compute. The mere fact that its called a “variable” makes it obvious that its supposed to change.
butokai 4 days ago||
This is a viewpoint commonly held by students who were exposed to imperative programming before having any class in maths. However it shouldn't survive long after that.
tialaramex 4 days ago||
Bjarne's excuse is very silly, it's like the Laffer curve but for programming language defects. It pins one edge case nobody cares about, then tries to imply that's proof for a claim no sane person could agree with and for which there is no evidence. Bjarne says languages with no users attract no complaints regardless of how terrible they are (nobody was arguing that they do), therefore implies Bjarne, the fact that people complain about my language just means it is popular. Bzzt, wrong. They're complaining because it's so riddled with problems.

Variables are distinct from constants. It's a problem that C and C++ use the keyword "const" to signify immutability instead, indeed as a result C++ needed three more keywords "constexpr", "constinit" and "consteval" to try to grapple with the problem.

hackthemack 4 days ago|
One area that I like to have immutability is in function argument passing. In javascript (and many other languages), I find it weird that arguments in function act differently depending on if they are simple (strings, numbers) versus if they are complex (objects, arrays).

I want everything that passes through a function to be a copy unless I put in a symbol or keyword that it suppose to be passed by reference.

I made a little function to do deep copies but am still experimenting with it.

  function deepCopy(value) {
    if (typeof structuredClone === 'function') {
      try { return structuredClone(value); } catch (_) {}
    }
    try {
      return JSON.parse(JSON.stringify(value));
    } catch (_) {
      // Last fallback: return original (shallow)
      return value;
    }
  }
DougBTX 4 days ago||
> I want everything that passes through a function to be a copy unless I put in a symbol or keyword that it suppose to be passed by reference.

JavaScript doesn’t have references, it is clearer to only use “passed by reference” terminology when writing about code in a language which does have them, like C++ [0].

In JavaScript, if a mutable object is passed to a function, then the function can change the properties on the object, but it is always the same object. When an object is passed by reference, the function can replace the initial object with a completely different one, that isn’t possible in JS.

Better is to distinguish between immutable objects (ints, strings in JS) and mutable ones. A mutable object can be made immutable in JS using Object.freeze [1].

[0] https://en.wikipedia.org/wiki/Reference_(C%2B%2B)

[1] https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe...

hackthemack 4 days ago|||
Thinking on this subject a bit more. I have to wonder if C++ made references just so there is a fast an efficient way to mutate without having to make a copy?

Maybe someone should work on a way to make references in javascript land. Sort of like immer but baked in.

https://immerjs.github.io/immer/

hackthemack 4 days ago|||
I guess in javascript world, the phrasing I am looking for would be

I wish all arguments were copies unless I put some symbol that says, alright, go ahead and give me the original to mutate?

It seems like this way, you reduce side effects, and if you want the speed of just using the originals, you could still do that by using special notation.

jstimpfle 4 days ago|||
Problem is that "copy" of an object is not well defined. It could be a "shallow" copy or a "deep" copy. The only models where "copy" is defined are simple "memory"/"value" models (like C) and immutable models (like Haskell).
hackthemack 4 days ago||
It is a similar idea to what Carmack is writing about. Golang, Clojure does something similar to what I am talking about above so not sure of the motivation behind the voting down of the comment.