News for hackers. Stuff that matters.
Re:Deno Joins TC39 by brundolf on Monday December 13, 2021 @11:29AM (#29541084)
I haven’t read the full post, but what’s the benefit of adding language support for records and tuples at this point? My understanding is that engines already optimize the objects/arrays version of those concepts pretty well, and TypeScript enforces the semantics on the dev side.
Re:Deno Joins TC39 by Zababa on Monday December 13, 2021 @11:53AM (#29541345)
> My understanding is that engines already optimize the objects/arrays version of those concepts pretty well

They don't, using libraries that guarantee runtime immutability has a heavy performance cost in JS currently.

Re:Deno Joins TC39 by brundolf on Monday December 13, 2021 @12:14PM (#29541666)
By “object approach” I just meant “making a bunch of objects with the same shape”. I’ve read that V8 can optimize these into flat structs.

Is immutability part of the proposed standard? And if so, what’s the benefit over using Object.freeze?

Re:Deno Joins TC39 by Zababa on Monday December 13, 2021 @12:17PM (#29541709)
Immutability is the whole point of records and tuples. You can read more about them on the proposal: https://github.com/tc39/proposal-record-tuple.
Re:Deno Joins TC39 by brundolf on Monday December 13, 2021 @12:35PM (#29541933)
Ah so these are actual persistent data structures. Got it, that makes more sense.

The use of the term "tuple" here is odd; I've only ever seen it used to describe fixed-width, non-homogenous sequences. These look more like immutable lists (though I guess they can serve both purposes).

Re:Deno Joins TC39 by Zababa on Monday December 13, 2021 @02:39PM (#29543507)
> I've only ever seen it used to describe fixed-width, non-homogenous sequences.

That's what they are here. Array are heterogenous in JS, and tuples are too. And since they're immutable, their size is fixed.

Re:Deno Joins TC39 by brundolf on Monday December 13, 2021 @04:14PM (#29544729)
Technically. I guess what I’m getting at is these are separate use cases that happen to be served by the same data structure in some languages, and “tuple” to me refers to the much less important/powerful use case, which is why I didn’t realize what the term referred to when I first heard about this proposal.

For instance: Rust has tuples that are fixed-length heterogenous sequences, but you can’t actually work with them as sequences in any meaningful way; you can’t map or loop or filter over them. The term “tuple”, to my mind, refers to that “multivalue” or “unlabeled-struct” kind of use case. The fact that we use arrays for that in JS always seemed to me like a historical accident/convenience.