Difference between revisions of "Best Coding Practices"
From Coder Merlin
Line 1: | Line 1: | ||
{{BestPractice|249| | {{BestPractice|249| | ||
Flowcharts are your friend}} | Flowcharts are your friend}} | ||
{{BestPractice|657| | {{BestPractice|657| | ||
Line 8: | Line 7: | ||
* ''Everything else'' is lowerCamelCase | * ''Everything else'' is lowerCamelCase | ||
}} | }} | ||
{{BestPractice|359| | {{BestPractice|359| | ||
Clarity is more important than brevity}} | Clarity is more important than brevity | ||
}} | |||
{{BestPractice|563| | {{BestPractice|563| | ||
Line 18: | Line 16: | ||
* Include sufficient information for the ''message'' to be useful | * Include sufficient information for the ''message'' to be useful | ||
}} | }} | ||
{{BestPractice|174| | {{BestPractice|174| | ||
Line 24: | Line 21: | ||
* Easy to read and comprehend | * Easy to read and comprehend | ||
* Easy to debug | * Easy to debug | ||
* Easy to modify to solve a variation of the original task | * Easy to modify to solve a variation of the original task<ref>https://www.cs.mtsu.edu/~untch/karel/functions.html</ref> | ||
<ref>https://www.cs.mtsu.edu/~untch/karel/functions.html</ref> | |||
}} | }} | ||
Line 98: | Line 94: | ||
** calculated, or | ** calculated, or | ||
** retrieved from configuration | ** retrieved from configuration | ||
}} | |||
{{BestPractice|959| | |||
Do not place extraneous files into source control | |||
* Exclude all build artifacts | |||
* Exclude any "backup" files (e.g. main.swift~) | |||
}} | }} | ||
Revision as of 18:23, 13 November 2022
Within these castle walls be forged Mavens of Computer Science ...
— Merlin, The Coder
Best Practice
👍 #249
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[1]
Best Practice
👍 #057
No global variables
- Global variables are evil
Best Practice
👍 #207
Always use appropriate and descriptive variable names
- nouns are usually most appropriate
Best Practice
👍 #208
Always use appropriate and descriptive function names
- verbs are usually most appropriate
Best Practice
👍 #394
Orderly exits from functions
- In general, avoid mid-function exits
Best Practice
👍 #444
Avoid repetition
- DRY: Do Not Repeat Yourself
- DIE: Duplication is Evil
Best Practice
👍 #502
Scope appropriately
- Scope is no wider than absolutely necessary
Best Practice
👍 #523
Loop appropriately
- Correct loop type
- In general, avoid mid-loop exits
Best Practice
👍 #029
Always use appropriate indentation
- Helpful whitespace
- Appropriate placement of closing braces and parentheses
Best Practice
👍 #074
Use comments to advantage others
- Deliberate and helpful comments
- Avoid "obvious" comments
Best Practice
👍 #617
Nest appropriately
- Avoid deep nesting
- Avoid inappropriate nesting of functions
- Indent correctly according to nested level
Best Practice
👍 #831
Limit line length
Best Practice
👍 #907
Organize files appropriately
- Generally one class per file
Best Practice
👍 #947
Hardcode only when there is no other choice
- All other values should be:
- calculated, or
- retrieved from configuration
Best Practice
👍 #959
Do not place extraneous files into source control
- Exclude all build artifacts
- Exclude any "backup" files (e.g. main.swift~)
Exercises[edit]
Exercises
- M1297-28 Complete Merlin Mission Manager Mission M1297-28.
References[edit]
- API Design Guidelines (Swift Documentation)
- API Style Guidelines (Google Documentation)