Live data from Hacker News

CoffeeScript 1.7.0

coffeescript.org

21–30 of 91 posts

Re: CoffeeScript 1.7.0

#21
post #17

> Leading . now closes all open calls, allowing for simpler chaining syntax. I feel like this is an important improvement, but I don't really understand what it means. Can someone elaborate on what this means and how it works? How did things used to be different?

Instead of this: $ 'body' .click (e) -> $ '.box' .fadeIn 'fast' .addClass '.active' .css 'marginRight', '10px'

You used to have to do this: $('body') .click (e) -> $('.box') .fadeIn('fast') .addClass('.active') .css 'marginRight', '10px'

Note the extra ( )s, if not used, the next method call is not recognized as a method call but rather part of the previous call's argument. The last method call did not and does not need to be closed with ( ).

This is hugely important for libraries like d3 with super long call chains.

Re: CoffeeScript 1.7.0

#22
post #17

> Leading . now closes all open calls, allowing for simpler chaining syntax. I feel like this is an important improvement, but I don't really understand what it means. Can someone elaborate on what this means and how it works? How did things used to be different?

It would have been nice if their code example for this feature showed how the code would have looked in the prior version of Coffeescript.

It would look like

    result = range(1, 3).concat(range 4, 6).map((x) -> x * x).filter (x) -> x % 2 is 0
or

    result = range 1, 3
    result = result.concat range 4, 6
    result = result.map (x) -> x * x
    result = result.filter (x) -> x % 2 is 0

Re: CoffeeScript 1.7.0

#23
post #17

> Leading . now closes all open calls, allowing for simpler chaining syntax. I feel like this is an important improvement, but I don't really understand what it means. Can someone elaborate on what this means and how it works? How did things used to be different?

It would have been nice if their code example for this feature showed how the code would have looked in the prior version of Coffeescript.

  $('body')
  .click (e) ->
    $('.box')
    .fadeIn('fast')
    .addClass '.active'
  .css 'background', 'white'
If I omit as many parentheses as possible. Also for the other example:

  result = range(1, 3)
    .concat(range 4, 6)
    .map((x) -> x * x)
    .filter (x) -> x % 2 is 0

Re: CoffeeScript 1.7.0

#24

There's also a nice writeup of some of the more user-visible changes available here: https://gist.github.com/aseemk/8637896

(couldn't edit parent, so) Top 3 things tl;dr Paren-free chaining (think jQuery or d3): bar = svg.append 'rect' .attr 'fill', 'papayawhip' .attr 'width', width .attr 'height', 0 .attr 'y', height .attr 'data-hover', data.slug Ellipsis for soaking up matching parameters, even if you don't want to name a variable: [first, ..., last] = arrayOfStuff lastArgumentFn = (..., last) -> last ... and generally improved source m…

And together with source maps significantly improved error reporting. I think that might be important for some people who struggled with CS's syntax.

Re: CoffeeScript 1.7.0

#25
post #5
post #3

Is coffeescript still hip? I used to read a lot about it on here, maybe a year or two. Where is it at? Mainstream?

There has been a development of hate towards CoffeeScript in most JavaScript communities. CoffeeScript seems to be very popular in the non-JS communities that need to write JavaScript, like in the Ruby and Python web development communities. CoffeeScript was designed for non-JS coders to feel a lot more comfortable writing JS.

Like the Node.js community, when they're not busy fighting themselves over gender pronouns.

Re: CoffeeScript 1.7.0

#26
I absolutely love CoffeeScript, with how it structures classes and functions makes sense (plus the python like syntax was a big plus for work). JavaScript seemed to unorganized, unclear, and cluttered for big projects.

Re: CoffeeScript 1.7.0

#27
post #3

Is coffeescript still hip? I used to read a lot about it on here, maybe a year or two. Where is it at? Mainstream?

I think CS is too similar to JS in it's current an upcoming versions to stay relevant in the future. After Harmony the few differences between JS and CS will be trivially fixable by a few macros like Sweet.js.

Personally I moved to LiveScript as it gives me much more syntactic support for functional semantics, without requiring runtime support like ClojureScript (although I'm looking into ClojureScript as well, just not using it in production). But I'm in a privileged position because I could make that choice myself; I think not many people could do this. And they don't, which means if they switched to CS they're effectively stuck with it for some time.

Which, yes, makes CoffeeScript rather mainstream language :)

Re: CoffeeScript 1.7.0

#30

// for integer division instead of comments? Are these guys on crack?

CoffeeScript has always used a single # instead of double // for comments.

In previous versions `//` compiled into an empty regular expression – something a little more difficult to express in JavaScript. But also something pretty much useless — hence the willingness to use it as an operator here.

Post reply on HN