please add x .= f()

Isiah Meadows isiahmeadows at gmail.com
Tue Aug 11 07:41:59 UTC 2015


Okay... Maybe not CoffeeScript (don't normally use it), but I know a few
notable derivatives have that (particularly Coco and LiveScript).

As for the idea itself, still a -1 from me. Unless we add an equivalent for
every binary operator, it's not much of an addition. It's just another
special case, another band aid. Unless your identifier is 30+ characters, I
don't see much benefit. Unlike with numeric operators or string building,
this isn't nearly as common beyond that one case (string/array slicing).
And for a single character identifier, you're only really saving 1
character. 2 for 2-character identifiers.

There's also no performance gain from it, just sugar. And in the LiveScript
code I've seen (a language with this operator), I still rarely see it.
That's with a community that enjoys experimenting with the syntax, almost
gaming it at times. (Well, there was talk a few months ago about where
sugar can become a problem itself, especially when there's 2-3 ways to
write 7-8 basic constructs. [1])

[1]: https://github.com/gkz/LiveScript/issues/721

On Mon, Aug 10, 2015, 22:27 Bergi <a.d.bergi at web.de> wrote:

> Isiah Meadows schrieb:
> > That's not really the point.
> >
> > The suggestion is this instead:
> >
> > ```js
> > if (s[0] === '/') s = s.slice(1);
> > if (s[0] === '/') s .= slice(1);
> > ```
> >
> > This already exists in CoffeeScript and most derivatives/dialects.
> >
> > ```coffee
> > s .= slice 1 if s[0] is '/'
> > ```
> >
> > Don't know of any other languages that have an equivalent, though.
>
> Really? Which version of CS, or which dialect are you using? It doesn't
> work for me in the online tool
> <
> http://coffeescript.org/#try:s%20%3D%20%22%2Fsomething%22%0As%20.%3D%20slice%201%20if%20s%5B0%5D%20is%20'%2F
> '>.
>
> But if you're that much inclined to save single characters, I'd
> recommend to use
> ```js
> s = s.slice(s[0] == '/');
> ```
>
>   Bergi
> _______________________________________________
> es-discuss mailing list
> es-discuss at mozilla.org
> https://mail.mozilla.org/listinfo/es-discuss
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20150811/91798888/attachment-0001.html>


More information about the es-discuss mailing list