I like to write assertions that aren't always easy to check. Like asserting that a list is sorted.
We captured these consideration in the internal docs here: https://github.com/tigerbeetle/tigerbeetle/blob/0.16.60/src/...
However, several factors have to be taken into account regarding performance impact when they get cleverly written, thus in manys cases they can only be fully turned on during debug builds.
It seems to be used for stuff like this, though I'm yet to really look into it properly.
It’s only O(n), but if I check that assertion in my binary search function then it might as well have been linear search.
void process_list(List aList)
in(aList.isSorted, "List must be sorted!")
do
{
// do something
}
However the O() cost of calling isSorted() has an impact on overall cost for process_list() on every call, hence why the way contracts are executed is usually configurable in languages that have them available.Whats trivial for a very small list, may be a no-go for gigabyte-sized lists.