A Real-Life Example of PBT.
Hi! This is a part of my series on mental models. Click here for other parts.
What Is a Record Locator.
A record locator can be used to provide a human-readable representation of a database primary key, providing users with a short, easy-to-read and pronounceable string, like those alpha-numeric confirmation codes that flight companies usually provide.
The library record-locator.
The record-locator library implements the algorithm above (i.e. encodes integers into a short, easy to read string). This library can encode 33 million integers in only five-character.
Examples.
- The integer
8128
encodes to the record locator9Y2
- The integer
3141592
encodes to the record locator4ZVYR
- The integer
355688197484
encodes to the record locatorDEADBEEF
The Example.
Because a record locator is used the locate an id, decode(encode(x))
should always equal x
—that’s the whole point, really. In PBT, we can express this exact property, as working code.
You can read the Pull-Request to see the rest of the tests.