I have read that when programming it is good to identify relations -- invariants -- that should hold true throughout the program, and it is good to insert assertions throughout the code to check that the invariants are maintained.
I can see how programs that involve mathematics can have invariants, i.e., some mathematical relation must be true throughout the code's manipulations.
Are there invariants in non-mathematical problems?
Are there invariants in text processing programs?
Suppose the processing problem is to transform one terminology to another. Are there invariants in this problem?
Let's take a specific example. The first vocabulary has an item TYPE whose value is A, B, C, or D. The second vocabulary has an item airIndicator whose value is Civil, Joint, Military, or Private. After reading the documentation it is determined that the mapping is as follows:
A maps to Civil. B maps to Joint. C maps to Military. D has a different meaning than Private so whenever D is encountered an error should be generated.
Here is pseudocode to do the mapping:
if TYPE = 'A' then "Civil" else if TYPE = 'B' then "Joint" else if TYPE = 'C' then "Military" else if TYPE = 'D' then error("No mapping for D") else error("Invalid TYPE value")
Is there an invariant in that mapping?
When you write text processing programs do you identify invariants and then insert assertions throughout your code to check that the invariants are maintained?