Coding Suggestions and Rules of Thumb
Contents
- "Measuring software productivity by lines of code is like measuring progress on an airplane by how much it weighs."
- — Bill Gates
Some Things We Want to Achieve
- create/modify programs efficiently
- less likely to introduce errors (bugs) into code
- create efficient program
- ease of maintaining/modifying code
Approaches: Top-down and Bottom-up
Algorithms
- Create one with pen and paper
- Use pseudo code
- Does not need to be (and probably should not be) valid C++ syntax
- Features of an Algorithm [Knuth]
- Finiteness
- Definiteness
- Output
Result of the computation
- Input
Objects/data given before algorithm begins
- Effectiveness
Sufficiently basic operations to solve a specific class of problems
Use Functions
- Abstraction
- Decomposition
Compile vs Runtime Errors
- Prefer compile-time errors to run-time errors
- 100% of compile time errors are detected, not so with runtime errors
- E.g., use const to more fully express your intentions
Minimize Redundancy
- Ideally, each characteristic of the program is included once (both implicitly and explicitly)
- Error prone/tedious/time consuming to maintain the redundancy
- E.g., easy to overlook changing one of the pieces that are redundant but forget to change other(s)
Minimize Dependency
- Difficult to detect adverse effects when making changes to code
- Increases code reuse
- E.g., code that is not dependent on an application can more easily
be shared among many applications. This is one feature of
libraries.