Re: Paren-free heads strawman
Did you read the proposal? http://wiki.ecmascript.org/doku.php?id=strawman:paren_free Yes, it means if you start a condition with '(' you are obligated to use paren-full not paren-free style. :-P /be On Mon, Feb 1, 2016 at 10:20 AM Andreas Rossberg wrote: > This refactoring hazard is intimately tied to the infinite look-ahead > problem. Teaching a parser to handle the latter case or examples like `if > (x) (y) -z {}` correctly is gonna be all but easy. Either backtracking or > terrifying grammar refactorings would be needed. > > On 1 February 2016 at 18:46, Brendan Eich wrote: > >> On Mon, Feb 1, 2016 at 8:02 AM kdex wrote: >> >>> [Douglas Crockford](https://www.youtube.com/watch?v=Nlqv6NtBXcA) and >>> [Brendan Eich](https://brendaneich.com/2010/11/paren-free/) seem >>> >>> to be in favor of making them optional; that's why the strawman exists. >>> >>> >> The strawman exists because I wrote it, yes. >> >> I was inspired by the common (not ubiquitous) style of always bracing >> sub-statements. The paren-free meme did "stick" with Rust, but it seems >> doomed for JS on account of the problems Waldemar Horwat raised: >> >> https://esdiscuss.org/topic/another-paren-free-gotcha >> >> Not the cited example, that seemed to forget that paren-free requires >> braces around the sub-statement in absence of leading left paren after >> controlling keyword. I pointed this out here: >> >> https://esdiscuss.org/topic/another-paren-free-gotcha#content-9 >> >> Waldemar's other example showed a refactoring hazard: >> >> """ >> >> if (a + b/g > f) f = a + b/g >> >> Convert it to paren-free: >> >> if a + b/g > f {f = a + b/g} >> >> So far so good; it works. However, later someone discovers that the code >> had a logic error, the fix to which is to divide the sum a+b by c instead >> of dividing only b by c. So he fixes the code to: >> >> if (a + b)/g > f {f = (a + b)/g} >> >> """ >> >> Anyway, the proposal predates 1JS (note my last message talks about "opt >> in") and needs a champion who can resolve the refactoring hazard worry (if >> possible). >> >> /be >> >> ___ >> es-discuss mailing list >> es-discuss@mozilla.org >> https://mail.mozilla.org/listinfo/es-discuss >> >> ___ es-discuss mailing list es-discuss@mozilla.org https://mail.mozilla.org/listinfo/es-discuss
Re: Paren-free heads strawman
This refactoring hazard is intimately tied to the infinite look-ahead problem. Teaching a parser to handle the latter case or examples like `if (x) (y) -z {}` correctly is gonna be all but easy. Either backtracking or terrifying grammar refactorings would be needed. On 1 February 2016 at 18:46, Brendan Eich wrote: > On Mon, Feb 1, 2016 at 8:02 AM kdex wrote: > >> [Douglas Crockford](https://www.youtube.com/watch?v=Nlqv6NtBXcA) and >> [Brendan Eich](https://brendaneich.com/2010/11/paren-free/) seem >> >> to be in favor of making them optional; that's why the strawman exists. >> >> > The strawman exists because I wrote it, yes. > > I was inspired by the common (not ubiquitous) style of always bracing > sub-statements. The paren-free meme did "stick" with Rust, but it seems > doomed for JS on account of the problems Waldemar Horwat raised: > > https://esdiscuss.org/topic/another-paren-free-gotcha > > Not the cited example, that seemed to forget that paren-free requires > braces around the sub-statement in absence of leading left paren after > controlling keyword. I pointed this out here: > > https://esdiscuss.org/topic/another-paren-free-gotcha#content-9 > > Waldemar's other example showed a refactoring hazard: > > """ > > if (a + b/g > f) f = a + b/g > > Convert it to paren-free: > > if a + b/g > f {f = a + b/g} > > So far so good; it works. However, later someone discovers that the code > had a logic error, the fix to which is to divide the sum a+b by c instead > of dividing only b by c. So he fixes the code to: > > if (a + b)/g > f {f = (a + b)/g} > > """ > > Anyway, the proposal predates 1JS (note my last message talks about "opt > in") and needs a champion who can resolve the refactoring hazard worry (if > possible). > > /be > > ___ > es-discuss mailing list > es-discuss@mozilla.org > https://mail.mozilla.org/listinfo/es-discuss > > ___ es-discuss mailing list es-discuss@mozilla.org https://mail.mozilla.org/listinfo/es-discuss
Re: Paren-free heads strawman
On Mon, Feb 1, 2016 at 8:02 AM kdex wrote: > [Douglas Crockford](https://www.youtube.com/watch?v=Nlqv6NtBXcA) and > [Brendan Eich](https://brendaneich.com/2010/11/paren-free/) seem > > to be in favor of making them optional; that's why the strawman exists. > > The strawman exists because I wrote it, yes. I was inspired by the common (not ubiquitous) style of always bracing sub-statements. The paren-free meme did "stick" with Rust, but it seems doomed for JS on account of the problems Waldemar Horwat raised: https://esdiscuss.org/topic/another-paren-free-gotcha Not the cited example, that seemed to forget that paren-free requires braces around the sub-statement in absence of leading left paren after controlling keyword. I pointed this out here: https://esdiscuss.org/topic/another-paren-free-gotcha#content-9 Waldemar's other example showed a refactoring hazard: """ if (a + b/g > f) f = a + b/g Convert it to paren-free: if a + b/g > f {f = a + b/g} So far so good; it works. However, later someone discovers that the code had a logic error, the fix to which is to divide the sum a+b by c instead of dividing only b by c. So he fixes the code to: if (a + b)/g > f {f = (a + b)/g} """ Anyway, the proposal predates 1JS (note my last message talks about "opt in") and needs a champion who can resolve the refactoring hazard worry (if possible). /be ___ es-discuss mailing list es-discuss@mozilla.org https://mail.mozilla.org/listinfo/es-discuss
Re: Paren-free heads strawman
Braces required, see the old strawman. /be On Mon, Feb 1, 2016 at 9:18 AM Andreas Rossberg wrote: > Will > > if x (y) (z); > > parse as > > if (x) ((y)(z)); > > or > > if (x(y)) (z); > > ? And how do you parse it without infinite look-ahead? > > /Andreas > > > On 1 February 2016 at 17:01, kdex wrote: > >> Well, try and define "natural" in the context of constructed languages. >> >> If this was a question of "naturalness" (whatever that may be), then >> really any deviation from what the language currently is, is "unnatural". >> >> Anyway, we're here to discuss, not to blindly judge. :) >> >> >> >> Note that the parens serve no purpose whatsoever. >> >> They're actually just a relic dating back to Ken Thompson's >> re-interpretation of BCPL, B (1969), which in turn did this, because in >> FORTRAN, >> >> `if x` and `ifx` looked the same to the parser; the parens were thus >> needed for the parser to differentiate between the two. >> >> >> >> Since C derived from B, virtually any language that derived from it >> adapted to this redundant syntax; nowadays, the parens exist solely for >> decoration. >> >> >> >> [Douglas Crockford](https://www.youtube.com/watch?v=Nlqv6NtBXcA) and >> [Brendan Eich](https://brendaneich.com/2010/11/paren-free/) seem >> >> to be in favor of making them optional; that's why the strawman exists. >> >> >> >> On Montag, 1. Februar 2016 15:47:52 CET Alican Çubukçuoğlu wrote: >> >> > Isn't this very unnatural? If you are into this kind of thing, why don't >> >> > you code Coffee for example? (Or don't since saving a few keystrokes >> isn't >> >> > worth your dignity.) >> >> > >> >> ___ >> es-discuss mailing list >> es-discuss@mozilla.org >> https://mail.mozilla.org/listinfo/es-discuss >> >> > ___ > es-discuss mailing list > es-discuss@mozilla.org > https://mail.mozilla.org/listinfo/es-discuss > ___ es-discuss mailing list es-discuss@mozilla.org https://mail.mozilla.org/listinfo/es-discuss
Re: Paren-free heads strawman
I love the paren-free head idea. But as an obsessive user of non-braced single-statement if/for/while bodies, I don't see the advantage of making the head paren-free at the cost of mandating braces for the body. Has either of the following been considered: ```js if i < 3: foo(); if i < 3 do foo(); ``` -- Bob On Mon, Feb 1, 2016 at 4:43 PM, kdex wrote: > I've noticed that there's a strawman that has been left untouched for > quite a while, namely [strawman:paren_free]( > http://wiki.ecmascript.org/doku.php?id=strawman:paren_free). > > It intends to make parentheses in heads optional, making, for instance: > ```js > if x > 3 { > /* … */ > } > ``` > ___ es-discuss mailing list es-discuss@mozilla.org https://mail.mozilla.org/listinfo/es-discuss
Re: Paren-free heads strawman
Will if x (y) (z); parse as if (x) ((y)(z)); or if (x(y)) (z); ? And how do you parse it without infinite look-ahead? /Andreas On 1 February 2016 at 17:01, kdex wrote: > Well, try and define "natural" in the context of constructed languages. > > If this was a question of "naturalness" (whatever that may be), then > really any deviation from what the language currently is, is "unnatural". > > Anyway, we're here to discuss, not to blindly judge. :) > > > > Note that the parens serve no purpose whatsoever. > > They're actually just a relic dating back to Ken Thompson's > re-interpretation of BCPL, B (1969), which in turn did this, because in > FORTRAN, > > `if x` and `ifx` looked the same to the parser; the parens were thus > needed for the parser to differentiate between the two. > > > > Since C derived from B, virtually any language that derived from it > adapted to this redundant syntax; nowadays, the parens exist solely for > decoration. > > > > [Douglas Crockford](https://www.youtube.com/watch?v=Nlqv6NtBXcA) and > [Brendan Eich](https://brendaneich.com/2010/11/paren-free/) seem > > to be in favor of making them optional; that's why the strawman exists. > > > > On Montag, 1. Februar 2016 15:47:52 CET Alican Çubukçuoğlu wrote: > > > Isn't this very unnatural? If you are into this kind of thing, why don't > > > you code Coffee for example? (Or don't since saving a few keystrokes > isn't > > > worth your dignity.) > > > > > ___ > es-discuss mailing list > es-discuss@mozilla.org > https://mail.mozilla.org/listinfo/es-discuss > > ___ es-discuss mailing list es-discuss@mozilla.org https://mail.mozilla.org/listinfo/es-discuss
Re: Paren-free heads strawman
Well, try and define "natural" in the context of constructed languages. If this was a question of "naturalness" (whatever that may be), then really any deviation from what the language currently is, is "unnatural". Anyway, we're here to discuss, not to blindly judge. :) Note that the parens serve no purpose whatsoever. They're actually just a relic dating back to Ken Thompson's re-interpretation of BCPL, B (1969), which in turn did this, because in FORTRAN, `if x` and `ifx` looked the same to the parser; the parens were thus needed for the parser to differentiate between the two. Since C derived from B, virtually any language that derived from it adapted to this redundant syntax; nowadays, the parens exist solely for decoration. [Douglas Crockford](https://www.youtube.com/watch?v=Nlqv6NtBXcA) and [Brendan Eich](https://brendaneich.com/2010/11/paren-free/) seem to be in favor of making them optional; that's why the strawman exists. On Montag, 1. Februar 2016 15:47:52 CET Alican Çubukçuoğlu wrote: > Isn't this very unnatural? If you are into this kind of thing, why don't > you code Coffee for example? (Or don't since saving a few keystrokes isn't > worth your dignity.) > ___ es-discuss mailing list es-discuss@mozilla.org https://mail.mozilla.org/listinfo/es-discuss
Re: Re: Paren-free heads strawman
Isn't this very unnatural? If you are into this kind of thing, why don't you code Coffee for example? (Or don't since saving a few keystrokes isn't worth your dignity.) ___ es-discuss mailing list es-discuss@mozilla.org https://mail.mozilla.org/listinfo/es-discuss
Paren-free heads strawman
I've noticed that there's a strawman that has been left untouched for quite a while, namely [strawman:paren_free](http://wiki.ecmascript.org/doku.php?id=strawman:paren_free). It intends to make parentheses in heads optional, making, for instance: ```js if x > 3 { /* … */ } ``` equivalent to: ```js if (x > 3) { /* … */ } ``` Does anyone know if there are still any efforts to bring this into a future version of EcmaScript? The strawman hasn't been updated for five years, and I have the feeling that this addition was forgotten about. The last time I've heard anyone from TC39 talk about paren-free heads was at [GOTO Aarhus 2013](https://www.youtube.com/watch?v=Nlqv6NtBXcA). Note that the strawman also talks about backward compatibility: > For backward compatibility, we support parenthesized heads with any > sub-statement. To preserve the LR(1) grammar this requires factoring out > OtherStatement. > > Thus, this proposal is intended to make no backward-incompatible syntactic or > semantic changes to ES5. “Paren-free” is now > purely a relaxation of syntax > rules. If anyone seeks to try this out, Mozilla's [Narcissus](https://github.com/mozilla/narcissus/) has been supporting it for years now. You can enable it via `--paren-free`. ___ es-discuss mailing list es-discuss@mozilla.org https://mail.mozilla.org/listinfo/es-discuss
Paren-free heads strawman
I've noticed that there's a strawman that has been left untouched for quite a while, namely [strawman:paren_free](http://wiki.ecmascript.org/doku.php?id=strawman:paren_free). It intends to make parentheses in heads optional, making, for instance: ```js if x > 3 { /* … */ } ``` equivalent to: ```js if (x > 3) { /* … */ } ``` Does anyone know if there are still any efforts to bring this into a future version of EcmaScript? The strawman hasn't been updated for five years, and I have the feeling that this addition was forgotten about. The last time I've heard anyone from TC39 talk about paren-free heads was at [GOTO Aarhus 2013](https://www.youtube.com/watch?v=Nlqv6NtBXcA). Note that the strawman also talks about backward compatibility: > For backward compatibility, we support parenthesized heads with any > sub-statement. To preserve the LR(1) grammar this requires factoring out > OtherStatement. > > Thus, this proposal is intended to make no backward-incompatible syntactic or > semantic changes to ES5. “Paren-free” is now > purely a relaxation of syntax > rules. If anyone seeks to try this out, Mozilla's [Narcissus](https://github.com/mozilla/narcissus/) has been supporting it for years now. You can enable it via `--paren-free`. ___ es-discuss mailing list es-discuss@mozilla.org https://mail.mozilla.org/listinfo/es-discuss