Measuring badness of a program - I
Remember that we are talking about code. Not a running program. So what are the badnesses in a program code organization?.
I would assume a language that allows multifile compilation of a program. Since lot of codes are in C/C++ I will try to stress some of the badness of C/C++ program organization.
Macros are not debug friendly, and I've never seen a commercial progam that was not under debugger to fix a bug or two or more. Mostly macros are little beast in the sense that some repeatative computations needed to be used in several places in a program and yet they are not bonafied candidate to become functions. I would use any means to get rid of macros that are not simple, so that they are visible under debugger.
Constant defines are also very clumsy. Use all means to get them to be visible under debugger.
interchanging the purpose of file types. Usally header files are only for headers, and not for implementations of functions or routines. Similarly code files should have mostly codes. If a code file contains lot of defines, macros etc., they should have specific meaning to the file scope. If any of these are also found in any other header or source file, a potential conflict will come forth sooner or later.
Header files and source files should follow consistent folder (container ) structure. As an example folder named pgm could have a subfolder named inc and another subfolder named src. Now these two sub-tree should have as much similarities as possible. It is a simple indication that the original owner cares for other potential maintainers.
Usually any commercial program need qute a few helper functions. They should be group into files in a logical manner. As an example, if I have generic implementations of tree sturctures and its operations, they should not be in mutiple files, and they should not be in any program domain related files. A program domain file is where the domain knowledge of the program is implemented partly or fully.
Sad fact is that I've seen many of these badness even from really accomplished programmer.
Reader Comments