Difference between revisions of "Best Coding Practices"
From Coder Merlin
Line 55: | Line 55: | ||
** Generally one class per file | ** Generally one class per file | ||
* Code is clear and concise | * Code is clear and concise | ||
== Exercises == | |||
{{Exercises| | |||
* {{MMMAssignment|M1297-28}} | |||
}} | |||
== References == | == References == |
Revision as of 13:52, 18 January 2022
Within these castle walls be forged Mavens of Computer Science ...
— Merlin, The Coder
Best Practice
👍 #261
Flowcharts are your friend
Best Practice
👍 #657
Use appropriate capitalization
- Names of types and protocols are UpperCamelCase (Pascal case)
- Everything else is lowerCamelCase
Best Practice
👍 #359
Clarity is more important than brevity
Best Practice
👍 #563
Preconditions are your friend
- Include sufficient information for the message to be useful
Best Practice
👍 #174
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
- 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
Exercises[edit]
Exercises
- M1297-28 Complete Merlin Mission Manager Mission M1297-28.
References[edit]
- API Design Guidelines (Swift Documentation)
- API Style Guidelines (Google Documentation)