From kicking off shoes to event sourcing

The other day, Linda (age 5) and I went to the playground with the swings. She took 3 different shoes with her, to test which one goes the farthest when kicked off. I wore the same black flats that I kicked all the way across the playground last time.

On the way home, I asked, “So which shoe was the best?” She had a clear princess shoe, a black tie shoe, and a gray-and-purple running shoe. “The black one,” she replied. Then: “Your shoes went far, and they’re black too. It must be that black shoes go the farthest.”

That’s her working theory, that black shoes travel the farthest through air.

This is perfectly valid induction. In her observation, every black shoe went farther than every non-black shoe. Yet it makes no sense: there’s no causal link between color and distance traveled.

This illustrates the limitations of inductive logic. “It’s true there and there, this new situation is the same in some way, probably true here too.” It also illustrates the power of the human mind to construct categories and make judgements based on surface characteristics. 

This is the power of the silent analogies we make in our heads, the recognizing of likeness and the inference of shared properties. This affects our code too.

One reason OO is so popular is that we can think about objects, we can form analogies to the familiar physical world. Yet that costs us, because that Customer is not a customer. Limitations of the physical world leak into our designs.

For instance, in real life, only one thing can be in each place at a time. A customer only has one name, and when it changes in real life we want to change it in the database. Yet, if we loosen the analogy between the real customer and the customer object, we don’t have to destroy the old name to assign the new name. And I don’t mean making a CUSTOMER_HISTORY table to store the old data. I mean rethinking the whole database. Make a customer record into the sum of everything we’ve learned about the customer over time. We are not limited to specific slots that map to boxes on a form.

Event sourcing, it’s called, the perception that data is a sum of prior events rather than the occupant of a place. It looks at the cause of things – how did it get this way?

If Linda looked at the cause of each shoe’s trajectory, she’d find a lot more to do with a the flick of the ankle at the top of the swing than the color of the shoe.