Skip to content
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

Placement and name of "from{Base64,Hex}Into" #41

Closed
anba opened this issue Jan 23, 2024 · 2 comments · Fixed by #45
Closed

Placement and name of "from{Base64,Hex}Into" #41

anba opened this issue Jan 23, 2024 · 2 comments · Fixed by #45

Comments

@anba
Copy link
Contributor

anba commented Jan 23, 2024

Uint8Array.fromBase64Into and Uint8Array.fromHexInto don't match the normal naming and placement of methods:

  • Array.from, %TypedArray%.from, and the new Uint8Array.fromBase64 and Uint8Array.fromHex create new objects, indicated by the "from" prefix. from{Base64,Hex}Into don't create a new object, but instead modify existing objects. [1]
  • from{Base64,Hex}Into modify existing objects, but aren't placed on Uint8Array.prototype, but are instead methods placed on the constructor Uint8Array. [2]

I don't have concrete suggestions how to change this, but at least I wanted to open an issue, so in case the current names and placements will stay, it's documented that this was an intentional design choice.


[1] Here we could argue that the additional suffix "Into" indicates that the method doesn't create a new object.
[2] Here I'd guess the obvious explanation is that this improves discoverability when the names are similar to Uint8Array.from{Base64,Hex}.

@bakkot
Copy link
Collaborator

bakkot commented Jan 23, 2024

This was indeed an intentional design choice. The fromXInto methods are close cousins of the fromX methods, despite having a different return type.

I guess be OK with moving these to .prototype.setBase64 or something, but I'm a little happier with the current placement. I'll leave this open for now though.

@ljharb
Copy link
Member

ljharb commented Jan 23, 2024

It does make sense to me for mutating methods to be on the prototype, even if the names are similar.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants