Live data from Hacker News

CoffeeScript 1.7.0

coffeescript.org

81–90 of 91 posts

Re: CoffeeScript 1.7.0

#81
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…

The point of CoffeeScript is not to be "different" from JS, it's supposed to be easier than JS. It moves the language out of your way, that is all.

Re: CoffeeScript 1.7.0

#82
post #5

Earlier quoted context omitted.

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.

There has been a development of hate towards CoffeeScript in most JavaScript communities. This is FUD. CoffeeScript is JavaScript, and if you come into CoffeeScript thinking it works like ruby just because it looks like ruby then you're in for a rude awakening. Personally, I'm a fan of CoffeeScript's streamlined syntax compared to JavaScript. For example: describe 'when the universe exists', -> it 'should be active',…

You can get even nicer and more useful (due to generated assertion messages) with Sweet.js macros (https://github.com/andreypopp/sweet-assertions)

  describe 'when the universe exists' {
    it 'should be active' {
      universe.active should be true
    }
  }
The pre-generated assertion messages means you get `universe.active should be true` in case of error which includes actual source of the expression.

Re: CoffeeScript 1.7.0

#83

Earlier quoted context omitted.

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…

The point of CoffeeScript is not to be "different" from JS, it's supposed to be easier than JS. It moves the language out of your way, that is all.

Agreed, but where do "different" begin and where it's still "just JavaScript"? Almost all patterns supported by LiveScript syntax are already present in JS and CS as a libraries. For example the cascade syntax in LS is almost the same as what raganwald's KaTy.js provides semantically. Similarly, function composition is supported by more than one library (Underscore.js has "compose", for example) and currying is also easily implemented in both JS and CS (see raganwald's writings, for example http://raganwald.com/2013/03/07/currying-and-partial-applica...), so once again the only thing LiveScript provides is a bit of syntactic sugar. Is it really that different from Coffee or JS?

In my opinion LiveScript is as similar to JS as Coffee is, just where CS adds syntactic support for more imperatively and OOP oriented constructs LS focuses on functional and declarative ones. Which are all expressible in JS.

Actually "different" would be ClojureScript, Amber or Objective-J. Or any number of compile-X-to-js projects.

Re: CoffeeScript 1.7.0

#84
post #63
post #53

Let's all take a moment to reflect on the elegance of the grammar.coffee file [0]. Notice how the function named 'o' provides simplicity as it plays well paren-less function calls. [0] - https://github.com/jashkenas/coffee-script/blob/master/src/g...

Here is the annotated link for that same file: http://coffeescript.org/documentation/docs/grammar.html

Impressive!

Re: CoffeeScript 1.7.0

#85
post #68

Earlier quoted context omitted.

I don't know if it's "hip," but I think it has a well-established place in the web development ecosystem, especially since using it is one of the defaults in Rails. Personally, I enjoy it and have been using it to build a fairly large Angular application (Java backend, oddly enough.) I've found that Coffee and Angular complement each other nicely.

Im curious, which library do you use to load the JS libraries? Do you use requireJS?

As of right now, they're just concatenated and minified into one file. This made more sense earlier in the project, and now I'm looking into other options, including Require.

Re: CoffeeScript 1.7.0

#86

What does %% do? The documentation says: a %% b is the same as (a % b + b) % b, but what is the difference between "true mathematical modulo" and the standard modulo?

The "standard modulo" is actually a remainder operator, and is a js-specific thing. Most languages implement the "true mathematical modulo", aka modulo.

One reason this is useful is if you want an array to wrap around. With modulo, you just index on `index % length` and all is well. But with remainder, this will only do what you want for `index >= 0`, because it can give negative outputs, given negative inputs.

Re: CoffeeScript 1.7.0

#87
post #72
post #7

Earlier quoted context omitted.

CoffeeScript was designed for non-JS coders to feel a lot more comfortable writing JS. I'm not so sure about that. I use it as an experienced JS developer because it makes a lot of needlessly complex JS operations simpler. Most of those are features in ES6, so it may well go out of vogue then - I've played around a little and may well end up returning to JavaScript at that point.

The thing about CoffeeScript is that it makes it a ton easier to reason about doing operations like default arguments, pattern matching or expressive for loops. When you don't see the messy code generated from its syntactic sugar, you don't think its a problem. But when it comes to best practices, long term decisions and performance , CoffeeScript will stab you in the back. The original reason for hatred towards CS i…

Much ado about nothing. CoffeeScript performance in general is a lot better due to non emulated foreach constructs which plague javascript today. Like noted there are ways of teasing the compiler in generating very friendly looking js code, but honestly if you are tripped up by a simple for loop in coffeescript maybe looking at code isn't your cup of tea.

Re: CoffeeScript 1.7.0

#88

Earlier quoted context omitted.

I do a fair amount of coffeescript work and every time I see the compiled source I'm so glad that I'm writing in coffeescript. It's not just that it makes certain JS gotchas almost non-issues (almost! there are still several things that can trip you up), it's that it makes clean, concise and correct programming so much easier. There are a lot of things, like curried functions (`f = (a) -> (b) -> result`) or testing f…

If I weren't coding ClojureScript now I would at least be in CS. CS is nice, but Clojure is just too strong a language.

I still need to try out ClojureScript. I've heard great things. I prefer the coffeescript syntax, though...

Re: CoffeeScript 1.7.0

#89
post #72
post #7

Earlier quoted context omitted.

CoffeeScript was designed for non-JS coders to feel a lot more comfortable writing JS. I'm not so sure about that. I use it as an experienced JS developer because it makes a lot of needlessly complex JS operations simpler. Most of those are features in ES6, so it may well go out of vogue then - I've played around a little and may well end up returning to JavaScript at that point.

The thing about CoffeeScript is that it makes it a ton easier to reason about doing operations like default arguments, pattern matching or expressive for loops. When you don't see the messy code generated from its syntactic sugar, you don't think its a problem. But when it comes to best practices, long term decisions and performance , CoffeeScript will stab you in the back. The original reason for hatred towards CS i…

Pretty big rush to judgement. Slice off a copy of the arguments if you need them, but

  pall = -> console.log line for line in arguments; return
would have done just fine there.

One can be annoyed by `return` in tail position, or delighted by invocations-as-expressions. But not both. It's ok to choose the latter. :-)

Also, `console.log` is not a fit for map, forEach, et al. Check the parameters.

Re: CoffeeScript 1.7.0

#90
post #73

Earlier quoted context omitted.

I'm also not so sure about the "non-JS coders" part. As a proficient Javascript programmer, I absolutely love CoffeeScript. I even recommand it to learn the good parts of JS when you are completely unfamiliar with it. I think there is a lot more than synctactic sugar to Coffeescript. It makes obscur or verbose JS patterns really easy to use. My code generally compiles down to up to twice as much JS code. Yes the comp…

What speed and ease to you gain with it? CoffeeScript won't get you any performance; if any, less. Making obscure or verbose patterns easier to use is syntactic sugar. Part of the thing about CoffeeScript, is that there are more bad parts that it introduces than prevents. Cleaning up the class model is generally not a good thing, since JavaScript isn't designed to have true OOP principles. Things like it's expressive…

> What speed and ease to you gain with it?

Speed and ease of development! Yes it is mostly syntactic sugar, where I wanted to make a point is that this "sugar" adds more to the language than sweetness for the sake of it. It exposes beautiful pattern that are cluttered in day to day javascript syntax. My final compiled javascript code is not the same I would have produced would I have coded directly in Javascript. Coffeescript also gives me a different approach to think about a problem.

> Things like it's expressive for loops and default arguments generate really ugly code, and shun people from using ES5 array methods like .forEach, .map, and .filter, which are a lot cleaner and more optimizable by the engine.

I use underscore which will delegate to .forEach et all it they exist... I really rarely use loop comprehension, though they can be very expressive if used correctly..

> CoffeeScript will completely obscure the way JavaScript works to newcomers

I disagree. I've installed the proper plugin (I'm on emacs, same is true for vim, sublime or lightTable), I am therefore two stroke away from the compiled javascript. Furthermore, I spent a decent amount of time a week in the debugger where the code is in JS. If I could have disliked this in the beginning, having two different languages whether you code or debug can seem unfamiliar, I actually love it. It keeps my Javascript sharpen and it gives a thorough understanding of exactly what's happening in my Coffeescript code. And that's exactly where I found a niche for Coffeescript. In my opinion, it is definitely not a replacement for Javascript, it is a cleaner, more expressive and easier way to write it, without any real overhead. Honestly, it took me minutes to understand and less than a day to feel comfortable and be efficient in Coffeescript. What I recommend to newcomers is to use coffeescript's syntax to to learn Javascript, by continually compiling down to JS and understanding what's happening. The JS output by CS isn't ugly at all, and that is a strong point. It is really possible to learn some great javascript idoms just by applying built-in coffeescript construct and understanding their value and working in JS

> JavaScript isn't designed to have true OOP principles

... Hmm right... ?

Post reply on HN