Rationalizing ASI (was: simple shorter function syntax)

Zachary Carter zack.carter at gmail.com
Mon Jul 26 07:44:22 PDT 2010


On Mon, Jul 26, 2010 at 2:46 AM, Dmitry A. Soshnikov <
dmitry.soshnikov at gmail.com> wrote:

> On 26.07.2010 4:11, Maciej Stachowiak wrote:
>
>> On Jul 25, 2010, at 5:06 PM, Brendan Eich wrote:
>>
>>
>>
>>> On Jul 25, 2010, at 4:59 PM, Maciej Stachowiak wrote:
>>>
>>>
>>>
>>>> On Jul 25, 2010, at 11:36 AM, Brendan Eich wrote:
>>>>
>>>>
>>>>
>>>>> Let's not go in circles. I claim:
>>>>>
>>>>> * The horses are long gone from the barn.
>>>>> * The mistake is easy to overlook even for JS coders who do use
>>>>> semicolons.
>>>>> * The trade-off of banning ASI rule 1 first bullet to reduce
>>>>> desensitization and eventually reduce the incidence of this kind of bug is
>>>>> not a clear win, vs. migration tax into Harmony and usability problems even
>>>>> writing fresh code.
>>>>>
>>>>> In order to reliably remove this hazard, we would need to ban
>>>>> statements from starting with '('. Perhaps we should consider doing so.
>>>>>
>>>>>
>>>> Banning statements from starting with '(' would remove one of the
>>>> easiest workarounds for the rules against statements starting with
>>>> 'function' or statements starting with '{'.
>>>>
>>>>
>>> Yeah, that's too harsh -- you'd have to use an operator or assign to a
>>> dummy variable or declare an initialized binding.
>>>
>>> Mark's restricted production idea is on target, if we think it's worth
>>> doing.
>>>
>>>
>> At least in C or C++, I've seen code like this:
>>
>>
>> veryLongObjectName.someOtherVeryVeryLongObjectName.ridiculouslyLongFunctionName
>>     (longArgument1, longArgument2, longArgument3, longArgument4,
>> longArgument5);
>>
>> If I understand correctly, Mark's proposal would make that a syntax error
>> in JavaScript. I'm not sure offhand if JavaScript programmers write in this
>> style, or would find the loss annoying. Of course, you could always write
>> this as a single very long line, or make sure that at least the open paren
>> is on the first line, but programmers can be picky about questions of style
>> like this.
>>
>>
>>
>
> There is interesting "declarative" pattern which looks nicer if to place
> '(' on the next line. This pattern uses self-reproducible (or
> self-replicative) function -- when a function returns itself.
>
> Instead of imperative:
>
> myApp.keys.register([
>  ['w', panNorth],
>  ['s', panSouth],
>  ['a', panWest],
>  ['d', panEast]
> ]);
>
> Can be used (just declare keys):
>
> myApp.keys
>  ('w', panNorth)
>  ('s', panSouth)
>  ('a', panWest)
>  ('d', panEast);


The (fab) library for Node takes this pattern to the extreme:

var fab = require("fab");

( fab )

  ( listen, 0xFAB )

  ( /^\/hello/ )

    ( tmpl )
      ( "Hello, <%= this %>!" )

    ( /^\/(\w+)$/ )
      ( capture.at, 0 )
      ( "world" )

  ( 404 );

http://github.com/jed/fab


>
> But in general, yeah, programmers tries to use '(' at the same line:
>
> someFunction(
>  argument,
>  otherData
> );
>
> Dmitry.


>
>  Regards,
>> Maciej
>>
>>
>> _______________________________________________
>> 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
>


-- 
Zach Carter
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20100726/8126bcf2/attachment.html>


More information about the es-discuss mailing list