Skip to content

Instantly share code, notes, and snippets.

@gioAlea
Last active May 16, 2016 08:11
Show Gist options
  • Save gioAlea/4c52d5d6f3073640fa07f4ea43d76d13 to your computer and use it in GitHub Desktop.
Save gioAlea/4c52d5d6f3073640fa07f4ea43d76d13 to your computer and use it in GitHub Desktop.

Variables

  1. Variable names should be in mixed case, starting with lower case: linearity, credibleThreat, qualityOfLife
  2. Large scope variables should have a meaningful name, short scope (e.g. counters) variables should have short names
  3. Variable representing the number of a certain object should be given the prefix n (or m if matrix): nFiles, nSeeds,mRows
  4. 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...
  5. Variables representing the index/number associated with a single entity should be prefixed by i: iTable, iEmployee
  6. Iterator variables should be prefixed by i,j,k, etc.
  7. Avoid negated boolean variable names: avoid isNotFound; rather use ~isFound
  8. Acronyms, even if normally uppercase, should be mixed or lower case isUsaSpecific rather than isUSASpecific
  9. Don't used reserved keywords or special values in variable names (check with iskeyword command)

Functions

  1. Function names should be written in lowercase, so that .m file and function name are exactly identical: getname(.)
  2. 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
  3. Functions with a single output can be names for the output: mean()
  4. Functions with no output argument or that only return a handle should be named as what they do: plot()
  5. Use get/set only for functions accessing an object or property of a structure variable
  6. Function that compute something should get the prefix compute: computespread()
  7. Where something is looked up, use the find prefix: findheaviestelement
  8. Function where something is initialized should get the prefix initialize : initializeproblemstate()
  9. Boolean functions should get the prefixes is or has or can : isoverpriced() , iscomplete (), haslicense()
  10. 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.
  11. Function names should be unique. Check it with which -all or exist

References

+[1] R. Johnson, 'Matlab Programming Style Guidelines'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment