Class/Function Models
Over the years of programming in c++, I've realized some underlying methodologies about how c++ can work with abstract concepts in 4 distinct models: tiny, small, medium, and large.
Tiny-
For tiny there is the macro concept which is where the macro is something small enough to where you wouldn't mind using the whole thing again when needed like min() and max(). The macro concept was used extensively in assemblers (compilers that only compiled assembly language), and carried through strongly in the c language. I’ve discovered that the #define c macros used extensively can make code very devious, so I have stopped using them and instead use inline functions. It seems the real benefit of macros is that it can give the ability to eliminate the call instruction (JSR), which really is only important for inner loops.
Small-
Then there is the function model which is something that can be independent of other functions. This is the smallest complete basic unit where it can work with its own local variables, and parameters to do everything needed to be done to accomplish the task.
Medium-
When the function needs more resources then local variables and parameters, this can be accomplished by using member variables in a class (Note: as far as I am concerned global variables do not exist). This new size was not really available in the c language, and thus made it difficult to write large programs. It is possible to do in c, but it is much harder to read.
Large-
Finally there is the complex class... this is a class composed of other classes... Visual Studio projects are a good example of this where they can create DLL’s for each project, and then other projects can be dependent on these.
|