Suggestions for Set

Mark S. Miller erights at
Wed Oct 3 13:07:27 PDT 2012

I can't imagine actually getting consensus on making the current default
change from sparse to dense. We've rejected many breaking changes that were
less breaking than this would be.

The subclass notion is interesting though. Reads dominate writes, and
frozen arrays can only be read anyway. Liskov substitutability on reads
suggests that dense arrays be a subclass of sparse -- it provides stronger
guarantees. Arranging the subclassing that way would also not be a breaking

On Wed, Oct 3, 2012 at 9:03 AM, Allen Wirfs-Brock <allen at>wrote:

> A couple observations:
> 1) this whole issue is only relevant  if you actually have array objects
> containing holes.  Special treat for sparse arrays doesn't hurt anybody
> (other than implementors)  who doesn't use them.
> 2)  If we (and the broader developer community) don't like sparse behavior
> for Array then rather than introducing additional inconsistencies about the
> handling of hole (for example, making Array.forEach and for-of on a sparse
> array different)  it would be better to simply see if we can eliminate (or
> compartmentalize) the sparse behavior of arrays.
> Some possible approaches
> 1)  Make all array instances dense and see what really breaks.  Possibly
> provide a new SparseArray "subclass". Anyone brave enough to do the
> experiment?
> 2)  Formalize the concept of sparseness into either a selectable attribute
> of arrays or as a special "subclass" of array.  Most current obviously
> non-sparse usages get the dense version:
> var aDenseArray = [0,1,2,3,4,5,6,7];
> var aSparseArray = [,,,,,,7];
> console.log.(aDenseArray.isSparse());  //false
> console.log.(aSparseArray.isSparse());  //true
> var dense2 = new Array(0,1,2,3,4,5);
> var dense3 = new Array(1000);
> console.log.(dense3.isSparse());  //false
> var sparse2 = new Array(1001);
> console.log.(dense3.isSparse());  //true
> var sparse3 = Array.sparse();
> console.log.(sparse3.isSparse());  //true
> Allen
> _______________________________________________
> es-discuss mailing list
> es-discuss at

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the es-discuss mailing list