Hacker News new | ask | show | jobs
by hajile 1655 days ago
Are you going to push for records and tuples?

Eich was pushing for them in 2011 and they still haven't arrived.

https://brendaneich.com/2011/01/harmony-of-my-dreams/

4 comments

He doesn’t need to, the authors of the proposal are on the committee and are planning to see it through.

The proposal is humming along through the stages at a good pace.

Exactly. I am very much in favor of them though. They would be a great addition to the language.
Yes, Bloomberg has a big JS investment due to the Terminal (20MLOC of JS last I heard) and they have employed the records and tuples champions.
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.
> 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.

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?

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.
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).

> 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.

Record and Tuple are actively being worked on: https://github.com/tc39/proposal-record-tuple -- currently Stage 2.
Or how about TCO (tail-call optimization)? Please pretty please!
TCO is something that specific JS engines need to implement. It is implemented in JSC (Safari), but not in V8 or SpiderMonkey. Also see https://v8.dev/blog/modern-javascript#proper-tail-calls.

As this is an engine feature rather than a spec thing, there is nothing me (or any other TC39 delegate) can do.

Oh yes, I see, that's true. Thanks for the explanation.
Proper tail calls are ALREADY part of the spec.

Google and Mozilla simply chose to ignore the spec.

More like Google, Mozilla just waits to see if Google is going to implement it since they can't think for themselves.
It would be so nice to have it though! It could do a lot popularize recursive problem-solving and function writing, without having to go into modifying these functions to make them stack-safe.