- classes (maps intended to be used with new) use captialized CamelCase:
- method names use camelCase, starting with lower-case, e.g.:
- variables follow the same convention:
Nouns vs. Verbs
In general, methods that perform some operation should be active verbs, e.g.
applyDiscount. Clear abbreviations are acceptable when a name would otherwise be unwieldy, e.g.
calcTotal instead of
calculateTotal. Methods that merely return an attribute (whether stored or calculated) should be named for what they return, e.g.
average. (The line between these two cases can be fuzzy; favor a simple attribute name if the calculation is quick and has no side effects, but an active verb if the calculation may take some time or has any effects beyond returning the answer.)
Object references should be descriptive nouns, e.g.
Very short variable names should be used only for fleeting purposes, such as loop counters in small loops, or parameter names in small functions. They are also often used when experimenting in a REPL. The following names are generally understood:
j: loop counters (usually numbers)
c: character (e.g. while looping over a string)
y: 2D coordinates
dy: 2D offset
vy: 2D velocity
dt: time step or offset
s: a string, or any sequence
d: a map (
dis short for "dictionary")
a: a list (
ais short for "array"; and note that
llooks very similar to
1, and so should probably be avoided)