News for hackers. Stuff that matters.
Re:Announcing CoffeeScript 2 by no_wizard on Monday September 18, 2017 @02:46PM (#15278423)
This is honestly the first time I have looked close at CoffeeScript. At a passing glance, it looks really close to Python with javascript elements added in. Is that a correct assessment? If it is, this might be for me.

My other question is: how nice does coffee script play with other libraries? We (unfortunately) use jQuery a lot. I have also been using underscore and lodash as well. Are those two even needed when writing coffee script? I'm kind of assuming not, since they're both largely just adding methods/functions.

Re:Announcing CoffeeScript 2 by ralmidani on Monday September 18, 2017 @02:58PM (#15278512)
If you like Python, you will love CoffeeScript. :)

I have not used Underscore/Lodash in production, but I use jQuery a lot with CoffeeScript. CoffeeScript does not replace jQuery, although it can make your jQuery a lot nicer.

As far as other libraries, there really are no restrictions; CoffeeScript compiles transparently to JavaScript. The only thing holding it back would be poor support in the specific ecosystem you are working with, such as a lack of plugins that automate the build process. In that case, you may need to compile manually or set up your own build script. But other than that, you can use CoffeeScript in place of JS pretty much anywhere.

Re:Announcing CoffeeScript 2 by no_wizard on Monday September 18, 2017 @03:14PM (#15278647)
I figured jQuery would be fine. Now that I think about it, I can't imagine why most things wouldn't really, since all javascript libraries are just extensions of those things.

Does CoffeeScript just convert the modules methods/functions accordingly when needing to be called?

Just curious how that works.

Since so much of JavaScript development, especially nowadays, ties into a lot of frameworks/libraries (modules? I'm not always sure what we want to call it), I just didn't see a reference (maybe I missed it) on their page in regards to what it actually looks like to invoke module/framework/library specific things.

Re:Announcing CoffeeScript 2 by syntheticcdo on Monday September 18, 2017 @11:00PM (#15281460)
I work with a 100% CS code base and lodash chains are a dream working in CS as opposed to vanilla JS, something like:

  capitalStringsWithX = _.chain array
    .map (item) -> item.toUpperCase()
    .filter (item) -> item.includes "X"
    .value()
as opposed to:

  var capitalStringsWithX = _.chain(array)
    .map(function(item) { return item.toUpperCase(); })
    .filter(function(item) { return item.includes("X"); })
    .value();
Re:Announcing CoffeeScript 2 by ralmidani on Monday September 18, 2017 @03:26PM (#15278744)
CoffeeScript does not do anything framework- or library-specific. It simply compiles your code to JavaScript, which is then parsed and executed as usual.
Re:Announcing CoffeeScript 2 by no_wizard on Monday September 18, 2017 @04:44PM (#15279376)
Good point. I guess I'm not making myself clear. If I'm working with jQuery, for instance, do I need to do anything different than I do now in terms of invoking say, the simplest thing, $(function({_..code here.._}) (or for you old schoolers $document.ready({_..code here.._}). Thats what I guess I mean. Maybe I just need to toy with it. I suspect I might be overthinking this in my head.
Re:Announcing CoffeeScript 2 by maxscam on Monday September 18, 2017 @05:03PM (#15279556)
Its actually a great example of Coffeesctipt conciseness, the jQuery ready function is just $ ->
Re:Announcing CoffeeScript 2 by ralmidani on Monday September 18, 2017 @05:06PM (#15279582)
Yeah, play around with the online compiler on the website.

Your jQuery example would simply be written:

$ -> _..code here.._

Re:Announcing CoffeeScript 2 by nickm12 on Monday September 18, 2017 @10:30PM (#15281340)
I love Python, but I always found CoffeeScript took Python's stylistic choices too far. Making {} around object literals and () after function calls optional led to code that was very difficult to visually parse.
Re:Announcing CoffeeScript 2 by molszanski on Tuesday September 19, 2017 @05:52AM (#15283120)
My friend that is using cs every day now was also using () around every function call back in the day. Now he doesn't. I think it is more of a preference that _changes_ over time. Just saying that you might like it the other way one day
Re:Announcing CoffeeScript 2 by nickm12 on Tuesday September 19, 2017 @11:27AM (#15285469)
Maybe. I only used CS for one project, after years of primarily programming Python. I could also believe that, if applied judiciously, the characters could be dropped without harming clarity.

However, the codebase I was working in had no clear style guidelines about when it was acceptable to drop braces/parens and so it left me wanting for Python's "there's one way to do it" aesthetic.

Re:Announcing CoffeeScript 2 by molszanski on Tuesday September 19, 2017 @12:05PM (#15285837)
I agree. It is not advised to introduce confusing syntax if there is a chance that somebody outside of the group would use the code.

It is even more frustrating in .js repositories today. People use various ESXX flavours and syntaxes that might not compatible with each other.

Just look at this list: https://babeljs.io/docs/plugins/ My favorite is: babel-plugin-transform-decorators-legacy (A plugin for Babel 6 that (mostly) replicates the old decorator behavior from Babel 5)

Talk about code reuse

Re:Announcing CoffeeScript 2 by jononor on Tuesday September 19, 2017 @04:46AM (#15282813)
My style guides to avoid this:

- Only use {}-free object literals in assignment

- Always add () to nested single-line function calls, and calls with expressions.

Re:Announcing CoffeeScript 2 by galfarragem on Tuesday September 19, 2017 @05:23AM (#15282990)
IMO Python is way easier to read though..

  def foo(bar):
    a = bar + 1

  vs

  foo = (bar) ->
    a = bar + 1
Re:Announcing CoffeeScript 2 by Justsignedup on Monday September 18, 2017 @02:49PM (#15278441)
CoffeeScript is javascript. It is just a nicer (in some people's opinion) form of javascript. It added some much needed features a few years back, but with recent JS advances the utility of coffeescript are much less than they used to be.

So invoking jquery and everything is totally 100% supported. In fact that is how I used coffeescript a few years ago.

Re:Announcing CoffeeScript 2 by aleph4 on Monday September 18, 2017 @03:02PM (#15278552)
It's "just" Javascript, so it plays quite well with everything. Definitely jQuery. Main issue was that the missing JSX support. It definitely a Pythonic JS, and I much preferred it to JS a few years ago.
Re:Announcing CoffeeScript 2 by rmrfrmrf on Monday September 18, 2017 @05:29PM (#15279764)
Having used CoffeeScript a while back, it's kind of like a weird mix of Ruby, Python, and Perl. With all the good underpinnings of JavaScript, of course.
Re:Announcing CoffeeScript 2 by molszanski on Tuesday September 19, 2017 @05:53AM (#15283132)
I think you might gain a lot from taking a closer look at CoffeeScript.