- Variable names should be in mixed case, starting with lower case:
linearity, credibleThreat, qualityOfLife
- Large scope variables should have a meaningful name, short scope (e.g. counters) variables should have short names
- Variable representing the number of a certain object should be given the prefix n (or m if matrix):
nFiles, nSeeds,mRows
- Adopt a convention on pluralization: either make all variable names singular or plural: don't create two variables that differ only by the final letter...
- Variables representing the index/number associated with a single entity should be prefixed by i:
iTable, iEmployee
- Iterator variables should be prefixed by i,j,k, etc.
- Avoid negated boolean variable names:
avoid isNotFound; rather use ~isFound
- Acronyms, even if normally uppercase, should be mixed or lower case
isUsaSpecific rather than isUSASpecific
- Don't used reserved keywords or special values in variable names (check with
iskeyword
command)
- Function names should be written in lowercase, so that .m file and function name are exactly identical:
getname(.)
- Function should have extended meaningful names, avoid acronyms unless widely used (e.g.
max()
): in the latter case in any case express the full acronym as first line in the comments - Functions with a single output can be names for the output:
mean()
- Functions with no output argument or that only return a handle should be named as what they do:
plot()
- Use get/set only for functions accessing an object or property of a structure variable
- Function that compute something should get the prefix compute:
computespread()
- Where something is looked up, use the find prefix:
findheaviestelement
- Function where something is initialized should get the prefix initialize :
initializeproblemstate()
- Boolean functions should get the prefixes is or has or can :
isoverpriced() , iscomplete (), haslicense()
- Complementary functions should get complementary prefixes:
get/set , add/remove, create/destroy, start/stop, insert/delete, increment/decrement, old/new, begin/end, first/last, up/down, min/max, next/previous, old/new, open/close, show/hide, suspend/resume, etc.
- Function names should be unique. Check it with
which -all or exist