brendan at mozilla.com
Tue Sep 27 21:52:32 PDT 2011
On Sep 27, 2011, at 4:02 PM, Dean Landolt wrote:
> On Tue, Sep 27, 2011 at 4:57 PM, Brendan Eich <brendan at mozilla.com> wrote:
> On Sep 27, 2011, at 1:21 PM, Dean Landolt wrote:
> > Out of curiosity is there any reason to keep holes the holes around in ObjectLiteral and ArrayLiteral?
> No holes in ObjectLiteral.
> Apologies -- I was thinking of the trailing comma, but that's not at issue.
Right, one (1) comma at end of either object or array literal is a terminator, for uniform maintenance when appending vs. inserting. Very big deal for those of us burned by ANSI C banning trailing single comma in C enum!
> What bugs have you seen due to holes in literas?
> Copy/paste errors, mainly. I'd think the same rationale to justify the trailing comma applies against comma holes in array literals.
Hmm, I think I see what you mean, but the hole case is different enough and anyway it has been in the language for 12 years.
> I've made this mistake more than once. This kind of bug tends to fail fast so it's not as easy to slip into production, but it's still a runtime error.
Ouch. And apologies.
> What's worse, the problem is exacerbated by the fact that tools that lean on Array.prototype.forEach hide the hole, while those that use for(;;) treat it as undefined.
That is a pain. I've heard independently that some people want forEach etc. to fill holes. Can you confirm?
> I understand that this is a problem with holes in general, and not with ArrayLiteral syntax in particular, but try a console.log on a holy array in, for instance, node and then chrome -- you'll get two VERY different-looking results. The way that console.log in node completely papers over array holes, compounded by the popularity of the comma-first style in that community (which makes a double-comma harder to spot),
I find comma first just ugly on aesthetic grounds.
> could be a pretty nasty trap to fall into, even for a js veteran.
Adjacent comma does scream HOLE to me, but that's just me.
> So, if we still have holes, is it really worth getting rid of ArrayLiteral support for them? I think not.
> But are they of any real use for ArrayLiterals? IMHO a hole in a small array (i.e. an ArrayLiteral) is almost always a mistake,
Or a testcase for the otherwise unwanted feature:
Some of those look intentional, and non-testy, though.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the es-discuss