r/javascript • • Nov 16 '12

A Case for Coffeescript

http://blog.gaslight.co/post/35845656900/a-case-for-coffeescript
1 Upvotes

24 comments sorted by

View all comments

22

u/rhysbrettbowen Nov 16 '12

A couple of things, when would you ever write:

function({}) ? - I'm guessing you mean function() {}.

and why write:

var that = this

when you can bind a function?

I actually think javascript is a beautiful language and coffeescript is uglier. Javascript has less symbols to learn (no @ for this and no -> or =>). Also you know that parenthesis and semi colons are required (or at least you have it in a style guide that they are). In coffeescript people can just drop parenthesis which makes things harder to read. I like having a parenthesis rather than whitepaces as I can scane for them to know a function is starting. That's what I call beautiful, the ability to know you're looking for one thing, not one of several.

I don't think beauty or readability is a case for coffeescript, if you're making a case then talk about the good things it does bring (you mentioned not putting in var which I like) but also comprehensions, splats , the existential operator and string interpolation.

3

u/Neurotrace Nov 16 '12

This. I've earnestly been trying to find someone who could finally sway me to the side of CoffeeScript because with all the rabble, it feels like I must be missing out on something. But everyone always talks about the "beauty" of it but I, like yourself, find JS syntax to be much nicer and more readable.

Sure, JS is more verbose and the little gotcha's can be a pain in the ass but when you're reading JavaScript you know you're reading JavaScript. Provided the person who was writing it kept their code formatted well, you can just scan through the code and see where variables are set, functions are defined, and all that other jazz. And while the gotcha's can be a pain, I think they add a little bit of character ;)

2

u/runvnc Nov 17 '12

How much coffeescript have you actually written? I had a similar perspective until i tried it out for a week or so.

2

u/Neurotrace Nov 17 '12

To be fair, I've only written maybe a total of 200 lines in it but it felt weird the whole time I was working with it. I'm no stranger to picking up new languages so it wasn't that, I just didn't like the style of it all.

1

u/hajamieli Nov 17 '12

I've written tens of thousands of lines of CoffeeScript already. Definitely an improvement over writing the same functionality in hundreds of thousands of lines of js. I've found myself porting old js code to CoffeeScript every time it needs a more major cleanup, and it's still faster than cleaning up, refactoring and finding the bug where you forgot a delimiter and jslint doesn't find it.

Anyhow, you'll need some well-integrated development tools with it, whereas with plain js, all you need is a text editor. However, my server is my dev-tool, and it does other nice things in addition to CoffeeScript compilation; it combines various source files and their associated assets into packages, minimizes them, shortens "private" references, gzips the response data, sets optimal caching headers, and reloads the clients after completing the build. Takes a few tens to hundreds of ms to complete a build after saving a file. A second later, my test browsers have reloaded the code without me interacting, and run the gui/unit tests, if set to do so.

In effect, this has boosted my productivity to entirely new levels and allows me to catch bugs early, before they escalate and become time-consuming to find. My text editor itself has built in, real time js as well as CoffeeScript linting/syntax validation, so issues like that are caught even before saving.

2

u/Neurotrace Nov 17 '12

I guess I'll just have to get down and dirty and write something non-trivial in it. I've already got a sweet set of server-side dev tools for building my projects so I suppose adding in the compilation step for CoffeeScript won't be too much of a hassle.

On a semi-related note, if you haven't started using Node.JS as part of your build process, I would highly suggest it. I got in to Node about two weeks ago and it's made everything so much nicer.

1

u/hajamieli Nov 17 '12

I'm kinda using it embedded in ruby. The performance bottleneck parts of the process are in C, which is much easier to do by extending ruby than js. CoffeeScript compilation (as it's in the embedded V8) is the slowest part of the build process by an order or two of a magnitude. However, thanks to that I was motivated to do smarter build-caching, whereas the brute-force speed of handling from the point of js and on was more than fast enough as is. However, before implementing the bottlenecks in C, it would take seconds, not milliseconds to build everything.