Shorthand for "function" keyword

Laurentiu Taschina source.spider at
Fri Nov 10 13:11:15 UTC 2017


I would like to propose the standard allow for shorthand form for the
normal "function" keyword.

No other special meaning, just shorter (preferably at most 4 characters).

*Advantages & Motivation*

   - the keyword often takes as much if not more space then the arguments,
   almost always as much as the name if not more
   - because it's so clunky people are encouraged to abuse arrow functions
   (arrow functions shouldn't have "shorter" as their selling point for when
   they're not needed IMO)
   - only regular functions can have names, but being so clunky people are
   discouraged from using the syntax in favor of short but anonymous arrow
   functions; this is detrimental for stack traces and debugging
   - all other modern languages use the shorter form
   - since it's just an alternative (much like let / const) only with no
   difference in meaning there's no particular drawback (especially if it's
   easy to read an already common alternative name is used)

I believe there are also various subjective "bonus" points, much how arrow
functions and class methods have gotten a lot of love for just being
shorter and people having a personal need for a thing they write a ton
being shorter, but I won't go into those.

I believe the most common, outside of not having a keyword at all, are in
particular order: "fn" (rust), "func" (go) and "def" (ruby, python). Out of
these I believe "func" is the best candidate since it maintains the highest

It should be said that allowing both "func" and "fn" for example is also an
option but the benefits, such as using it to express a difference between
some functions, eg. single use / general / inline, may cause more chaos and
confusion then they're worth. I also personally believe the language should
have a easy way to defined a named arrow function and the keyword "fn" may
be very useful in this sense, ie. fn doStuff(sum, item) => { ... }


None that I can think of.

*Previous Discussion*

Searched the mailing list but could only find "exotic" syntax proposals.
If this has already been discussed please let me know.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the es-discuss mailing list