Nannying (was: Array comprehension syntax)

Allen Wirfs-Brock allen at
Mon Sep 24 12:04:19 PDT 2012

On Sep 24, 2012, at 10:37 AM, Jason Orendorff wrote:

> I want to defend my kind of nannying.  :-)
> I favor rejecting `if x = y` in comprehensions because it's almost
> always going to be a bug, and a tough bug to diagnose.  Mistaken
> assumptions tend to stay invisible for a long time.  The more
> fundamental the mistake, the harder it is to see.

The argument could validly be made for IfStatement which we cannot change, for compatibility reasons.  To me, if is probably mostly an issue of whether we want consistency between IfStatement and  comprehension if clauses. consistency is good but we've already discussed that we probably don't want to have Expression for if clauses because of comma confusion.  I think this is a discussion that could go either way, it's just good to consider the full range of principles we are factoring into the decision 

> Here's another program I think we should reject, for the same reason:
>    var titles = => {title: b.title});
> The behavior here is really astonishing.  It's hard to see how the
> developer is supposed to figure out what's wrong.  I'm willing to take
> on some implementation complexity to head off this kind of
> frustration.

I agree that this is a real hazard. I think eliminating it requires two token look-ahead.  If that is ok, then we could specify

ConciseBody :
[lookahead  ∉ { { }] AssignmentExpression 
{[lookahead  ∉ { IdentifierName }] [lookahead  ∉ { :}] FunctionBody }

> Beyond likely mistakes, my sympathy for nannying drops off quickly.
> In particular, there's little to gain from trying to enforce
> readability in JS at the language level.  It's just not that kind of
> language.
> -j
> _______________________________________________
> es-discuss mailing list
> es-discuss at

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

More information about the es-discuss mailing list