-
Notifications
You must be signed in to change notification settings - Fork 20
Names of functions #10
Comments
Some data that could feed into this discussion. Kotlin has Java has Python has Swift has |
Just to be clear, using past participles makes conversation hard: E.G. "I popped the array." has a fairly easy to understand meaning currently but with different phrasing with past participles it could suddenly mean either the mutating or non-mutating method, which potentially even have differing return expectations. |
Definitely prefer something that reads different enough for eye scanning purposes:
vs. just past tense adding |
We will introduce |
I like the new scheme! Maybe the past tense isn’t even needed:
Upside: Easier to derive the names (which sound more familiar). Downside: Doesn’t map as well to natural language. |
The downside there seems to conflict with the upside - since being closer to natural language makes it easier to derive the names. |
Without past tense, the rules are simpler – just prefix “with”. With past tense, you have to look for a verb (which may or may not be there) and then change it to past tense. I’m also not completely sure that the past tense is really closer to natural language. |
Something else to discuss: If we do go for the |
@acutmore IIRC all current methods use (key, value). For example, |
Yea, I think we should more change |
One idea I had was |
IMHO, this is a mistake. Parity with a deliberately-immutable data structure (Tuples) isn't worth the confusing and inconsistent plethora of new methods. Here's our current list of array-returning verbs:
You really want to add another ~10 methods to that list just to be consistent with an unrelated but superficially-similar object type? I'd rather stick with the familiar
This strikes me as a non-argument. Sure, they're both iterable and array-ish, but so are TypedArrays. A Moreover, how many users will need to construct tuples from other tuples often enough to justify the existence of a . |
I must've paraphrased out the part of my comment that explicitly addresses the naming. Use methods named after their equivalent operations on As for methods that don't sanely carry across to tuples ( Array.prototype.unshift => Tuple.prototype.prepend
Array.prototype.push => Tuple.prototype.append
Array.prototype.pop => Tuple.prototype.slice(-1)
Array.prototype.shift => Tuple.prototype.slice(1) I doubt the last two operations will be common enough to warrant their own methods. |
Quoting myself from the other issue:
(about one year later, these are still my favorites) |
@Alhadis |
@papb What are your thoughts on |
They also carry the idea of mutation to me. For the immutable counterparts, I would suggest |
I think going with the simple past tense and consistent with other languages is a not a bad idea at all. I am not convinced that scanning is an issue, once you're familiar with these methods it is not hard to look out for them since you will just scan for And I think it reads naturally as well.
To me, |
Personally if I saw "with" I'd expect to need to pass a function not that it was in past tense.
This reads a lot better than adding "with" to the start. |
Maybe because I'm not a native English speaker I had this impression but |
@OmgImAlexis I don't... I expect |
I think it's important for these names to be familiar coming from the mutating versions while also making it clear there is a new copy of the array being created. Since I don't think it's been mentioned, I'd like to suggest Do note that this suggestion does not make a distinction between things like |
Another naming scheme that would make the purpose of these functions stand out more might be a prefix of Just throwing that one in the ring :) |
As a non-native english speaker 'withX' is hard to intuitively understandp; much harder than 'copyX' or 'toX'. |
Putting a vote in for
The closest thing to
Like many people I struggled for a long time to remember which was which with |
Agreeing with this comment, and also with either
And so does I have assigned the tuple as popped one. |
Except in contrived cases, 'with' always implies the addition of something. It's therefore a confusing choice for methods that remove elements —
Secondly, it introduces an asymmetry — the past tense of I propose the following scheme:
The odd one out here is |
Wouldn't something like python be a good option? Python array.sort() # (mutating)
sorted(array) # (non-mutating)
array.reverse() # (mutating)
reversed(array) # (non-mutating) Javascript array.sort() // (mutating)
Array.sorted(array) // (non-mutating)
array.reverse() // (mutating)
Array.reversed(array) // (non-mutating) |
|
There is no gain in this regard, i just suggested it to see what you think about this option. |
Is it possible to do the same as it was done with addEventListener and add an options object to the method that will allow to specify the operation type of it if it is mutating or not? I know it will change the response according to mode but this can be expected with regards of setting the option object. |
Thanks for the suggestion. One of the goals of this proposal is to have the same method names across Array/TypedArray and Tuple. So |
For me
Naming aside, I don't see the benefit of putting I mean, if saving 2-4 characters is considered worth it, then Out of the proposed methods, only |
that's true for I actually think the Python ish suggestion wins over all others .. the imho, the requirements are clear, the way forward looks already overly confusing to me. |
Putting in a vote for only problem is also, a bit about the proposal of the word const array = [1, 5, 10];
const newArray = array.copyAt(1, 2);
console.log(newArray); // one could think this should return [1, 10, 10], but this is actually [1, 2, 10] |
Thanks for your input @AnthonyLenglet. I think it can be an option for the |
Hi @zloirock , the key goal of the next Tc39 meeting for us is to get volunteers to review the spec. We will mention that the current names are still very much tbc. But I don’t think we need to update the documents until the new names have been agreed. |
Chiming in as big fan of the One thing I was confused about was |
This comment has been minimized.
This comment has been minimized.
Thanks for chiming in @sarahghp! For reference the “to” column presented at tc39 this week had:
|
Since the most preferred to- prefix schema, I think that in |
See tc39/proposal-record-tuple#121, but we might want to discuss naming before commiting to this.
The text was updated successfully, but these errors were encountered: