Hacker News new | past | comments | ask | show | jobs | submit login

It is not quite as big as CSS->Sass — that takes CSS from a dumb configuration language to a grown-up programming language with functions and variables. But it is a big difference, and it's not just syntactic.

First of all, I'd like to point out that syntax is not entirely irrelevant, at least not in the sense that CoffeeScript is "just a weird syntax" for JavaScript. Python decorators and list comprehensions are generally thought of as very nice features of the language, but they're really just a nice syntax for higher-order functions and iteration. That syntax makes a big difference. Just adding CoffeeScript's syntax for functions (including the do-operator) and the existential operator would noticeably reduce the size of most JavaScript code, without anything else.

But the difference isn't just syntactic. Here are a few semantic changes in CoffeeScript:

• Everything is an expression (a la Ruby)

• Equality is always strict

• A simplified class-based inheritance model on top of JavaScript's prototypal inheritance

• Switch is almost identical to Ruby's case expression rather than C's switch statement (i.e. clauses don't fall through and it's an expression rather than a statement), which makes it much more useful

I'll put it this way: I've been making websites since 1995 and am fairly proficient in JavaScript, but I have never really liked the language all that much. But CoffeeScript is a joy to use. I actually enjoy programming it, and it's just amazingly readable (both from the nicer syntax and the fact that CoffeeScript's sugar means you don't have to write as much code, and it's easier to understand five lines than 20, even if 15 of the 20 are boilerplate).




For someone who has little or no experience in JS and CS, how realistic is it to get away without learning JS and skip directly to CS ?


Not very realistic. CoffeeScript semantics are nearly identical to JavaScript semantics -- you'll have to understand them.


Hate to disagree with such a distinguished source, but having done it:

Very realistic. Looking at the compiled CoffeeScript taught me more Javascript than all of the tutorials put together, and CoffeeScript itself was a joy to learn. I think you're under estimating your own baby here, jashkenas.

I would point out that you're not so much 'skipping' learning JS, as that learning CS is the quickest way I've found so far to learn JS.


Hey, that's wonderful.

I'm just saying that you're not in any way going to avoid learning JS by starting with Coffee -- you still need to know:

  * How JS numbers work.

  * All about "this" (dynamic scope).

  * Function vs. block-level scope.

  * How the prototype chain is structured.
... and all those other un-obvious things about JavaScript.


True, but I would need to learn these regardless of which syntax I use to write my JavaScript. And coffee actually helped me to become aware of/understand some of these issues: -> vs. =>, for example, or the prototype code produced by your 'class' syntax.


Spend a couple hours reading "Javascript: The Good Parts" by Douglas Crockford. Read it twice, cover to cover.

The other option is to skip learning javascript properly, which I tried... and it came back hard at me when I tried going beyond enhancing my pages with jquery.


I'd say it is realistic for what you're probably trying to do off the bat with Javascript.

It's what I did. Since I'm already comfortably with Ruby and CoffeeScript's simple syntax, I used CoffeeScript's "Try CoffeeScript" console to insert Ruby-like code and get the Javascript equivalent. Helped me rapidly map Ruby-Javascript equivalences in my head.

Now that I'm quickly comfortable with Javscript's surface and my foot's in the door, diving deeper into the language isn't the obstacle I used to consider it as.


Very realistic until you need to debug your code. Debugging's JS-only, as far as I know, so you're picking through the compiled CS looking for errors.

edit: Well listen to the man himself, but I learned tons about JS's semantics by picking up (and picking apart) CS.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: