Difference between revisions of "Best Coding Practices"

From Coder Merlin
Line 19: Line 19:
* Appropriate placement of closing braces and parentheses
* Appropriate placement of closing braces and parentheses
* Appropriate use of preconditions
* Appropriate use of preconditions
** Include sufficient information to be useful
* Deliberate and helpful comments
* Deliberate and helpful comments
** Avoid "obvious" comments
** Avoid "obvious" comments

Revision as of 11:56, 17 April 2019

Within these castle walls be forged Mavens of Computer Science ...
— Merlin, The Coder
  • No global variables
  • Appropriate capitalization
  • Appropriate and descriptive variable names
    • nouns are usually most appropriate
  • Appropriate and descriptive function names
    • verbs are usually most appropriate
  • Appropriate use of functions
    • In general, avoid mid-function exits
  • Avoid repetition
    • DRY: Do Not Repeat Yourself
    • DIE: Duplication is Evil
  • Appropriate scoping
    • Scope is no wider than absolutely necessary
  • Appropriate loops
    • Correct loop type
    • In general, avoid mid-loop exits
  • Appropriate indentation
  • Helpful whitespace
  • Appropriate placement of closing braces and parentheses
  • Appropriate use of preconditions
    • Include sufficient information to be useful
  • Deliberate and helpful comments
    • Avoid "obvious" comments
  • Avoid deep nesting
  • Avoid inappropriate nesting of functions
  • Limit line length
  • Appropriate file organization
    • Generally one class per file
  • Code is clear and concise