Best Coding Practices

From Coder Merlin
πŸ‘ Best Practice πŸ‘ #261 πŸ‘
HintIcon.png
Flowcharts are your friend


πŸ‘ Best Practice πŸ‘ #657 πŸ‘
HintIcon.png

Use appropriate capitalization

  • Names of types and protocols are UpperCamelCase (Pascal case)
  • Everything else is lowerCamelCase


πŸ‘ Best Practice πŸ‘ #359 πŸ‘
HintIcon.png
Clarity is more important than brevity


πŸ‘ Best Practice πŸ‘ #563 πŸ‘
HintIcon.png

Preconditions are your friend

  • Include sufficient information for the message to be useful


πŸ‘ Best Practice πŸ‘ #174 πŸ‘
HintIcon.png

Great functions exhibit these three vital properties:

  • Easy to read and comprehend
  • Easy to debug
  • Easy to modify to solve a variation of the original task

[1]

  • 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
  • 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

References[edit]