Ioan Lazarciuc's Weblog I program, therefore I exist.


Managing "Global Constants" with a Database


There always comes a time while developing an application when a programmer has to introduce some "constants". These may be Id's, names, time intervals. The first action is to just put the literal constant where it's needed first.

Once the value of the constant is needed in additional places, a decision has to made: where to store the "constant". The really bad answer would be to just reuse the literal constant. A better approach would be to create a "const" or "readonly" field with the required value. This is perfectly fine if the constant has a very little chance of changing it's value (due to specifications change some of the constants may change). Changes to constants defined in this way can only be performed by recompiling the code and redistributing the new build.

Sometimes the probability of change for a "constant" is so high, that it actually becomes a "global variable" (even though it may continue to be called a "constant"). Recompiling the whole solution now becomes unfeasible.