A Real-Life Example of PBT.

Gunar Gessner
2 min readMar 12, 2019

--

Photo by rawpixel on Unsplash

Hi! This is a part of my series on mental models. Click here for other parts.

tl;dr

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.

(Why You Shouldn’t Post Your Boarding Pass on Social Media)

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 locator 9Y2
  • The integer 3141592 encodes to the record locator 4ZVYR
  • The integer 355688197484 encodes to the record locator DEADBEEF

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.

--

--