-
Notifications
You must be signed in to change notification settings - Fork 1
Code Style
Classes use PascalCase
Everything else uses camelCase
Do not use abbreviations. Always write out the whole word. If a variable name is too unwieldy, use an acronym instead.
The only exception is for names which are reserved words. These should be avoided in the first place but the following are acceptable abbreviations:
-
arr
for arrays -
fn
for functions -
num
for numbers -
obj
for objects -
str
for strings
Acronyms should always be fully upper-case or fully lower-case. Which one depends on their position within the variable name: if they are the first “word” in the name, they should be fully lower-case, however if they are the 2nd or later “word”, they should be fully upper-case.
.entityIds // wrong
.entityIDs // correct
.JSONData // wrong
.jSONData // wrong
.jsonData // correct
Classes should be organized in the following order:
- Property declarations
- Constructor
-
get
andset
functions, grouped by property, alphabetically - All other methods, alphabetically
These rules should be observed when writing comments.
Single line comments can be sentence fragments, and should be at most a single sentence with no end-punctuation.
Multi-line comments should be full sentences including punctuation.
Avoid “this”.
This is a class, not an instance, so use “the [class],” instead of “this [class]” to refer to whatever entity instance is actually calling the function.
Be concise.
For example, avoid writing “type of component” and instead say simply ”component type.”