4 ms·
>> Why CoffeeScript Isn't the Answer What is the question for which CoffeeScript is a compelling answer? "I needed to speak to Germans, so I learned French an
by freyr 13y ago
>> Why CoffeeScript Isn't the Answer
What is the question for which CoffeeScript is a compelling answer?
"I needed to speak to Germans, so I learned French and spoke through a French-German interpreter. Things were occasionally lost in translation and somteimes I couldn't get my point across, but French is prettier. Can I recreate this experience in code?"
"My team can't learn to write `var` or `===`. Can we just learn a new language instead?"
"Indentation speaks to my aesthetic sensibilities, but braces do NOT! What fits my needs?"
"I don't want to use JavaScript. Fortunately, since I never make coding errors, I'll never need to debug transpiled JavaScript. What's the right language for me?"
Seriously, though, what is the problem that CoffeeScript solves?
- ilaksh 13y agohttp://en.wikipedia.org/wiki/Status_quo_bias http://en.wikipedia.org/wiki/Status_quo_bias CoffeeScript obviously solves problems. Its not compelling to you because of status quo bias, and because you don't want to invest the effort to learn it. The issue with equality is a real issue. CoffeeScript solves that issue. Braces and parenthesis _do_ become awkward in JavaScript with callbacks. CoffeeScript solves that problem. You have been able to debug CoffeeScript as CoffeeScript for some time now with source maps. However, debugging the generated JavaScript is not hard for someone who knows JavaScript.
- rubyn00bie 13y agoIts cute you link to status quo bias, then immediately state, like a fact from god that "braces and parenthesis _do_ become awkward (...) Coffeescript solves that problem." It's your opinion that coffeescript solves the callback and parentheses issue. I'd also call your argument a bit of red herring. ... FWIW? I think futures do a mighty fine job of solving callback issues; no coffeescript needed. Design around them, don't make a whole new "dialect" for it..
- ilaksh 13y agoFor callbacks I have found ToffeeScript to be an even bigger improvement than CoffeeScript. You can write code like this: e, personJson = fs.readFile! "person.json" person = JSON.parse personJson matchesLastname = myDB.query! "lastname", person.name id = msgQueue.push! { JSON.stringify(matchesLastname) } log.info "Message sent to queue: #{id}" instead of this: fs.readFile("person.json", function(e, personJson) { var person = JSON.parse(personJson); myDB.query("lastname", person.name, function(matched) { msgQueue.push(JSON.stringify(matchesLastname), function(id) { log.info("Message sent to queue: " + id); }); }); }); Why do you believe that it is better to design around serious issues rather than creating a new paradigm? I have found that the best solutions always involve a new/different fundamental model that incorporates solutions to recurring problems.
- rubyn00bie 13y agoI 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.
- ilaksh 13y agoWhat would the code look like for my example using futures in JavaScript?
- TheZenPsycho 13y agofs.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); });
- ilaksh 13y agoThat's part of it. What about creating the promises?
- emn13 13y agoIf anything, coffeescript is the status quo. People just assume it's the hip thing to do; that if you're using JS it's because you simply haven't bothered evaluating coffeescript. What problems do you think coffeescript solves?