ASI and wrapping long lines

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

ASI and wrapping long lines

Allen Wirfs-Brock-2

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


_______________________________________________
es-discuss mailing list
[hidden email]
https://mail.mozilla.org/listinfo/es-discuss
Reply | Threaded
Open this post in threaded view
|

Re: ASI and wrapping long lines

Irakli Gozalishvili
Another pattern of solving this that people writing semicolonless code already employ is:

function a() {
    return (
        "some string"
    )
}

Regards
--
Irakli Gozalishvili
Web: http://www.jeditoolkit.com/
Phone: +31 614 205275
Address: 29 Rue Saint-Georges, 75009 Paris, France


On Tue, Jul 27, 2010 at 00:29, Allen Wirfs-Brock <[hidden email]> wrote:

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


_______________________________________________
es-discuss mailing list
[hidden email]
https://mail.mozilla.org/listinfo/es-discuss



_______________________________________________
es-discuss mailing list
[hidden email]
https://mail.mozilla.org/listinfo/es-discuss