This repository has been archived by the owner on Jul 3, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 397
Style Guide
Jeff Dyer edited this page Jan 5, 2014
·
13 revisions
Note: This wasn't always followed, but any new code should do this.
- Indentation - 2 spaces
- Line Length - 80 characters
- Tab characters - not used to format code
- Encoding - UTF-8 with LF as line terminator (Windows system must be configured to not use CR/LF)
- variables and functions - lowerCamelCase
- constructor like functions - UpperCamelCase
- constants - ALL_UPPER_CASE_WITH_UNDERSCORES
- Always use braces and put them on same line even for single line control statements
if (someVar) {
return true;
} else {
return null;
}
Semicolons must be always added as statement terminators.
Use a trailing comma in an Array initializer ([one, two, three, ]) or object initializer ({one: 1, two: 2, three: 3, }) when the initializer represents a literal list of items that may grow or shrink overtime.
The motivation for this guideline is two fold:
- It avoids syntax errors due to copying the last item to extending the list.
- It signals to the user that this list is safe to extend.
A note to the concerned: [1, 2].length === [1, 2,].length
- Space after control statements (if, else, while, for, ...)
if (someVar) {
- Use only strict equalities (and inequalities) in control statements, e.g.
if (someVar === conditionA) {
return true;
} else if (someVar !== conditionB) {
return false;
}
The standard way of creating classes in Shumway is the following. Please note that by class we mean an object that is class-like. Also, note the naming of all anonymous functions.
var ClassName = (function () {
function constructor(...) {
...
}
constructor.prototype = {
functionName: function functionName(...) {
...
}
};
return constructor;
})();
- Use the available error handling functions:
unexpected("..");
notImplemented("..");
- Guard assertions using:
release || assert(condition, "...");
Mozilla 2019