Live data from Hacker News

Why CoffeeScript Isn't the Answer

walkercoderanger.com

121–130 of 148 posts

Re: Why CoffeeScript Isn't the Answer

#121

Disclosure: I have never used CoffeeScript. However, based on the article, the death-knell against CoffeeScript for me was the variable scoping rules. With no variable declaration keyword (a la var, my, local, private), adding a variable assignment anywhere could radically change the variable scoping. I'm done, this isn't suitable for prime-time, time to go somewhere else. I spent too many years in the 80s working wi…

I've used coffeescript extensively for years, and I have never had that be an issue. Not sure if it's because I rarely write a file longer than ~200 lines, or I'm careful about variable names and global scope. More generally I've found that coffeescript mixes much better with a functional style than with an imperitive one.

These sort of problems crop up a lot more the larger a codebase gets and the more people working on it. Being careful with your variable naming and global scope are necessary to working well with CS.

Re: Why CoffeeScript Isn't the Answer

#122

Earlier quoted context omitted.

I've used coffeescript extensively for years, and I have never had that be an issue. Not sure if it's because I rarely write a file longer than ~200 lines, or I'm careful about variable names and global scope. More generally I've found that coffeescript mixes much better with a functional style than with an imperitive one.

These sort of problems crop up a lot more the larger a codebase gets and the more people working on it. Being careful with your variable naming and global scope are necessary to working well with CS.

The biggest problems I find with bad coffeescript that I don't generally find in bad javascript are extensive inheritance hierarchies, overbroad class design, and explicit dependencies.

Generally the same kinds of problems I find with bad ruby/java.

Re: Why CoffeeScript Isn't the Answer

#123
post #116

Earlier quoted context omitted.

I guess I just don't think it's a serious issue. I've found that often when I have an "issue" it's more so my design lacking not the tool (javascript) itself.

What would the code look like for my example using futures in JavaScript?

    fs.readFile("person.json")
    .then(function(e, personJson) {
        var person = JSON.parse(personJson);
        return myDB.query("lastname", person.name);
    })
    .then(function(matched) {
        return msgQueue.push(JSON.stringify(matchesLastname));
    })
    .then(function(id) {
        log.info("Message sent to queue: " + id);
    });

Re: Why CoffeeScript Isn't the Answer

#124

It's a tool, that is all. Ambiguous code is a poorly thought out contrived example with a simple solution. To me, this: eat food for food in foods when food isnt 'chocolate' Is kind of beautiful and much more readable than: for (var i = 0, var len = foods.length; i How is this even an argument?: "One wouldn’t realize it was conditional until reading the end." How do you expect to understand any code without reading i…

While on the one hand I agree with your overarching point, I actually find the second set of code tells me much more about what is going on.

That might be because I have been doing curly brace languages for a decade but tells me more, Foods is an array, not an object.

The word isnt as a keyword also makes me want to scream inside a little every time I see it:)

That said you are totally right, It's a tool in a category of tools I never really got into.

Re: Why CoffeeScript Isn't the Answer

#125

It's a tool, that is all. Ambiguous code is a poorly thought out contrived example with a simple solution. To me, this: eat food for food in foods when food isnt 'chocolate' Is kind of beautiful and much more readable than: for (var i = 0, var len = foods.length; i How is this even an argument?: "One wouldn’t realize it was conditional until reading the end." How do you expect to understand any code without reading i…

Your Javascript example is a bit contrived too. How about:

  foods.filter(function (e) { return e !== 'chocolate'; }).forEach(eat);
Regardless, I disagree that the Coffeescript example is more readable. My brain is much faster at parsing symbols (`(`, `{`, etc.) than english words.

With your JS example, without having to read the words, I know there's a loop, a conditional and a function invocation. I also know that I can safely add statements after this piece of code without worrying it might break some other function (in Coffeescript, I'd have no way to tell if the implied return really mattered or not assuming it was the last line of a function).

With your CS example, I have no way to tell what's going on until I've read the full sentence. I have to read every word and see if it matches one of the many reserved keywords in order to determine if it has a special meaning or if it's just a regular variable.

In Javascript, you have a few reserved words but the list is relatively short and those words are almost always preceded by a line break or a symbol.

