tc39/proposal-arraybuffer-base64

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

anba opened this issue · 2 comments

anba commented

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}.

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.

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