Rationalizing ASI (was: simple shorter function syntax)

Mark S. Miller erights at google.com
Sun Jul 25 10:52:11 PDT 2010

On Sat, Jul 24, 2010 at 11:46 PM, Brendan Eich <brendan at mozilla.com> wrote:

> On Jul 24, 2010, at 11:30 PM, Mark S. Miller wrote:
> > From: Brendan Eich <brendan at mozilla.com>
> > I see three tenable alternatives:
> >
> > A. Remove ASI in some opt-in version, in full -- no error correction, no
> restricted productions.
> >
> > This seems best to me. I would have no objection to keeping the second
> bullet of ASI rule #1. I may even advocate keeping it; I'm not sure yet.
> However, the first bullet of rule #1 is a terrible hazard.
> Can you say more? It's hazardous because "X, Y, and Z" -- three concrete
> examples.
> The hazard I see, which Garrett Smith mailed me about just now, is the one
> I already identified as "the mistaken expectation of ASI" -- the case where
> there's no syntax error for ASI to correct:
> var MyWidget = function(){
>  this.name = "mike";
> }
> /**
>  * Initialize Widget
>  */
> (function() {
>  /*...*/
> });
> (from http://jibbering.com/faq/notes/code-guidelines/asi.html).
> This is simply a failure to use a semicolon where it is needed.
> Removing ASI won't make this hazard go away unless (eventually, and in
> statistically significant numbers) developers stop "counting" on such
> magical "DWIM" ASI, and become more careful. But that is farfetched, since
> it's pretty easy to make this mistake even if one assiduously inserts
> semicolons manually.

This is a perfect example, and I agree with most of your analysis of it, but
not with your conclusion.

A slightly better example is

    obj.widget = function(){
      this.name = "mike";

since the first one can be easily avoid by using function declarations where
they're appropriate.

The problem is that as long as ASI exists, one will often see working code
such as this, since it does usually work. This training of the eye is a kind
of habituation, and in this case it is insidious because it desensitizes the
programmer from a pattern that *should* look malformed but doesn't. In the
absence of ASI, such code would never normally appear in running code. When
it does appear in running code, that should alert the programmer that their
program violates their intention and needs to be fixed.

> > Yes! Data! Bring it on!
> That's your job :-P. I don't have access to the Google copy of the web, or
> sawzall.
> /be

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20100725/717a5eef/attachment.html>

More information about the es-discuss mailing list