Maybe our brains work differently...

Re: Why CoffeeScript Isn't the Answer

#127

It's a tool, that is all. Ambiguous code is a poorly thought out contrived example with a simple solution. To me, this: eat food for food in foods when food isnt 'chocolate' Is kind of beautiful and much more readable than: for (var i = 0, var len = foods.length; i How is this even an argument?: "One wouldn’t realize it was conditional until reading the end." How do you expect to understand any code without reading i…

Your Javascript example is a bit contrived too. How about: foods.filter(function (e) { return e !== 'chocolate'; }).forEach(eat); Regardless, I disagree that the Coffeescript example is more readable. My brain is much faster at parsing symbols (`(`, `{`, etc.) than english words. With your JS example, without having to read the words, I know there's a loop, a conditional and a function invocation. I also know that I…

I'm obliged to agree. Even the "contrived" example is easier for me to parse given that I have years of seeing "{}[]()" as delimiters.

Not to mention that filter/each functions will get even easier to parse once es6 standards reach the browser (stabby procs, woo).

Re: Why CoffeeScript Isn't the Answer

#128

It's a tool, that is all. Ambiguous code is a poorly thought out contrived example with a simple solution. To me, this: eat food for food in foods when food isnt 'chocolate' Is kind of beautiful and much more readable than: for (var i = 0, var len = foods.length; i How is this even an argument?: "One wouldn’t realize it was conditional until reading the end." How do you expect to understand any code without reading i…

Your Javascript example is a bit contrived too. How about: foods.filter(function (e) { return e !== 'chocolate'; }).forEach(eat); Regardless, I disagree that the Coffeescript example is more readable. My brain is much faster at parsing symbols (`(`, `{`, etc.) than english words. With your JS example, without having to read the words, I know there's a loop, a conditional and a function invocation. I also know that I…

Agreed, I dig the functional example you posted. Completely personally I think the CS example I posted fits my style more and is a bit terser.

Also the CS reserved word problem you speak of surely isn't harder than learning to program in the functional style. I mean come on. ;)

Re: Why CoffeeScript Isn't the Answer

#129
post #127

Earlier quoted context omitted.

Your Javascript example is a bit contrived too. How about: foods.filter(function (e) { return e !== 'chocolate'; }).forEach(eat); Regardless, I disagree that the Coffeescript example is more readable. My brain is much faster at parsing symbols (`(`, `{`, etc.) than english words. With your JS example, without having to read the words, I know there's a loop, a conditional and a function invocation. I also know that I…

I'm obliged to agree. Even the "contrived" example is easier for me to parse given that I have years of seeing "{}[]()" as delimiters. Not to mention that filter/each functions will get even easier to parse once es6 standards reach the browser (stabby procs, woo).

I don't understand. Because you have been doing something one way for years, a different way is harder and thus worse?

I'm not trying to be inflammatory at all just wondering as this is a reply to my comment.

Re: Why CoffeeScript Isn't the Answer

#130

Earlier quoted context omitted.

Your Javascript example is a bit contrived too. How about: foods.filter(function (e) { return e !== 'chocolate'; }).forEach(eat); Regardless, I disagree that the Coffeescript example is more readable. My brain is much faster at parsing symbols (`(`, `{`, etc.) than english words. With your JS example, without having to read the words, I know there's a loop, a conditional and a function invocation. I also know that I…

Agreed, I dig the functional example you posted. Completely personally I think the CS example I posted fits my style more and is a bit terser. Also the CS reserved word problem you speak of surely isn't harder than learning to program in the functional style. I mean come on. ;)

I agree that using functional style was not fair (comment edited :)). By the way, here's a non contrived CS example directly from CS's source which I find really hard to understand: https://github.com/jashkenas/coffee-script/blob/master/src/g...

  tokens = []
  for name, alternatives of grammar
    grammar[name] = for alt in alternatives
      for token in alt[0].split ' '
        tokens.push token unless grammar[token]
      alt[1] = "return #{alt[1]}" if name is 'Root'
      alt
Why is a loop assigned to a variable? I understand that loops are expressions but the intent here is not immediately clear and definitely requires some thinking. That's what I mean by readability (terseness is another thing).
Post reply on HN