Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

I don't subscribe to the notion that you can write code faster with less keystrokes (vi/emacs, anyone?). I do however, understand that a cleaner syntax would lend some readability and simplicity to your code once you learn said syntax. Ultimately, I find that the problems that CoffeeScript solves, and solves quite well, are not really that big of a deal for me given that I've been working with Javascript enough to get used to the quirks. I'm not sure if I'll ever use it myself, but I can't blame anyone who would; this article does a good job explaining some of the benefits.


"Ultimately, I find that the problems that CoffeeScript solves, and solves quite well, are not really that big of a deal for me given that I've been working with Javascript enough to get used to the quirks."

I wouldn't expect you to believe me until you've used CoffeeScript for a little while, but I think you're definitely wrong about this. CoffeeScript simply has better syntax than plain js in every way, and any js developer will be more productive using it. The only drawbacks are dealing with file conversions and debugging, but these are something like a 10% penalty at worst on top of a 100%+ productivity boost. It's not just an aesthetic preference thing. CoffeeScript is a much better language and is pretty much guaranteed to save you time and mental effort.


> CoffeeScript simply has better syntax than plain js in every way, and any js developer will be more productive using it.

That's a pretty bold claim. Have any examples to back it up? Most of what I've seen of coffescript (note: I haven't looked hard) seems to be relatively similar syntax with fewer characters or fixing JS gotchas that many developers are familiar with.

Both of these are useful things, but they don't make a 100%+ productivity boost in my mind.


List comprehensions. Distinct 'of' (property) and 'in' (value) operators. Bind a function to current 'this' with =>. Nothing winds up in global scope unless you mean it. Use reserved words as property names. Existential operator and assignment. Always use '==='. Everything is an expression:

    value = switch value
        when 1 then one
        else whatever
Closures.

  do (value) ->
     #value is wrapped in a closure
The 'class' macro.

And that's just off the top of my head. Yes, it compiles to JavaScript. You could write all this by hand. It would be a waste of your time-- CS writes safe, efficient, readable code faster and better than you do, every time.

Look harder.


Peoples' obsession with CS having the class macro is weird to me. Seems like laziness more than anything - once I grokked JS's protoype object model I've found it to be ridiculously powerful AND I got to learn a cool new programming abstraction at the same time. All the rails guys I know are going gaga over CS but I just don't see the point as I like and can be efficient in JS.


I can't speak for anyone else, but I treat the class macro as pure shorthand. I understand implicitly that "properties" in a "class" are being assigned one at a time on the constrictor's prototype, and frequently use that knowledge for metaprogramming. You call it laziness; I call it nicer syntax.

I understand that puts me in a small boat. In my opinion, people shouldn't use the class macro without knowing what it really does. Actually I'd extend that to say people shouldn't use CoffeeScript at all without an understanding of the JavaScript it compiles to, just as you shouldn't use C without an understanding of the assembly it compiles to... But that's probably wishful thinking. It wouldn't be an improvement for those people to write assembly (or raw JS) instead.


I don't particularly like all of the syntax choices in CoffeeScript, and I absolutely don't subscribe to the theory that fewer keystrokes means cleaner code, but on anything complex I think CoffeeScript is a better choice than vanilla JavaScript.

It really is true that having a compiler make it impossible to screw up your scope saves you from a lot of mistakes. This feature is probably the thing I wish we had put in Objective-J most. It's also really nice to have a syntax for classes.


Sounds like a bit of a straw man to me. It'd depend on just how big the difference in the number of keystrokes there are, would it not?

Do you not agree that writing 100 lines of code instead of 1000 lines saves time, when writing it but perhaps most importantly when reading it and developing it further?

I'm not saying CoffeeScript cuts down the number of lines of code by a factor of ten, but, depending on what you do with it, often by 50% or more.

Making it about "keystrokes" is a bit disingenuous, it's about cruft (aka "keystrokes") but it's also about lines of code, imho.


I'm less concerned about raw keystrokes than I am about repetitive things that I have to keep in my head at all times.

Simple iteration over the key/value pairs of a javascript object requires that I remember to check hasOwnProperty at the right times. Soaking up nulls is a pain. Dealing with args kind of sucks. There's quite a bit more.

It's less valuable that these things can be done with shorter character sequences, and more valuable that I don't have to think about them nearly as much.


The problem with Javascript is that because of political reasons it has only evolved slightly in the last 12 years, so it takes a lot of effort to avoid the bad parts.

I about CoffeeScript as JSLint + Syntactic Sugar. Both of which mean you need less heroics to get Javascript right.


I agree with this. As a counter example I can completely understand why some people use GWT because it provides a development infrastructure and code enforcement that you just can't get from normal javascript coding. I can't say that CoffeeScript provides enough of a change in discipline over normal javascript coding.




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

Search: