ASI and wrapping long lines

Allen Wirfs-Brock Allen.Wirfs-Brock at microsoft.com
Mon Jul 26 15:29:41 PDT 2010


I confess that I haven't waded through the entire Rationalizing ASI thread.  I generally agree with Brendan concerning the horse and the barn.

However, there was one ASI problem that was raised for which I think we could at least provide a basic remediation:


>We talked at the July 2008 Oslo ("Harmony") meeting about one way to mitigate the unreported dead-code error that results from

>function foo() {

>   if (some) {

>       if (deep) {

>           if (random) {

>               if (logic) {

>                   if (ending) {

>                       if (in_a_very_long) {

>                           return

>                               "I believe in the 80 column limit, so I wrapped";

>                       }

>                   }

>               }

>           }

>       }

>    }

>    return "LOL";

>}

The problem here is that the programmer has a legitimate reason to want to break  a return across two lines and they can't.  There is an easy fix for this.  It's called "line continuation".

In ES5 we standardized the de facto browser behavior for line continuation within string literals:  LineContinuation :: \ LineTerminator Sequence.

A LineContinuation certainly  could also be allowed as an alternative for whitespace.  Then if [no LineTerminator here] is reinterpreted to not match a LineContinuation  then the above return could have been written as:


                           return \

                               "I believe in the 80 column limit, so I used a LineContinuation";

It wouldn't help people who didn't know about line continuation but it would allow those who do know about them the flexibility to format their code the way they want it.  I would normally say a language shouldn't need cruft like this.  However, once you've go down the road of making line breaks syntactically significant it is  arguably reasonable to also allow for  line breaks that explicitly have no syntactic significance.

Allen
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20100726/038715a9/attachment-0001.html>


More information about the es-discuss mailing list