Based on the following quote from Coders At Work...
But once you know the invariant that it's maintaining, you can see,
ah, if we maintain that invariant then we'll get log lookup time.
...I guess "invariant" = "condition you want to maintain to ensure a desired effect".
It seems that invariant has two senses that differ in a subtle way:
- Something that stays the same.
- Something that you're trying to keep the same, in order to achieve goal X (such as a "log lookup time" above).
So 1 is like an assertion; 2 is like a tool for proving correctness, performance, or other properties - I think. See the Wikipedia article for an example of 2 (proving the correctness of the solution to the MU puzzle).
Actually a 3rd sense of invariant is:
.3. What the program (or module or function) is supposed to do; in other words, its purpose.
From the same Coders At Work interview:
But what makes big software manageable is having some global invariants or big-picture statements about what it's supposed to do and what things are supposed to be true.