tc39 / proposal-iterator.range

A proposal for ECMAScript to add a built-in Iterator.range()
https://tc39.es/proposal-iterator.range/
MIT License
487 stars 13 forks source link

parameter names #29

Closed Andrew-Cottrell closed 4 years ago

Andrew-Cottrell commented 4 years ago

The parameter names mentioned in the spec might be unimportant, but potentially they would eventually be copied to MDN, online examples, and other training materials.

The spec currently names the parameters from and to.

So, I want to think about alternative names that might be a better fit for ECMAScript.

This leads to my opening suggestion

Jack-Works commented 4 years ago

The name to may confuse as the range does not yield the to value.

Hmm, it's (from, to] (exclusive from, inclusive to)

IMO start and done doesn't become a pair, start / end might be better name.

Andrew-Cottrell commented 4 years ago

Hmm, it's (from, to] (exclusive from, inclusive to)

That is contrary to what I conclude while reading the spec.

On the first iteration at 5.1.22.a the currentCount should be zero, so lastValue === from, and lastValue is not modified before being yielded at 5.1.22.g.

In an increasing range, when lastValue becomes >= to, the range is done at 5.1.22.c. In a decreasing range, when lastValue becomes <= to, the range is done at 5.1.22.d.

Is the spec out of date with current thinking, or am I reading it wrong?

Jack-Works commented 4 years ago

Ah! I'm very sorry, my mind doesn't clear today... Yes, you're right, the design is [from, to) currently. And I'm going to refine the spec to make it easier to read (with no spec change).

On the other hand, https://tc39.es/proposal-Number.range/playground.html you can try it on the playground. The playground is one-to-one implemented the spec so it will be easier to track spec variables to verify your thought.

Andrew-Cottrell commented 4 years ago

IMO start and done doesn't become a pair, start / end might be better name.

The pair start/end looks good to me. My implementation previously used begin/end, which is basically the same thing; but has just now changed to use start/end.

Notably, the specification of Array.prototype.copyWithin, Array.prototype.fill, and Array.prototype.slice each use start/end with inclusive start and exclusive end.

Any future documentation will need to be clear the iterator is done once the end value is hit, or passed, and will not yield the end value; similar to the MDN document for those Array.prototype methods.