Fundamental Coding Principles
by Brian Russin
-
Make Decisions at the Highest Possible Level
-
When a logical decision must be made, it should be made at the highest level of the software where all the necessary information to make the decision is available.
-
Member variable access should be public
for Data-centric objects and private
for Function-centric objects.
-
In most cases, objects are either data-centric or function-centric, with a primary purpose to either hold data or perform functions, respectively.
-
This is an observation, not a rule.
-
I do not mean that data-centric objects should not perform functions, or that function-centric objects should not hold data, I just mean that an object usually leans heavily in favor of one purpose or the other.
-
In languages that support default
public
or private
member variable access, this can be defined at a high level.
-
In C++, for example, a data-centric object should be declared as a
struct
or C-struct
, and a function-centric object should be declared as a class
-
The Only Reliable Analysis of Behavior is Derived Through Observation
-
Reverse-engineering trumps documentation every time.
-
Only the code tells the truth.
-
Eliminate Compiler Warnings ASAP
-
Compiler warnings indicate areas of the code that can be problematic. Possibly problematic code leads to runtime errors, or unintended behavior. Resolve as many compiler warnings as possible, as soon as possible.