The default bug view has changed. See this FAQ.

rename typed array slice() to subarray()

RESOLVED FIXED

Status

()

Core
JavaScript Engine
RESOLVED FIXED
6 years ago
6 years ago

People

(Reporter: vlad, Assigned: vlad)

Tracking

({dev-doc-complete})

Firefox Tracking Flags

(Not tracked)

Details

(Whiteboard: [softblocker])

Attachments

(2 attachments, 1 obsolete attachment)

We decided last week that we screwed up with the slice() naming, and changed the name of that function to subset().  We should get this change in, so that we can get a real slice() in the future.  (Current slice() creates a new view object, but still references the same underlying data.)  Marking this as a softblocker for API consistency, but I'll post a patch tomorrow.
Why "subset"? There's no sane set-theoretic interpretation. As P. Tucker Withington pointed out, the view objects are like Common Lisp's "Displaced Arrays". Not that you should use that name. "sliceView"?

/be
(Assignee)

Comment 2

6 years ago
Created attachment 508511 [details] [diff] [review]
rename slice -> subset

renamed, and tests updated; also added a test to ensure that subset() behaves as intended (references same buffer).
Assignee: general → vladimir
Attachment #508511 - Flags: review?
CC'ing some others who might get broken by this.  FYI, gentlemen.
(Assignee)

Comment 4

6 years ago
I don't have a good answer as to "why subset", other than that Ken & I liked that name, and it didn't collide with "slice"; the slice wart we should've caught a while ago (and I think Brendan even mentioned it originally :/)
Wow, "subset" smells pretty funky to me... neither the original array nor the result array is a set. I can see how "slice" could be misleading given that array.slice produces a fresh array. How about "subarray"?

Some of the original work on this kind of API was known as "subsequences" since it was about taking pieces of (possibly mutable) sequence types that share references:

    http://portal.acm.org/citation.cfm?id=133234

Seems like a good analogy: subarray : array :: subsequence : sequence. Especially since an array is a kind of sequence.

Dave
subrange, subview, sharedRange, sharedSlice
(Assignee)

Comment 7

6 years ago
I don't think we get to pick a new name at this point... Ken already made the change in WebKit.  Cc'ing him here -- really should get some JS folks involved in the typed array work :)
Fair enough, throwing them out just in case.

As far as JS people getting involved, my understanding is that ECMA is doing its own thing in this space, looking to supplant typed arrays.  See comment 575688 comment 6.
(Assignee)

Comment 9

6 years ago
Comment on attachment 508511 [details] [diff] [review]
rename slice -> subset

(Argh, I hate that you're not :waldo :-)

Yeah, TC39 is doing its own thing, but we have this now and will likely have it for quite a while... we're already depending on it very heavily for a lot of Fx4 launch demos and the like :-)
Attachment #508511 - Flags: review? → review?(jwalden+bmo)
Comment on attachment 508511 [details] [diff] [review]
rename slice -> subset

rs=me assuming it builds and tests out fine.

We should eventually move this over to use the atom stuff and shared const char[] in jsatom.h, but that certainly doesn't need to happen now, nor should it, really.
Attachment #508511 - Flags: review?(jwalden+bmo) → review+

Comment 11

6 years ago
Since we've already broken content with the slice -> subset renaming, I suppose if we quickly renamed it again it wouldn't be that bad.

Of the above suggestions, I like subarray the best. There are more view types of ArrayBuffers than just the Typed Arrays, in particular DataView, which doesn't support this operation. Therefore subview doesn't seem appropriate. subrange seems okay, but if we're adding more letters to the method name it seems to me we might as well keep the name focused on the array-like nature of these objects.

Vlad, what do you think?

Comment 12

6 years ago
"Since we've already broken content with the slice -> subset renaming, I suppose
if we quickly renamed it again it wouldn't be that bad." Let's go 'derper' with the renaming now: http://images0.memegenerator.net/ImageMacro/3784263/we-need-to-go-derper.jpg?imageSize=Medium&generatorName=Inception
(Assignee)

Comment 13

6 years ago
If you're ok with an additional rename, subarray sounds fine, or 'subarrayview', but now maybe we're trying too hard.
+1 on subarray.

(subarrayview is overlong and violates camelCaps -- subarray does not if it's one word, which neologisms and back-formations quickly become, esp. in hacker jargon.)

/be

Comment 15

6 years ago
If we're in agreement on subarray, I'll update the Typed Array spec and conformance tests and do yet another rename on the WebKit side. Vlad?
(Assignee)

Comment 16

6 years ago
sounds good to me, i'll update this patch

Comment 17

6 years ago
ಠ_ಠ
(Assignee)

Comment 18

6 years ago
Created attachment 508837 [details] [diff] [review]
rename slice -> subarray

slice -> subarray!
Attachment #508511 - Attachment is obsolete: true
Attachment #508837 - Flags: review?
(Assignee)

Updated

6 years ago
Attachment #508837 - Flags: review? → review?(jwalden+bmo)

Comment 19

6 years ago
I hope I don't come back here to see that it's been changed another two times.
Comment on attachment 508837 [details] [diff] [review]
rename slice -> subarray

rs=me again
Attachment #508837 - Flags: review?(jwalden+bmo) → review+
(Assignee)

Comment 21

6 years ago
http://hg.mozilla.org/mozilla-central/rev/84c8b33619e0

death to slice, long live subarray.
(Assignee)

Comment 22

6 years ago
argh, the commit comment is wrong; I meant subarray! (code is correct)
Status: NEW → RESOLVED
Last Resolved: 6 years ago
Resolution: --- → FIXED
Summary: rename typed array slice() to subset() → rename typed array slice() to subarray()
This turned tests orange. I checked in a attempted fix:
http://hg.mozilla.org/mozilla-central/rev/808970eca6d5
(In reply to comment #23)
> This turned tests orange. I checked in a attempted fix:
> http://hg.mozilla.org/mozilla-central/rev/808970eca6d5

And the checkin comment/stale bug summary bites. Sicking renamed the calls from slice to subset!

Vlad, can you fix? rs=me

/be
Ugh, didn't realize that the checkin-comment didn't reflect reality. Backed out the whole thing since this has already kept the tree orange for several cycles and my fix was risky enough as I didn't have time to compile a fresh tree and test.

http://hg.mozilla.org/mozilla-central/rev/298c555d0c6e
Status: RESOLVED → REOPENED
Resolution: FIXED → ---
For what it's worth, my patch didn't apparently cover all cases which needed s/slice/subfoo/
(Assignee)

Comment 27

6 years ago
Yeah, sorry -- I tested JS, but forgot that the webgl tests had coverage of this :(  I have everything patched locally (with correct commit message this time), but refreshing my build to make sure everything's good.
(Assignee)

Comment 28

6 years ago
Created attachment 508967 [details] [diff] [review]
update webgl tests

The additional patch.
(Assignee)

Comment 29

6 years ago
relanded with additional webgl test fixes.
Status: REOPENED → RESOLVED
Last Resolved: 6 years ago6 years ago
Resolution: --- → FIXED
Keywords: dev-doc-needed
Reminder that this is one that should have gotten a dev-doc-needed keyword on it. :)

That said, documentation has been updated, thanks to Dave Humphrey's blog post catching my eye.
Keywords: dev-doc-needed → dev-doc-complete
You need to log in before you can comment on or make changes to this bug.