Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is it not somehow redundant with the record & tuple proposal ? #9

Open
lifaon74 opened this issue Oct 1, 2021 · 4 comments
Open

Is it not somehow redundant with the record & tuple proposal ? #9

lifaon74 opened this issue Oct 1, 2021 · 4 comments

Comments

@lifaon74
Copy link

lifaon74 commented Oct 1, 2021

It looks very similar of the record & tuple proposal: https://github.com/tc39/proposal-record-tuple

Your proposal is using prototypes and inheritance instead of plain object. However, it feels better tu use a 'record' instead of struct ? (performance wise, readability and immutability). Do I miss something ?
What feels interesting in this proposal is the possibility to "share" these objects, but we could apply the same logic to 'records' instead

@syg
Copy link
Collaborator

syg commented Oct 1, 2021

The proposals solve different problems. Records and tuples are all about value semantics (i.e. no identity) and immutability. This proposal, in contrast, is all about predictable layout of objects with mutability and identity that can be concurrently accessed.

It's possible that some use cases can overlap, but my hunch is those use cases are the ones that already overlap today where you can use plain objects or a Record. You'd use a Record if you want the immutability and value semantics, and a plain object if you don't.

As for performance, speaking as an implementer, it is unlikely records and tuples will be faster in general.

Does that answer your question?

@lifaon74
Copy link
Author

lifaon74 commented Oct 1, 2021

Yes it answers my question. However, for me tuple and records will be probably faster as they would be converted as fixed length bytecode (ak: c++ struct) by the JIT compiler. I may be wrong.

I agree that having some mutable struct would be great (somehow archived by record when spreading), but currently, it feels like (on my point of view) that using classes and inheritance for that, sounds a little wrong.
For me a struct should not have any constructor nor inherit from something else. It should only describe its shape (properties).

@robbiespeed
Copy link

It's possible that some use cases can overlap, but my hunch is those use cases are the ones that already overlap today where you can use plain objects or a Record. You'd use a Record if you want the immutability and value semantics, and a plain object if you don't.

It seems like this proposal could allow implementing immutable records and tuples in user land, with the same benefits. Might be a good use case to explore. I'd rather have one syntax (structs) that can accomplish both goals, rather than 2 separate ones.

@hax
Copy link
Member

hax commented Sep 15, 2023

Note, it seems R&T proposal has already been blocked (mainly by engine vendors).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants