-
Notifications
You must be signed in to change notification settings - Fork 33
Coding Conventions
Fredrik Eldh edited this page Jun 26, 2015
·
7 revisions
Purpose of the coding conventions is to make it easier to understand and maintain the code.
- 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
- Comment particularly complex lines or sections of code to help future maintainers (including yourself)
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"
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