Inside Out

Notes on seeking wisdom and crafting software

Principles and Patterns

Principles have universal applicability. They’re true in most of the contexts. Depending on their scope, we term some of the principles as laws. Others can stay at a personal level, the set of truths we value in the day to day interactions in the world at large.

Take Compounding as an example. It states that non linear outcomes are possible with marginal changes applied for a long time. We come across this in high school maths, and possibly apply this only to financial contexts. Doesn’t the same principle apply to building habits? Or becoming an expert at anything? Deliberately show up, practice a bit for sufficiently long, and inevitably you will be an expert.

Patterns are applicable only to a specific context. A context is defined by the problem and related constraints. Books on patterns often follow a specific format. Apart from problem and context, they also call out forces and resulting context to outline various granular requirements for a solution and the end state. A pattern is not of much use if we cannot internalize and identify the context in real world. Correlating a pattern with similar problems (we may have seen in the past) does help in building this ability.

Take the façade pattern for example. It allows us to encapsulate the details of a component behind a well defined contract (or API), suitable for one or more use cases. When to apply? Communication across bounded contexts, microservices, external contracts and systems with independent axis of growth. This pattern is necessary to keep systems decoupled and thus evolve independently. At the same time, apply this pattern too much, e.g. at each internal layer will lead to unnecessary bloat that is hard to refactor or extend.

It is essential to learn both principles and patterns. Or, to pick them up from our day to day interactions. The hard part is to build the distinction. Is that observation a principle or a pattern?

Principles are a compass. A few of them are truly universal, and bunch of them are entirely personal. They are handful in number. Nevertheless, they help design a course of action and save the day from chaos or confusion. It is worth mentioning that universal principles are eternal and thus are only discovered by us.

“Curious indeed how these things happen. The wand chooses the wizard, remember…“

  • J.K. Rowling, Harry Potter and the Sorcerer’s Stone

It is debatable if we discover the principle, or principle reveals itself.

Patterns are good solutions. I correlate learning patterns with the younger days of solving mathematics problems. The more problems you solve, the more patterns you observe and note. More patterns you have in your repertoire, the higher is your problem solving ability. Second, patterns are the accumulated knowledge from the past. Learn history in order to not repeat them.

Why limit ourselves to only learning history from our craft? Learn from the related fields e.g. architecture; and evaluate if they apply to us.

A common error is to treat a pattern as a principle. E.g. learn the sidecar pattern, and then start designing the core domain capabilities as a sidecar ;) This is equivalent to the hammer and nail cognitive bias. Please be careful. Second, personal principles are a function of wisdom. We grow wise over time, and thus some principles in that scope are subject to change. At times, we have to embrace an open mindset to call our previous self wrong.

Both principles and patterns give us a powerful vocabulary to exchange our ideas and explain the world. Such distinction is a crucial element in our personal latticework of mental models. All it requires is a little more awareness of our self, the world and their intersection.