Is it better for Discourse to use JavaScript or CoffeeScript?

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)

2 Likes

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.

9 Likes

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.

3 Likes

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.

2 Likes

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;
});

with:

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:

[
  1
  ->
  2
  ->
  3
 ->
  4
  ->
  5
  ->
  6
]

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

[
  1, function() {}, 2, function() {}, 3, function() {
    4;
    (function() {});
    5;

    (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.

4 Likes

Some of my pet annoyances

foo = bar ->
  ""
var foo;

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

foo = bar->
  ""

no compily


foo=(bar)->
  ""
var foo;

foo = function(bar) {
  return "";
};
2 Likes

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

Typescript is totally not windows only. Itā€™s vanilla node.js code and runs anywhere.

What if you would convert each module/script to vanilla as itā€™s modified? This would gradually convert everything over to JS as time permits. A solid style guide would be a must though!

I find that you can tab-trigger your way out of the ā€˜vanillaā€™ JS is more typing problem. You can have presets setup for almost everythingā€¦ methods, functions, anon callbacks, AMD modules, etcā€¦

One advantage that CS has is that itā€™s more readable if you work with CS a lot. However, I found it hard to parse blocks when I first started writing it ( I mainly use it for tests currently).

1 Like

From a personal perspective, the only reason I would contribute to discourse is because the client base is coffee script. JavaScriptā€¦ All the amazing innovations in techā€¦ JavaScript? Kids donā€™t like it, and Iā€™d put 50 bucks that JavaScript is the mainframe tech stack of the next generation(to be replaced). 5 years from now your coffee script can be compiled into JavaScriptā€™s replacement. Discourse is awesome BECAUSE coffescript was used and enables creativity to trump syntax. Switching to JS might just send you ā€œoff courseā€.

I would hope you would like to contribute to the project because you believe in the mission, like the software and want to evolve and improve online Discourse, not purely because we chose js or cs.

2 Likes

5 years from now your coffee script can be compiled into JavaScriptā€™s
replacement.

Javascript has been running in browsers for 18 years. Itā€™s been adopted by every browser on every platform.

Itā€™s possible that in 5 years, an alternative language will be supported by some browsers (and that would be nice). But itā€™s near-certain that Javascript will still be supported by all browsers. It has too much inertia to disappear that fast.

2 Likes

I agree with you on your point. To clarify: Itā€™s not that I would only contribute to CS projects, it is that Iā€™m not a JavaScript guru (Iā€™m more of a devops/data warehouse/automation creature). I see CS as a tool that enables others to create clean & functional JS, is easier to read (opinion), and would provide an easier entry for me as a contributor.

Though come to think of it, it seems there are other barriers to contributing to open source other than the language itself. Contribution processes, Git pull requests, anxiety around being publicly chastised for janky pull requests, etc. :smile:

How about streamlining the contribution process? Seems like there could be an opportunity here for some interesting open source development as wellā€¦ a ā€œGitHubā€ like service that manages contributions, integrates with github(others), and makes the contribution process more welcoming for developers who may be coming from varied backgrounds.