Difference between revisions of "Best Coding Practices"

From Coder Merlin
Line 1: Line 1:
{{BestPractice|261|
Flowcharts are your friend}}
{{BestPractice|657|
Use appropriate capitalization
* Names of ''types'' and ''protocols'' are UpperCamelCase (Pascal case)
* ''Everything else'' is lowerCamelCase
}}
{{BestPractice|359|
Clarity is more important than brevity}}
{{BestPractice|563|
Preconditions are your friend
* Include sufficient information for the ''message'' to be useful
}}
* No global variables
* No global variables
* Appropriate capitalization
* Appropriate capitalization
Line 18: Line 39:
* Helpful whitespace
* Helpful whitespace
* Appropriate placement of closing braces and parentheses
* Appropriate placement of closing braces and parentheses
* Appropriate use of preconditions
** Include sufficient information to be useful
* Deliberate and helpful comments
* Deliberate and helpful comments
** Avoid "obvious" comments
** Avoid "obvious" comments
Line 28: Line 47:
** Generally one class per file
** Generally one class per file
* Code is clear and concise
* Code is clear and concise
== References ==
* [https://swift.org/documentation/api-design-guidelines/ API Design Guidelines] (Swift Documentation)
* [https://google.github.io/swift/#apples-api-style-guidelines API Style Guidelines] (Google Documentation)

Revision as of 23:45, 8 February 2021

Within these castle walls be forged Mavens of Computer Science ...
— Merlin, The Coder
Best PracticeHintIcon.png
👍 #261

Flowcharts are your friend


Best PracticeHintIcon.png
👍 #657

Use appropriate capitalization

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


Best PracticeHintIcon.png
👍 #359

Clarity is more important than brevity


Best PracticeHintIcon.png
👍 #563

Preconditions are your friend

  • Include sufficient information for the message to be useful


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