-
Notifications
You must be signed in to change notification settings - Fork 62
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
Naming #82
Comments
Tuples aren't just immutable arrays, because they have value semantics. Value semantics means that tuples are both immutable and that comparisons between tuples are structural and not referential. |
I agree with @slikts, since tuples are a special kind of immutable arrays, it is even better to have another name, preventing people from thinking they are nothing more than an immutable array |
echoing the other comments, the problem with calling them "immutable objects" and "immutable arrays" is that they are not objects or arrays (which are objects), because they are primitive values and have value semantics (as @slikts has mentioned). If we called them immutable objects/arrays, I would expect them to have prototypes, identity, and all of the other properties that objects have that "values" don't (string, number, etc) given the above, we think |
I for one am sold on “tuple”. Is there prior art for “record” being a value type? What other names could fit the bill there? |
struct |
I ended up naming them Python has something called "named tuples" which resembles an object, but the names of the tuple members don't affect the value of the tuple. |
Many functional languages with diverse typing disciplines call these things "records". Not sure if this is counts as "prior art," but this is where I know the term from. |
The champion group is strongly favoring the current naming. That being said, if being presented with strong arguments for another naming before stage 3, we are open to change it. |
I'm not educated in type theory, so I had to do some research on the nomenclature. If I'm mistaken in some of this, please jump in and correct me. Tuple is mainly described as a mathematical concept on Wikipedia. When the name is used in functional programming languages, it appears to be associated with algebraic data types, pattern matching and destructuring assignments. In this aspect, the proposal deviates from "prior art". Not that that's a bad thing!
Structure and Dictionary are also used. Strictly speaking, they're Associative arrays. What names could apply to List is the name of the abstract data type that applies to arrays. Arguably a more accurate name than tuple? Other languages that have List as an immutable array include Scala and Kotlin, while in Python it's a dynamic array, and of course a linked list in the Lisp-family.
Sequence is another mathematical concept that may be used to describe lists.
Alternative names for Tuple:
Alternative names for Record:
Sorry for complicating things :) |
Lists and sequences don’t connote fixed-length to me; Tuple does. |
@ljharb I somewhat agree. The most accurate name is actually |
I don’t think that’s the most accurate name either - arrays are not universally fixed-size, even outside JavaScript. |
I suppose you're right. Wikipedia seems to take "array" to mean static array by default, as opposed to dynamic, probably a remnant from ancient languages like C. |
Reading on @joakim answer (zero expertise on type theory too, just my 2 cents), I was thinking the same thing. I don't think we should use for |
Thus, my favorite alternatives are FixedArray and FixedObject, so far. |
Many newcomers are already surprised by |
Regarding the TypeScript naming clash, we do intend to find an effective way to disambiguate with the current Record & Tuple naming, we are currently working on a suggestion for that. Our champion group has been looking at alternative naming multiple times over the past few years, unfortunately finding an alternative is hard. We found that all alternatives using "Object" or "Array" in them are difficult to pull off specifically because Record & Tuple are, by nature, not Objects or Arrays, whatever prefix we put in front of them. At this point, any new naming needs to pass a very high bar: it needs to differentiate itself from Objects and Arrays, it needs to stay short while being representative enough because by this point, a change of naming is a change of all communication around the proposal. That is fine if we find something truly more representative (but that might be based on subjective opinions), otherwise staying the course makes the most sense for us. |
@rricard Good points! Then TypeScript might have to change (but it’ll be painful…):
To my eyes, there is no good alternative to “tuple” for the proposed JavaScript feature. “Record” and “struct” both work well, but given that |
Those are good suggestions @rauschma! They are pretty much in line with what we had in mind but I personally prefer the naming you are proposing to replace and disambiguate. Yes, it will be painful (I do work with a lot of TS on a day to day basis and Record is used a lot!). We looked a lot (and are still looking) at possible alternatives but the more time advances the harder it gets to change naming... |
We are going to stay with Record & Tuple as we did not find better alternatives to it and branding on the proposal is established. |
Hi guys,
Nice feature, I can't wait to be able to work with native immutable data structures in the future. I'm just not sure about the terminology:
I was mostly unfamiliar with the proper meaning of records and tuples before now, so I did a little research. What I found is that they represent simpler and more generic ideas than what this proposal introduced. Also, some programming languages use these terminologies but differently than how this proposal intends to implement them.
I'd propose just to stick with "immutable objects" and "immutable arrays".
Imagine your average JS dev. Already familiar with objects and arrays, probably already familiar with immutability thanks to React. It is easier for them to grasp the meaning of an "immutable array" than a "touple", even if they are the same thing.
I don't really see a drawback of simply prefixing already known features with "immutable" to name these features. It's boring. It's a bit longer. On the other hand, we get a simple, easy-to-understand naming which then can be applied to other data structures in the future (for example immutable maps or immutable dates)
The text was updated successfully, but these errors were encountered: