Why is concise body for method definition dropped?

Brendan Eich brendan at mozilla.com
Wed Jun 5 17:43:38 PDT 2013


[Resending my 1:1 reply. /be]

We decisively rejected statement-level Tennent's Correspondence 
Principle when I did a stand-up routine at the March 2012 TC39 meeting 
and thereby got arrow function syntax accepted:

https://mail.mozilla.org/pipermail/es-discuss/2012-March/021872.html

C/Java/JS are not Rust or ML. Can't start fresh. In particular, we don't 
want return/break/continue to satisfy TCP. We also don't want unintended 
completion-value leaks that are inevitable doing what you propose.

/be

Brian Di Palma wrote:
> Was there any desire to support Rust style expressions if enclosed
> within '{}' i.e.
>
> class C {
>      method( x ) {  x + x }
> }
>
> So the same as in Rust, the last value is returned if no ';' is used
> to turn the line into a statement?
>
> It's quite elegant and I would imagine is a safer approach?
>
> On Wed, Jun 5, 2013 at 4:38 PM, Brendan Eich<brendan at mozilla.com>  wrote:
>> Matthew Robb wrote:
>>> At one point I was under the impression that the following would produce 
>>>
>>> an implicit return method:
>>>
>>> class x {
>>>     method(x) x+x
>>> }
>> We dropped it. Maybe Rick can find the meeting notes -- I'm short on time 
>>
>> due to travel today. The problem is you must terminate with a ; or else the 
>>
>> expression body may continue into what the user intended to be a subsequent 
>>
>> property name, especially one of the form we considered (but ultimately
>> rejected for now):
>>
>>    class C {
>>      method(x) x+x
>>      [symbol]: 42
>>    }
>>
>> If there was no syntax error, then ASI does not apply.
>>
>> Now we could reckon that [computed-property-name] is "out", so we can put 
>>
>> expression body back "in" -- but the future-fragility if not
>> future-hostility stayed our hands from doing this. I think that's the right 
>>
>> call, still.
>>
>> /be
>>
>>> On Wed, Jun 5, 2013 at 8:07 AM, Rick Waldron<waldron.rick at gmail.com
>>> <mailto:waldron.rick at gmail.com>>  wrote:
>>>
>>>
>>>
>>>
>>>      On Wed, Jun 5, 2013 at 10:56 AM, Matthew Robb
>>> <matthewwrobb at gmail.com<mailto:matthewwrobb at gmail.com>>  wrote:
>>>
>>>          Does a concise body method still return by default?
>>>
>>>
>>>      ArrowFunction offers implicit return in the unbraced form:
>>>
>>>      let two = () =>  1 + 1;
>>>      two(); // 2
>>>
>>>      Whereas the braced form requires an explicit return, otherwise
>>>      returning the default undefined.
>>>
>>>      Rick
>>>
>>>
>>>
>>>       /snip
>>>
>>>
>>>
>>>
>>> -- 
>>> - Matthew Robb
>>> _______________________________________________
>>> es-discuss mailing list
>>> es-discuss at mozilla.org
>>> https://mail.mozilla.org/listinfo/es-discuss
>> _______________________________________________
>> es-discuss mailing list
>> es-discuss at mozilla.org
>> https://mail.mozilla.org/listinfo/es-discuss


More information about the es-discuss mailing list