Is it better for Discourse to use JavaScript or CoffeeScript?

Hmm, I may have to backtrack on my original opinion after giving this more consideration.

While I have been able to figure out how things work without too much issue despite not having a deep familiarity with either CoffeeScript or Ember, the combination does introduce a level of friction that makes me far more cautious when making changes.

I imagine that if the codebase was purely JavaScript, which I’m confident with, I’d be able to focus more easily on understanding the Ember side of things without worrying that I missed some CoffeScript shenaniganery that might not produce exactly the behaviour I was after.


While we’re deep in bikeshedding zone,

The pretext in the responses seem to be that enough hypothetical proficient Ember.js devs are going to be dissuaded from contributing to Discourse at such a substantial rate that it’s worth getting rid of Coffeescript.

And that it ostensibly outweighs the benefits that non-hypothetical, real-life Discourse contributors experience while maintaining a Coffeescript codebase, particularly that of the core dev team.

:bike: :house:

1 Like

CoffeeScript has significant whitespace.

So instant no. It makes it a pain in the butt to parse. It’s annoying. Most people (except for Python developers) don’t like it. Due to being difficult to parse, you will have problems when you try to refactor. Not to mention the problems of re-indenting everything when you have really long and ugly blocks you want to clean up (happens).

Stick with JS. More people are experienced with JavaScript afterall and critical mass in attracting developers is important for Discourse.


Actually, this problem could not occur in JavaScript, because ES6+ will always be backwards compatible with the current version of JavaScript. Further, the “1JS” principle means that you will be able to take existing code and opt into new features simply by using the new syntax (there will be no “use es6” pragma or version switch).

The core difference is that ES6 is, by definition and by requirement, a strict superset of current JavaScript. By definition, there can be no new syntax that is incompatible with existing JavaScript.

In contrast, how would CoffeeScript target the new for/of loops, when they already have for/of loops of their own? Sure, they could add new syntax, but it would be massively confusing for for/of to target the old semantics, and some other syntax to target ES6 for/of.

Similarly, CoffeeScript classes and super have subtly different semantics than ES6 classes and super. If CoffeeScript started targeting the new semantics, they would break existing code. If they required a different keyword to target ES6 class, it would, again, be very confusing.

You could imagine an incompatible CoffeeScript 2 that targeted ES6 syntax, but existing CoffeeScript code would not work. Again, this cannot happen in future versions of JavaScript, because new JavaScript features are required not to break existing JavaScript code.

It may be a bit difficult to wrap your mind around the difference, but I assure you, it’s true.


JavaScript all the way. There are way more JavaScript developers than CoffeeScript developers (and more JavaScript devs than Rails devs, I assume). I think you’ll get more contribution by opting keep the codebase in JavaScript.

And as for personal preference: I won’t write CoffeeScript (for free). So there is some evidence right there, @eviltrout! :-p

p.s. CoffeeScript reminds me of VB. And nobody likes VB.


Aside from the points that have already been discussed, I’ve noticed that writing Ember apps in CoffeeScript also just feels a little off. Several of the niceties of Ember, like computed properties, are expressed as extensions on the JS Function prototype:

