Suggestions for the proposed ByteArray in ES4

Steven Johnson stejohns at adobe.com
Thu Jan 18 09:53:10 PST 2007


On 1/17/07 8:46 PM, "Jeff Walden" <jwalden at MIT.EDU> wrote:

> http://developer.mozilla.org/es4/proposals/bytearray.html
> 
> What was the rationale for disallowing use of array literals for initializing
> a ByteArray?  As described now, there exists no way to seed a ByteArray with
> values other than by using some host functionality to create it (or, of
> course, by manually assigning).

I think the concern was one of typing: given the expression [ 1, 2, 3 ],
what type is it, Array or ByteArray? ( Perhaps we could use an explicit type
annotation, e.g., [1,2,3]:ByteArray ... ) The point being that Array and
ByteArray aren't interchangeable (Array provides much more functionality).

I suppose we could allow array literals to be coerced to ByteArray, though,
and it could probably be optimized at compiletime in many cases.

But yeah, SOME way to do literal initialization would be a good idea.

> ByteArray instances certainly don't need all 30-odd methods included in the AS
> implementation (especially since the thrust of the AS ByteArray is basically
> to act like an input/output stream).  However, ByteArray does need some
> methods to actually be usable; assigning index-by-index is painful and ugly.
> I think it makes sense to copy /some/ of the methods over from Array to
> ByteArray, keeping in mind how ByteArray would actually be used.

[snip] Agreed. The proposal was written in a deliberately minimal form to
try to keep implementation cost low and thus increase the likelihood of
acceptance, but the methods you mention sound worthwhile and of tiny
overhead.

(The AS methods are quite useful, though :-)

> One last suggestion: ByteArray should support slice notation, with the result
> referencing the original ByteArray (i.e., mutating the result of a slice of a
> ByteArray modifies the original) so long as the step is 1 and the slice is not
> a copying slice (copy = byteArray[:]).

Oooh, yeah, that sounds like a good idea.




More information about the Es4-discuss mailing list