First-principles exercise

When I do a first-principles exercise, I like thinking in nouns and verbs i.e. what kinds of nouns and verbs would I need to be able to describe what I want to implement?

First and foremost, I think of Git as a storage service: one that saves the state of your source code throughout time, and allows you travel to different states in history. What nouns and verbs do I need to describe a time-travelling service for a file system?

A time-travelling service needs snapshots of the file system. A file system consists of files and folders. I take snapshots of the file system. I connect different snapshots together. I travel to different snapshots. I create new branches in time. I keep track of where I am in time.

The identified nouns are:

  1. Snapshots
  2. File system
  3. Files
  4. Folders

The identified verb-noun pairs are:

  1. take-snapshot
  2. connect-snapshots
  3. travel to-snapshot
  4. create-branch
  5. keep track-snapshot

These nouns and verbs approximately describe the Git API.
Taking snapshots

What does it mean "to take a snapshot" of a file system? I need a way to represent files and folders. In Git, files are called blob objects and folders are tree objects. All Git objects are stored in .git/objects, which means that this folder serves as a database!

Blobs and trees are both named by SHA-1 hashing their contents. The first two characters of the hash constitute the folder in which in the object will reside; the remaining characters make up the name of the object.

Blobs and trees have different structures. Trees are nested structures, so they have a 3-tuple form. In code,

Resources