New ES6 strawman: Array.prototype.fill and Array.prototype.move

Brendan Eich brendan at mozilla.com
Sun Jun 23 18:17:55 PDT 2013


Allen Wirfs-Brock wrote:
> On Jun 23, 2013, at 1:36 PM, Brendan Eich wrote:
>
>> Allen Wirfs-Brock wrote:
>>> See http://wiki.ecmascript.org/doku.php?id=strawman:array_fill_and_move for a strawman proposal for two new Array methods. These are proposed for inclusion in ES6.
>> I updated the wiki:
>>
>>
>> Discussion
>>
>> Q: Does anyone know of a rationale for why (start, end) might be a better design pattern than (start, count) for such operation?
>>
>> A: Array.prototype.slice uses (start, end) where end is a fencepost to facilitate looping over half-open ranges within a larger range. Spec’ing count requires subtracting next_start - end, gratuitously. Also, consistency with slice and range APIs matters. This should be considered carefully in the design.
>
> Yes, both start,end (slice) and start,count  (splice) currently appears in Array methods so it isn't obvious which precedent to follow for best consistency.

The only place anything like (start, count) occurs is 
Array.prototype.splice, where count is deleteCount. There, the operation 
is destructive so one cannot update start in a larger loop over slices 
to the end (start + deleteCount), since that will skip further elements 
after the deleteCount ones that were removed.

So there is no precedent for (start, count) in non-destructive methods, 
and there is no utility in (start, end) for the destructive one.

>   I could go either way.

Nope! :-P

>    It would be nice to have a utilitarian-based argument for one or the other.

You have one here, from me.

Here's another thing, raised on twitter: the "move" name and metaphor is 
wrong. C++ has move semantics (so does Rust). The old memmove chestnut 
(required once upon a time instead of memcpy when source and target 
overlap) is misnamed. We should beware broken precedent -- remember Ken 
Thompson saying he would have spelled creat with a second e if he had 
Unix to do all over ;-).

Brian Kardell suggested copyRange. Not bad, but I prefer copySlice, it 
reinforces the (start, end) pattern.

>    Search result was it because of the -1.

Sorry, I don't know what you mean here.

/be
>
> allen
>
>
>
>
>
>> — /Brendan Eich<mailto:%26%23x62%3B%26%23x72%3B%26%23x65%3B%26%23x6e%3B%26%23x64%3B%26%23x61%3B%26%23x6e%3B%26%23x40%3B%26%23x6d%3B%26%23x6f%3B%26%23x7a%3B%26%23x69%3B%26%23x6c%3B%26%23x6c%3B%26%23x61%3B%26%23x2e%3B%26%23x6f%3B%26%23x72%3B%26%23x67%3B>  2013/06/23 20:31/
>>
>>
>> /be
>>
>
>


More information about the es-discuss mailing list