Maybe ban holes, then... (was: Re: lexical for-in/for-of loose end)

# Herby Vojčík (14 years ago)

Allen Wirfs-Brock wrote:

That said, I'd hate to see things like:

[,,,,,x] = someArray;

and even [a,,y] = someArray;

can be easily missed.

It isn't clear to me that we are doing ES programmers (especially those with poor eyesight) a favor by allowing such expressions. What is the evidence with JS1.7 up. How much usage do we see of such holes?

If

{"5":x} = someArray;

and

{"0":a, "2":y} = someArray;

would be possible, there is probably little need for holes. In case of

[a,b,c,d,,f] = someArray;

one could always use (some conventional) anon-var, like _ (from Prolog):

[a,b,c,d,_,f] = someArray;

# Allen Wirfs-Brock (14 years ago)

On Feb 2, 2012, at 11:49 AM, Herby Vojčík wrote:

Allen Wirfs-Brock wrote:

That said, I'd hate to see things like:

[,,,,,x] = someArray;

and even [a,,y] = someArray;

can be easily missed.

It isn't clear to me that we are doing ES programmers (especially those with poor eyesight) a favor by allowing such expressions. What is the evidence with JS1.7 up. How much usage do we see of such holes?

If

{"5":x} = someArray;

and

{"0":a, "2":y} = someArray;

would be possible, there is probably little need for holes. In case of

+1

It isn't just possible, it is already specified as valid. and you don't need the quotes around the array indices. But you need a set of params to deal with the expression statement can't start with { problem. This wouldn't be the case for binding position destructuring.

({5:x} = someArray); ({0:a, 2:y} = someArray);

[a,b,c,d,,f] = someArray;

[a,b,c,d,...{1:f}] = someArray;

the above works for de-structuring asignments (where each destructuring element including ... targets a LHS expression} but not for binding forms where ... must be followed by an identifier. I suppose we could allow BindingPattern instead of BindingIdentifier after the ... but maybe that is a step too far??

# Brendan Eich (14 years ago)

This is all unwanted "innovation". We have holes in arrays, and in SpiderMonkey and Rhino we've had holes in destructuring array patterns for years. No one got confused or went blind. We should stop nanny-ing about holes.

Some of you don't like holes, but they're not going away in arrays. They are useful in array patterns to avoid _ or junk bindings. That's enough to keep them, rather than straining to invent more cumbersome ad-hoc replacements.

# Herby Vojčík (14 years ago)

Allen Wirfs-Brock wrote:

It isn't just possible, it is already specified as valid. and youdon't need the quotes around the array indices. But you need a set ofparams to deal with the expression statement can't start with { problem. This wouldn't be the case for binding position destructuring.

({5:x} = someArray); ({0:a, 2:y} = someArray);

A bit off-topic... I don't like paretheses. Not only because I have to put them in both ends, but also because of uncomfortable feeling of "thing closed in parentheses".

Maybe alternative convention to deal with expressions beginning with { could be used as well:

0, {5:x} = someArray; 0, {0:a, 2:y} = someArray;

# Andreas Rossberg (14 years ago)

On 2 February 2012 21:19, Brendan Eich <brendan at mozilla.org> wrote:

Some of you don't like holes, but they're not going away in arrays. They are useful in array patterns to avoid _ or junk bindings. That's enough to keep them, rather than straining to invent more cumbersome ad-hoc replacements.

Are you implying that wildcards are more ad-hoc than array holes? That doesn't add up for me.