Skip to content
Fredrik Eldh edited this page Jun 26, 2015 · 7 revisions

Purpose

Purpose of the coding conventions is to make it easier to understand and maintain the code.

List of conventions

  • Indent using tabs
  • Use descriptive names, avoid abbreviations if possible
  • Keep placement of brackets and use of semicolons consistent within a file
  • Aim for 80 character line length
  • Comment key classes/functions to help people understand the overall structure

Additional conventions

Here are some conventions that have been used by the JavaScript code in the "hyper" folder in the evothings-studio repo:

  • Ending semicolons are not used (to reduce "line noise"), which is also common in Lua
  • Variables that refer to modules are in CAPS to make it clear that they are modules and not local variables
  • Variables global within a module are prefixed with "m"

JavaScript Gotchas

When not using ending semicolons, lines that start with a opening paren must begin with a semicolon to avoid joining of lines, like this:

;(...

Be aware that a new line after return makes the function return undefined.

This returns undefined:

return
    1 + 2

This returns 3:

return 1 +
    2
Clone this wiki locally