Software modeling is all about relations. Symbols like 0 and 1 acquire meaning only after we define how they relate - e.g. less_than = {(0, 1)}, greater_than = {(1, 0)}, equal = {(0, 0), (1, 1)} etc. Because of this the choice of symbols doesn’t matter as long as desired relations hold. This self-evident and seemingly unimportant fact powers most optimizations, refactors and other transformations software engineers and tools perform every day.
For example, say, we need to print array of strings in sorted order.
This works and, indeed, less_than_or_equal relation holds for every adjacent pair of strings. But this relation doesn’t have to be coupled with array representation. Since symbols don’t matter, we can replace strings with their indices.
Now the same relation can be established using these indices
Decoupling relation representation from the input enables relatively cheap way to avoid input modification, which sometimes comes very hand. But that’s not all - turns out moving around heavy objects is not always desirable, so just like changing building numbers is easier than physically moving buildings, swaps performed by std::sort can quickly add up.
Even for relatively small strings benchmarks report pleasant 20% speedup
but it can be significantly higher for large structs that are fairly common for business domain classes.