Live data from Hacker News

Writing Eloquent JavaScript Without CoffeeScript

oscargodson.com

51–55 of 55 posts

Re: Writing Eloquent JavaScript Without CoffeeScript

#51
post #31

Earlier quoted context omitted.

This kind of clarification is exactly why I posted this link. It's great to clear the air in one respect and at the same time ask the question, "is there something on the CS site needing change to avoid this confusion?"

My problem is that I want a comparison of syntax so I can see exactly how Coffeescript is an improvement over the equivalent Javascript. When I visit the site and I see a table with CoffeeScript on one side and Javascript on the other, my brain sees just enough to verify that the expected elements are all there before it says, "Yep - there is the comparison you wanted". So while it does clearly state that the JavaScr…

My problem is that I don't find the javascript on the main comparison page to be all that bad.

It doesn't do enough to warrant learning the abstraction syntax.

Re: Writing Eloquent JavaScript Without CoffeeScript

#52
post #38
post #31

Earlier quoted context omitted.

This kind of clarification is exactly why I posted this link. It's great to clear the air in one respect and at the same time ask the question, "is there something on the CS site needing change to avoid this confusion?"

I don't know how Jeremy could make it any clearer. It says: CoffeeScript on the left, compiled JavaScript output on the right. Maybe the two halves should have the headers directly aligned above them: > CoffeeScript > The JavaScript that it compiles to. Other than that, it's hard to make it any clearer for its intended audience (people who know JS and know what the words "compiled" and "output" mean). Still, I'm temp…

Well, it's written in small italic gray at the top of the page. To make it clearer, it could be written "Compiled javascript" on the top right of each compiled javascript code. Or, maybe instead of a left and right rectangle, there could be a kind of arrow to inform that the left side gets automatically changed into the right side instead of showing an equivalence between the two.

Re: Writing Eloquent JavaScript Without CoffeeScript

#53

Earlier quoted context omitted.

Not really. It's not usually mentioned but CoffeeScript loses a lot of its supposed elegance when you try to do things like chaining. Especially chaining a function that takes a function as an argument. To achieve better looking chaining you'll talk yourself into not using anonymous functions. tldr: whitespace significant languages do not do chaining very elegantly. Other than that CoffeeScript is pretty cool.

... not so much. A big part of the point of having a minimal function literal, `->` instead of `function(){}`, is that using anonymous functions is a bit more pleasant in any context -- including chaining. list.map((num) -> num * 2 ).map((doubled) -> doubled + 5 ) ... instead of: list.map(function(num) { return num * 2; }).map(function(doubled) { return doubled + 5; }); It's not a huge difference. But, by the same to…

CoffeeScript is always going to be less verbose than JavaScript, but in the context of a full code file having some functions with parentheses and some without isn't a pleasant consistent experience in my book.

Another thing CoffeeScript handles unelegantly is two anonymous functions (very common when a function needs an onsuccess and an onerror):

  api.get(
    ->
      # Success here.
    ->
      # Failure here.
  )
The benefit of curlies is you get a consistent experience and don't have to go to Stackoverflow to find out when you need commas or parentheses and when you don't.

Re: Writing Eloquent JavaScript Without CoffeeScript

#55

As someone who writes JS every day, ignoring the fact that I think most of these paradigms are terribly ugly (though the comma placement is acceptable for cleaner diffs), I expected this post to be about actually getting things done eloquently without CoffeeScript. What I got was a blog post about how ternary operators can be written on multiple lines.

My thoughts exactly
Post reply on HN