CodeFaster

CodeFaster

One weird trick, bugs HATE him

Tyler Adams's avatar
Tyler Adams
Mar 02, 2021
∙ Paid

Today, we’re not talking about code. We’re talking about data.

SPOT Rule

Within a program’s data, every fact has a Single Point Of Truth.

That’s it. If your data does this, and it’s impossible to write a whole species of bug.

A Quick Example

This program tracks if people are friends (assuming no one-way friendships):

friends = {
}

def add_friends(a, b):
   if not are_friends(a, b):
     if a not in friends:
       friends[a] = set()
     friends[a].add(b)

     if b not in friends:
       friends[b] = set()
     friends[b].add(a)

def are_friends(a, b):
  return b in friends.get("a", set())

def main():
  add_friends("bob", "jim")
  print(are_friends("jim", "bob"))

Facts

The “facts” in this code are whether two people are friends. Are “bob” and “jim” friends? That’s a fact.

Points of Truth

For a given fact (say whether “bob” and “jim” are friends), where is it stored?

Two places:

  • whether “jim” is in friends[“bob”]

  • whether “bob” is in friends[“jim”]

This violates the SPOT rule.

Writing a bug

Cons…

This post is for paid subscribers

Already a paid subscriber? Sign in
© 2025 Tyler Adams · Privacy ∙ Terms ∙ Collection notice
Start your SubstackGet the app
Substack is the home for great culture