MyApp.president = Ember.Object.create({
    fullName: function() {
      return this.get('firstName') + ' ' + this.get('lastName');
    }.property('firstName', 'lastName')

This requires you to use parens in CoffeeScript, which kind of defeats the purpose of the significant whitespace:

MyApp.president = Ember.Object.create
    fullName: (->
     @get('firstName') + ' ' + @get('lastName')
    ).property('firstName', 'lastName')

In addition to that, there’s the CoffeeScript class vs Ember extend() stuff, CS iteration vs Ember enumerables, etc. I just think there’s enough of an impedance between using CS and using Ember to make it more appealing to just use pure JS with Ember.


I guess, but less of a hybrid, if every single time I debugged Ruby I had to run GDB and constantly found myself reading C source I think it would be closer. If every time I wrote I line of Ruby I had to construct a mental model of the way MRI is going to translate the thing to C (for example because I need to know its going to wrap up my switch statements in a closure or what have you), we would be a more of a hybrid system.

Well, we have seen almost no contributions from the community wrt refactoring our js and we are a HUGE js app. In contrast we have seen massive amounts of refactoring around the Ruby side of things. Impossible for me to pin this on CS as I have no crystal ball, but it is a fact.

On a personal level I would be happy to never use CS again, I feel my hands are tied in weird ways and it encourages me to write stuff that I probably would never have written in the first place (like 4 levels of nested functions)


It seems like the people have spoken.

I’m convinced! I am on board to convert the coffee to regular JS, assuming of course we set up jshint as part of our testing system.


This seems like a sound decision. If you want any help with setting up automated jshinting, let me know.

1 Like

Wise choice @eviltrout.

I prefer CoffeeScript, personally, its the only language I write in that I don’t think about the language.

However, Discourse is going to (hopefully) be around for a very long time. There are so many things that are going to be difficult for CoffeeScript in the future. For example, default arguments. null in CoffeeScript will defer to the default while in ES6 it will not because null !== undefined. I can’t see how it will target ES6 successfully and keep backwards compat.

Worth noting, CoffeeScript fell off the top 10 list on github. CoffeeScripters usually still like and write JavaScript, including the language’s creator. Discourse will get more contributors with JavaScript without question.

Better create a style guide first.


I prefer jS since it’s better to write in JS since the it will take a bit of time for another contributor to convert the current “Getting Started Guide” or “Tutorial” from Ember and another lib written in JS to coffeescript.

I feel you.

Javascript skills in general are already hard to find.

And since Ember devs are a fractional subset of that, It’s hard enough to find Ember devs that can contribute, JS or CS.

We had this similar discussion at work, but it’s obviously a lot different when you’re hiring people than leaning on open contributions.

Thank you, @eviltrout, that makes me a lot more confident in Discourse’s future. Lowering the bar for contributors is a good thing :sunny:

1 Like

Help, a PR or anything in this area would be much appreciated !

Not sure how quickly I could get a PR out, but if you want to ping me directly I can at least try to point you in the right direction.

First, whitespace itself is not significant in CoffeeScript, any more than it is in Javascript (where it separates tokens, as in virtually every other language). Whitespace is not significant in Python either - indentation level is. See Python: Myths about Indentation. Coffeescript works the same way.

Second, significant indentation is not actually hard to parse. On the contrary, it’s very simple - I refer you back to the above article. Essentially, the parser simply parses the difference in indentation as and tokens, modifying the level accordingly. While this might be slightly more difficult to parse than bracket-based blocks, it is hardly a “pain in the butt” to parse.

There are several things significant indentation does make harder:

  • Parsing with regexes. Which you should never do in the first place.
  • Mixing tabs and spaces. Which you should never do in the first place.

This is completely subjective (and I suspect it’s probably not true).

… which is much easier than balancing brackets, because it’s obvious at a glance. You already have to reindent when you write code in a bracket language. Now you just don’t have to balance the brackets.

This is the real reason Discourse should use Javascript. Don’t get me wrong - I do prefer Coffeescript, I just think Javascript is more appropriate for the official Discourse client.


I disagree that indentation-sensitivity is not a type of whitespace-sensitivity, but even if that applies to Python it does not apply to CoffeeScript. CoffeeScript is more whitespace-sensitive than Python. Compare:

jQuery ($) -> bar
jQuery(function($) {
  return bar;


jQuery($) -> bar
jQuery($)(function() {
  return bar;

It also doesn’t enforce consistent indentation in the same way as Python, allowing for silly cases like this:


Instead of causing a compile error, the mis-aligned -> alters how the indentation of subsequent lines is interpreted.

  1, function() {}, 2, function() {}, 3, function() {
    (function() {});

    (function() {});
    return 6;

I followed the CoffeeScript project on GitHub for a while, and my impression is that there are tons of edge cases in the compiler whose behaviour is poorly defined, varies between versions and may be difficult to replicate without a direct port. Part of the goal of the CoffeeScript 2.0 project was to define the grammar more rigorously, but I don’t know the status of that project.


Some of my pet annoyances

foo = bar ->
var foo;

foo = bar(function() {
  return "";

foo = bar->

no compily

var foo;

foo = function(bar) {
  return "";

I concur with this if for no other reason than I use OTBS and the indentation is far more important to me than the closing brace. The closing brace is at best a handy visual aid to ensure I’m at the end of the intended logic branch, but only because braces are required.

On the flip side, braces allow me to use inline stubs for things like encapsulating API methods or throwing exceptions where code has not yet been implemented.

Perhaps I’m unique, it certainly seems so from reading the posts above, however I’d like to add that I’m much less likely to contribute to a project written in javascript than in coffeescript, and I also happen to be someone with the exact skillset necessary to contribute (rails/ember/coffee).

Does it come down to taste? I guess that ultimately it does, however I find that after working with coffeescript for so long writing, pure js just feels incredibly annoying, slow and unwieldy.

It certainly seems like I’m in the minority, however I don’t find that to be unusual when talking about coffeescript!

1 Like