Encoded Assumptions
While coding programmers invariably have to make lots of assumptions. Because of change in business logic or external circumstances those assumptions may not remain valid. Since the same assumption is coded at multiple places in a Software it becomes a maintainence nightmare to locate and correct the code.
For example, a code that checks whether a given phone number is local or not may simply compare its area code with the local area code. However, this assumption may not be true if local phone company starts treating calls within the same local area code as local toll calls.
One solution is to code assumptions explicitly. For example, in the above case, the assumption was All_Calls_Within_Same_Area_Code_Are_Local. Give each assumption a name, and define a C macro by the same name. The macro should currently expand to TRUE. Assert the macro wherever the assumption is made, like this: assert(All_Calls_Within_Same_Area_Code_Are_Local). Since, it is currently defined as TRUE, assert will expand to nothing.
It becomes very easy to find out all the places in the code where a particular assumption is made by simply searching for the use of the corresponding macro. To find out places where the assumptions are being made that are false dynamically, simply redefine the corresponding macros to FALSE. The modified code will start asserting everywhere those assumptions were made.
Thus, this method allows easy documentation, easy detection and testing for all the critical assumptions that a software makes. This aids in maintainence greatly.
For example, a code that checks whether a given phone number is local or not may simply compare its area code with the local area code. However, this assumption may not be true if local phone company starts treating calls within the same local area code as local toll calls.
One solution is to code assumptions explicitly. For example, in the above case, the assumption was All_Calls_Within_Same_Area_Code_Are_Local. Give each assumption a name, and define a C macro by the same name. The macro should currently expand to TRUE. Assert the macro wherever the assumption is made, like this: assert(All_Calls_Within_Same_Area_Code_Are_Local). Since, it is currently defined as TRUE, assert will expand to nothing.
It becomes very easy to find out all the places in the code where a particular assumption is made by simply searching for the use of the corresponding macro. To find out places where the assumptions are being made that are false dynamically, simply redefine the corresponding macros to FALSE. The modified code will start asserting everywhere those assumptions were made.
Thus, this method allows easy documentation, easy detection and testing for all the critical assumptions that a software makes. This aids in maintainence greatly.
0 Comments:
Post a Comment
<< Home