CoffeeScript

Maxime Lathuilière edited this page Oct 14, 2016 · 8 revisions

(why|what is) CoffeeScript?

tl;dr: no more })})));});, meaningful indentation makes your code look beautiful! :heart:

CoffeeScript is a language allowing to write clean, unfancy code that compiles to JavaScript before being run either by the server or the browser as normal JS. But as the developers of CoffeeScript put it: it just JavaScript!.

So if you already know JS, it should be super easy for you to learn it: go to the official website to learn from the (quite short) doc, or read a (free) book such as The Little Book on CoffeeScript. You can also play with JS2Coffee to experiment with the differences.

If you don't know JavaScript, start by learning it: here is a list of great resources to start learning JS.

Code Guidelines

### Syntax Master rule: Prefer code readability over cleverness

For the rest, we are largely following those guidelines & conventions:

[Update]: the projects conventions actually sensibly diverged from the two reference above. Ideally, those should comprehensively listed here, but it the meantime, simply take inspiration from the existing code convention and open an issue if you see inconsistencies.

Inheritence

Prefer composition over classes inheritance

### Notable Influences

Project specificities

Promises

Uses promises flow as a clean summary of the functions called, using partials functions.

user_.getUserId req
.then items_.verifyOwnership.bind(null, id)
.then items_.delete.bind(null, id, rev)
.then res.json.bind(res)
.catch error_.Handler(res)

Partials

Prefer items_.delete.bind(null, id, rev) over _.partial(items_.delete, id, rev)

It makes promises flows a more explicit summary by highlighting the function used instead of the fact it is a partial

Higher-order functions

Functions returning functions should have their name capitalized.

Exemple: error_.Handler, a functions typically used in controllers promises flow: .catch error_.Handler(res)

Discussion

You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.
Press h to open a hovercard with more details.