Live data from Hacker News

Poll: Have you moved from JavaScript to CoffeeScript?

news.ycombinator.com

161–170 of 178 posts

Re: Poll: Have you moved from JavaScript to CoffeeScript?

#161
post #74

Earlier quoted context omitted.

Alright, I buy your argument. Now go and do everything in assembler, right now. Deadline is yesterday. What are you looking at?? Go!!!

You are exaggerating. Is it only me who likes JS better than CS? :( It's stylish.

Now seriously, it's not just the way it looks. If you never spent at least half an hour playing with a language such as python or ruby, you will probably never know what is it that makes programmers all warm and fussy about their languages. Just take a look at array comprehensions (or list comprehensions in python) to know how succint and powerful they are, and how much clear the code looks. It's about replacing four or more lines of js with just one, readable line of coffeescript (or python).

It's all about power, flexibility, succintness and readability, all things that make programming more enjoyable and fun.

Re: Poll: Have you moved from JavaScript to CoffeeScript?

#162
Like many, I read about the cool kids using CoffeeScript for months before I finally tried it.

(I mostly work with Objective-C native apps and Ruby backends, so I'm not a JavaScript programmer--more like a user. A web view needs to frob the DOM or do some AJAX or something.)

A project came up where I needed to write the skeleton for a simple single-page web app component of a larger system. The window has a few panes which need to do AJAX, swap subviews in and out, and react to various inputs. Simple, but it has a few different view controllers and different kinds of data objects, so I decided to use this project to try CoffeeScript.

Comapared with JS, CS is much more concise and instantly readable. I think basically everybody agrees about that. It makes even Ruby feel a bit clunky with all the extra typing. ;-)

But surprisingly, there are no significant drawbacks. Debugging, the issue I had been wondering about, turned out to not actually be a problem at all. Two lines of CS code might be compiled to a sixteen lines of JS, but it's obvious what is going on, and debugging is effectively just as easy as ever.

So, two weeks in, I am reasonably sure that I will never write in raw JavaScript again. I just can't imagine why I would ever again type "function() {" three times to write one spec, or write my own for loop just to iterate a collection, or spend my time mentally filtering out all those braces and semicolons.

Granted, I am not mainly a JS coder, so my perspective is not the same as, say, a frontend dev to whom JS is second nature and 'the good parts' are deeply ingrained. My hunch is, though, that even if I was I would still switch.

The end result is the same, but the process of reading (and writing) the code is much nicer.

Re: Poll: Have you moved from JavaScript to CoffeeScript?

#163
post #38

One of the interesting things on doing some analytics on our customer base was seeing just how wide the gap is between the usual HN fare and reality: http://blog.directededge.com/2010/05/30/what-programming-lan... The core message being: things like Scala, Erlang, et al still represent a tiny portion of the actual tech world. (And our customers tend to be biased towards being techy anyway.) Just because CoffeeScript…

This is one of the reasons I've transferred most of my enthusiasm for new languages into new problem domains. I've been studying machine learning and DSP for most of the last year and it's done a lot more to revive my passion for programming than learning another new language could have.

Wish I could upvote you more than once. I find the language fetishism - especially for new/"hip"/esoteric languages - in HN and other geek echo chambers kinda annoying and, frankly, silly. There's only so many times one can express the same algorithm using basically different symbols until it gets old. Mastering new problem domains is a better time investment and more satisfactory than learning yet another way to write the Fibonacci function or a String class.

Re: Poll: Have you moved from JavaScript to CoffeeScript?

#164
post #60

Earlier quoted context omitted.

you can try js2coffee which will convert all existing js file to coffee-script.

I see no need to convert my js to coffee just so I can compile it back to js.

FWIW, I used js2coffee on a 400-line JS file powering an app today and the compiled version of the code (js->coffee->js) was noticeably faster than the straight JS version. The for-in efficiency is probably part of that.

A quick way to port once: http://ricostacruz.com/js2coffee/

Re: Poll: Have you moved from JavaScript to CoffeeScript?

#165
post #65

Earlier quoted context omitted.

@jashkensas what you want though would break the way closures are handled in javascript. What you should do if you still want access to Accountview is to trap a variable with a reference to it in the closure. Using your jquery example: AccountView.prototype.render = function() { $(".account").click( { that: this }, function(e) { // 'that' now holds a reference to AccountView }); }; If you don't want to use (or you ar…

No, it's a jQueryism. How would it break the way closures are handled in JavaScript? You realize you're replying to the author of CoffeeScript?

LoL I did not realize that. To me, I think I've just made my peace with the way it is. I don't think that jQuery needs to be changed in the way mentioned though - to me, 'this' is context sensitive and in this case, it would refer to the current object and not the container

Re: Poll: Have you moved from JavaScript to CoffeeScript?

#167

Earlier quoted context omitted.

There are a total of 9 references to the `_vars`. I think line noise in the compiled javascript is a legitimate counter argument to the claim that its strait forward and readable.

The reason why all declarations happen at the top of the current function body, instead of inline with the first assignment is because in JavaScript assignment is a statement, not an expression. You can't do this: alert(var one = 2); In CoffeeScript, (nearly) everything is an expression. So you need to be able to do this: alert one = 2 By pushing up all the var declarations, all assignments can be themselves assigned…

Aren't local variables scoped to be visible within the entire JavaScript function? I thought the recommendation to declare local variables at the top the function was a reminder (or to avoid accidental importing of global variables of the same name)?

Re: Poll: Have you moved from JavaScript to CoffeeScript?

#168

Earlier quoted context omitted.

This is one of the reasons I've transferred most of my enthusiasm for new languages into new problem domains. I've been studying machine learning and DSP for most of the last year and it's done a lot more to revive my passion for programming than learning another new language could have.

Wish I could upvote you more than once. I find the language fetishism - especially for new/"hip"/esoteric languages - in HN and other geek echo chambers kinda annoying and, frankly, silly. There's only so many times one can express the same algorithm using basically different symbols until it gets old. Mastering new problem domains is a better time investment and more satisfactory than learning yet another way to wri…

Same here, language fetishim gets old really fast. I think it comes mainly from the new generation of programmers who have not been programming for that long or have not worked on hard enough problems were the language makes very little difference. After having to work on a really hard problem it should hopefully become apparent that what really matters is the algorithm, not the language it is written on. Being obsessed with a language because it saves you a couple of seconds with its unique syntax is frankly quite silly. What takes most of the time is the actual design and figuring out of the algorithms involved. Also debugging takes quite some time. The actual programming shouldn't take that long. A couple of seconds saved because of some syntax will not make an iota of a difference.

Re: Poll: Have you moved from JavaScript to CoffeeScript?

#169
post #55

I have used Javascript exclusively on client and server since late 2008. First Rhino and then Node. Before that I used Rails. I can understand the syntax gripes that some people have towards Javascript but I think this has more to do with a Ruby notion of "elegance" coupled with a lack of familiarity with Javascript then it does with actual issues with Javascript. In fact, I prefer Javascript to Ruby. I have gone the…

You may have been misinformed -- the values of direct, raw, fast code are a big part of the reason why CoffeeScript works the way it does, and why many scripts can end up running faster after getting ported to CoffeeScript. The golden rule of CoffeeScript is to avoid adding any library code to the runtime, and to avoid introducing any special calls, to the greatest extent possible. Many folks rely on a "forEach" (or…

if order does not matter:

var sum=0,i=list.length; while(i--) sum += list[i].amount;

if it does: var sum=0,i=0,ln=list.length; while (ln-- && (sum += list[i++].amount));

but the for in syntax is nicer indeed.

Re: Poll: Have you moved from JavaScript to CoffeeScript?

#170

Earlier quoted context omitted.

12 if you count the declaration. You'd have exactly the same doing it yourself, you can at most reduce it to 10 by declaring i and ln inside for(). You're also overlooking the fact that this can be considered an advantage: variable naming for these transient uses is very consistent. When writing JS you could have names all over, even a different one for every loop.

I've maintained the hoisted index variable and cached the length: var i, foods = ['toast', 'cheese', 'wine'], foods_length = foods.length; for (i = 0; i Prefixing variables with an underscore is not an advantage in readability because it lends nothing to the description of what the variable represents. Its another glyph that you have to visually parse before reaching possible meaning.

I didn't say the underscore is good - it's a necessary evil.

I said consistency is good. And you just proved my point.

Post reply on HN