Asserting Implications
A short one today!
When using assertions heavily, a common pattern is asserting an implication:
assert(a implies b);
Most programming languages don’t have special syntax for implication, as you don’t often branch based on implications. But in my experience, you want to assert implications all the time!
Recall that and
, or
, and not
logical operators form a basis, so an implication can be expressed in
terms of disjunction and negation:
This tautology is how asserting that a
implies
b
gets expressed by default:
!a or b); assert(
I find this form hard to read, and suggest using the if
instead:
if (a) assert(b);
From a recent code change:
// Before:
!= null or replica.commit_min == replica.op_checkpoint);
assert(header_b
// After:
if (header_b == null) assert(replica.commit_min == replica.op_checkpoint);