│

Exploring Quality, Complexity, and Creation

Category: Systems Architecture

  • What Strong Towns, Moses, and Software Architecture Have in Common

    What Strong Towns, Moses, and Software Architecture Have in Common

    I recently finished reading Escaping the Housing Trap by Charles Marohn Jr. and Daniel Herriges. One idea, in particular, stayed with me long after I closed the book. In Chapter 3, the authors examine J.C. Nichols’ postwar philosophy of “Planning for Permanence,” a vision of creating neighborhoods that would remain permanently stable through careful, master-planned design rather than the organic evolution that had shaped cities for generations. Their critique of that philosophy sparked a realization that ultimately led me far beyond urban planning.

    Marohn and Herriges argue that this vision misunderstood the nature of cities. The issue is not planning itself. Every healthy community requires planning. The problem is assuming that we can predict enough about the future to permanently determine the form a community should take. Roads, utilities, zoning, and development become organized around a vision that may or may not correspond to the reality that eventually unfolds.

    Strong Towns is a movement founded by Charles Marohn Jr. that challenges many assumptions of modern urban planning. At its core, it argues that cities are not machines that can be designed into their final form but complex systems that must continually adapt and evolve. Rather than attempting to build the ideal city all at once, Strong Towns encourages communities to grow incrementally. Small investments are made, their results are observed, and each successful step creates opportunities for the next one. The city is not treated as something that can be completely designed in advance but as something that continually adapts to reality.

    Healthy complex systems cannot be permanently designed because they are continually discovering new information about reality. That realization extends far beyond cities. As I reflected on it, the idea began to feel strangely familiar. I had encountered this pattern before, although not in urban planning. The more I thought about it, the more I realized I had seen it in several completely different disciplines. Each discipline described the same organizational principle while using an entirely different vocabulary. What surprised me most was not that they shared similarities, but that they all seemed to arrive at the same conclusion independently.

    An Ancient Pattern

    One of the earliest examples appears in Exodus. After leading Israel out of Egypt, Moses became responsible for judging every dispute among the people. At first this may have seemed manageable, but as the nation grew it became impossible. Everyone depended upon one man to resolve every significant question. The larger Israel became, the more the entire system depended upon Moses’s ability to make every important decision.

    Jethro immediately recognized the problem. His solution was not to replace Moses or eliminate hierarchy. Instead, he distributed responsibility among leaders of thousands, hundreds, fifties, and tens. Ordinary matters remained close to the people who understood them best, while only the difficult cases moved upward. Moses remained the leader of Israel, but his responsibility fundamentally changed. Rather than personally carrying every burden, he became responsible for integrating the work of many smaller leaders.

    What has always fascinated me about this story is that authority did not disappear. Moses still led the nation. The hierarchy remained intact. The difference was that responsibility was moved closer to the people who possessed the knowledge needed to exercise it well. The higher levels of the system did not become less important, but their role shifted from doing the work themselves to coordinating the work of others.

    The same organizational pattern appears centuries later in the idea of federalism. The word federal comes from the Latin foedus, meaning covenant or compact. Independent communities joined together because there were responsibilities they could fulfill more effectively together than separately. The federal government existed to coordinate the states, not to replace them. Each level possessed responsibilities appropriate to its role, and the health of the nation depended upon each level fulfilling those responsibilities well.

    Catholic social teaching expresses this same principle through subsidiarity. Decisions should remain with the lowest level capable of making them effectively. Families should remain responsible for what families can accomplish. Local communities should remain responsible for what local communities can accomplish. Higher levels certainly have responsibilities of their own, but those responsibilities are not to absorb the work of smaller communities. Their role is to support them, coordinate them, and provide what they cannot provide for themselves.

    At the time, I did not have language for what connected these examples. I only knew they all seemed to preserve responsibility at the lower levels while allowing higher levels to create something greater through integration. Whether I was reading about ancient Israel, constitutional government, or Catholic social teaching, the same pattern kept reappearing. That made me wonder whether this was more than a historical coincidence. Perhaps healthy complex systems naturally organize themselves this way because reality itself favors this pattern.

    Software Rediscovers the Same Idea

    The final place I encountered this pattern was the one most familiar to me. Long before I read Strong Towns or spent much time thinking about federalism and subsidiarity, I had spent years trying to solve the same problem in software engineering.

    When I first began developing software, many applications were designed around a large central application layer that understood almost everything. Business rules, persistence, communication, and user interactions often became tightly coupled because it seemed easier to keep the logic in one place. As systems grew, however, every new feature required modifying the same increasingly complex components. Those components eventually became bottlenecks. They possessed too much responsibility because they attempted to understand too much about the system.

    The industry gradually moved in a different direction. Rather than concentrating responsibility into larger and larger components, software architects began dividing systems into smaller modules with clearly defined responsibilities. Each component became responsible for a narrow part of the system while providing well-defined capabilities to the components above it. Larger applications were no longer constructed by continually expanding a central application layer. They were assembled by composing many smaller pieces that could each evolve independently.

    This shift became even more apparent with Agile development. Agile is often described as a project management methodology, but I have come to think of it differently. At its heart, Agile recognizes that knowledge is distributed throughout a system. Product owners learn from customers. Developers learn from implementation. Testers discover assumptions that everyone else overlooked. Operations teams learn how software behaves under real workloads. Instead of assuming that one group can predict everything in advance, Agile allows each part of the organization to contribute what it uniquely learns through direct contact with reality.

    The same principle appears in software architecture through Inversion of Control. Although the term is usually associated with dependency injection or application frameworks, I think its deeper significance is often overlooked. Inversion of Control is really about allowing each component to remain responsible for the knowledge it already possesses. Repositories understand persistence. Services understand business rules. APIs understand communication with external systems. User interfaces understand how people interact with the application. Each layer consumes capabilities provided by the layers beneath it while providing new capabilities to the layers above it. The architecture becomes simpler because responsibility remains where the knowledge already exists.

    One Pattern, Many Disciplines

    As I reflected on these examples, I realized they all shared something even deeper. Every level within these systems both consumes and provides. A neighborhood depends upon its residents while providing economic activity to the city. States depend upon their citizens while providing stability to the federal union. Leaders of tens provide judgment to leaders of fifties. Software services depend upon lower-level components while providing capabilities to APIs and user interfaces. Every part receives something from below while contributing something of value to what comes next.

    Years later, while writing Striving for Quality, I finally realized what connected these examples. I came to call it the Consumer–Provider Paradigm. Every healthy complex system is composed of modules that consume value from the systems beneath them while providing value to the systems above them. Higher levels become valuable not because they replace lower levels, but because they integrate their provision into something greater. Likewise, lower levels are not isolated. Their work becomes meaningful because it contributes to the flourishing of the larger system.

    Looking back, I no longer see Strong Towns, the Hebrew Republic, federalism, subsidiarity, and software architecture as unrelated discoveries. They are different windows into the same structure of reality. Urban planners discovered one aspect of the pattern. Political philosophers described another. Catholic social teaching explained another. Software engineers solved the same problem while building applications. None of these disciplines invented the principle. Each simply encountered reality honestly enough to discover it.

    That realization has profoundly changed the way I think about quality. Healthy systems certainly require leadership, vision, and coordination, but they do not flourish because higher levels continually absorb more responsibility. They flourish because every level faithfully fulfills the responsibility that belongs to it while providing something of value to the systems around it. Leadership does not replace provision. It integrates it.

    This has become one of the central ideas explored throughout Striving for Quality. Again and again, disciplines that appear completely unrelated arrive at remarkably similar conclusions because they are all studying the same reality. Engineering, theology, economics, history, and political philosophy each illuminate different aspects of the same underlying order. The names differ. The examples differ. The language differs. Yet the pattern remains remarkably consistent.

    The more I study healthy complex systems, the more convinced I become that they are not primarily built through control. They grow through provision, responsibility, and integration. Every healthy part consumes from what supports it and provides to what depends upon it. When each level faithfully fulfills its own responsibility instead of attempting to assume the responsibilities of another, the entire system becomes capable of growing into something greater than any individual part could accomplish alone.

    That, I believe, is where responsibility belongs.

  • AI Is Shifting Software from Measurement to Quality

    AI Is Shifting Software from Measurement to Quality

    For decades, software engineering has been built on a simple assumption: the same input should produce the same output.

    That assumption shaped everything. It shaped how we wrote code, how we designed systems, and especially how we tested them. If a function returned something different for the same input, we called it a bug. Determinism became the foundation of trust.

    And it made sense. Traditional software deals almost entirely in quantitative data. Numbers, booleans, exact strings. Things that can be measured, compared, and asserted.

    Then AI showed up.

    AI does not operate the same way. It does not produce purely quantitative outputs. It produces language, images, and ideas. It produces things that must be interpreted. And interpretation introduces variability.

    You can give the same prompt to an AI system multiple times and receive different responses. Not random responses, but different expressions of something that may still be correct. The output is no longer a fixed object. It is a qualitative result.

    We Are Trying to Force AI Into the Old Model

    The industry’s first instinct has been to resist this. We try to force AI back into the old model. We want it to behave like traditional software. We tweak prompts, lower temperature settings, and build layers of control in an attempt to make the output consistent. But this misses the opportunity.

    AI is not breaking software. It is exposing a limitation in how we have been thinking about it. We have spent years optimizing for consistency because consistency is easy to measure. But consistency is not the same thing as quality. It is just a proxy. And like all proxies, it eventually fails.

    That failure is now visible.

    Our Testing Model Was Built for Sameness

    What makes this shift uncomfortable is not just that the outputs are different. It is that our entire testing philosophy was built around sameness. Traditional systems allowed us to build automated tests that assert exact results. If X goes in, Y must come out. That was the definition of correctness.

    AI breaks that definition at the root.

    Two outputs can be different and still be good. They can even be better in different ways. That means correctness is no longer something we can fully capture with assertions.

    The Return of Human Judgment

    In the short term, this forces a return to human judgment.

    We are seeing this directly in how we operate. Our UX team is now far more involved in QA than they have ever been. They are not just validating that something works. They are judging the quality of what is being produced. They are asking whether the output is useful, clear, and aligned with intent.

    That is not something an automated test can fully assert. It requires a person.

    This is uncomfortable for an industry that has spent decades trying to remove humans from the testing process. But it reveals something important. We were not actually testing quality before. We were testing consistency.

    Can AI Test AI?

    At the same time, we are exploring how to bring AI into the testing process itself. If the system produces qualitative output, then the testing layer may also need to operate qualitatively. That means using AI to evaluate AI.

    But this introduces a real constraint. Automated testing depends on speed. AI-based evaluation is slower. It requires context, processing, and judgment. We are still working through how to balance that tradeoff.

    What is emerging is a layered approach. Fast, deterministic tests still exist where they make sense. But above them, we are introducing qualitative validation, both from humans and eventually from AI systems that can judge quality at scale.

    It is less precise, but it is more aligned with reality.

    This Is What Striving for Quality Was Pointing To

    In Striving for Quality, I argue that quality cannot be measured directly. It can only be judged. Metrics can point toward quality, but they can never fully capture it. When we rely too heavily on what can be measured, we begin optimizing for the metric instead of the thing the metric was supposed to represent.

    That is exactly what happened in software.

    We optimized for determinism because it was measurable. We built systems that could prove they were correct through repetition. But in doing so, we quietly reduced our ability to recognize actual quality.

    AI is forcing that back into the system.

    From Measurement Back to Quality

    AI is reintroducing the need for judgment. It is forcing us to evaluate outputs based on usefulness, clarity, and alignment instead of exact matches. It is moving us away from the object as the primary focus and back toward quality itself.

    This is not a step backward.

    It is a correction.

    AI did not create this problem. It exposed it.

  • Why Narrow Responsibilities Make Better AI Agents

    Why Narrow Responsibilities Make Better AI Agents

    My team has been doing a lot of agentic development at work lately. AI is an incredibly powerful tool, and when it is used well, it can significantly advance a software system. Over the past several months, we have been working to better understand agentic development and what actually makes these systems effective.

    What we have uncovered is not new. It is something that has been around for a very long time. All complex systems are built as a hierarchy of responsibilities, and AI systems are no exception.

    The Consumer–Provider Paradigm

    To understand why this matters, it helps to look at how responsibility is structured in any complex system.

    I call this the Consumer–Provider Paradigm. It is the idea that every part of a system depends on something beneath it and is responsible for providing something to what comes above it. Nothing exists on its own. Each part both receives and contributes, and the system holds together through that flow.

    As I wrote in Striving for Quality:

    “It is the idea that every part of a structure depends on certain levels beneath it and contributes something to the levels above it. Each part in a complex system is both a consumer and a provider. The levels beneath it are its dependencies, and the part itself must become a dependency for the levels above it. It consumes what it needs from lower levels, and it provides something of value to the levels that rely on it. Nothing operates on its own. This upward flow of value is what keeps the structure intact.”

    Responsibility is what defines that relationship. It determines what a module is expected to provide and sets the boundary for what it should consume. When that responsibility is clear, the module has a place in the system. When it is not, the module begins to drift.

    What Agentic Development Actually Is

    Agentic software development makes this structure visible in a way that traditional software does not.

    Instead of writing fixed sequences of logic, we create agents that are given roles and allowed to act. Each agent is defined by a system prompt, consumes context, depends on tools, and produces outputs that other parts of the system rely on. These agents are then composed together into larger systems.

    As these systems grow, they naturally form layers. Agents call tools, tools invoke other agents, and those agents depend on additional tools. What begins as a simple interaction becomes a structure of interdependent parts.

    At a technical level, this can look complex. But the underlying pattern is simple. Each agent is a module that consumes and provides.

    Why Agentic Systems Must Follow This Structure

    Because of this, agentic systems must follow the Consumer–Provider Paradigm if they are going to work well.

    An agent must depend on lower-level modules to provide what it needs, and it must provide something clear and reliable to the layers above it. Its responsibility defines both sides of that relationship. It defines what it consumes and what it produces.

    When this structure is respected, the system begins to integrate. Each agent has a defined role. Each layer contributes something specific. The system becomes easier to reason about because responsibility is distributed in a way that aligns with the structure.

    When it is not respected, the system begins to lose clarity. Agents overreach into responsibilities that belong to higher layers, or fail to carry the responsibilities that belong to them. Either way, the structure weakens, and the quality of the system declines.

    What We Are Seeing in Practice

    This is why we keep seeing the same pattern in practice.

    When an agent is given too much responsibility, the quality of its work declines. The outputs become less precise. The reasoning becomes less reliable. The system becomes harder to build on. But when the responsibility is narrowed, something changes. The outputs become clearer. The behavior stabilizes. The system begins to take on structure.

    As I wrote in Striving for Quality:

    “When responsibility is taken seriously, systems grow in strength, resilience, and clarity. When responsibility is neglected, they slide into disorder or stagnation.” 

    That is exactly what we are seeing in these systems.

    Narrow, Generic, and Free

    There is a natural instinct to solve this by expanding the agent. We give it more context, more tools, broader instructions, hoping that increased capability will produce better results. In practice, the opposite happens. The agent becomes less predictable because its responsibility is no longer defined with enough clarity to guide its behavior.

    We see this even in the practical limits of these systems. As the number of tools available to an agent grows, its effectiveness tends to decline. It has more options, but less clarity. The additional capability does not improve the outcome. It introduces confusion.

    What also works is more discipline.

    The agent must be given a responsibility that is narrow enough to be clear, but still generic enough to apply across many situations. If it is too narrow, it becomes brittle and cannot adapt. If it is too broad, it becomes unfocused and loses coherence. The quality of the system depends on holding that line.

    This is where freedom becomes necessary. An agent with a well-defined responsibility must be allowed to fulfill it. If it is overly constrained, it cannot adapt. If it is given freedom without a clear boundary, it becomes chaotic. The system stabilizes only when both are present.

    What This Reveals

    What becomes clear through this work is something that is easy to overlook when building software. Quality does not come from expanding what a module can do. It comes from defining what it is responsible for and allowing it to fulfill that responsibility well. Agentic systems do not introduce a new way of building. They reveal the structure we were always depending on.

    I am very proud of the work my team has done to get to this point. They have been working hard over the past several months, not just building these systems, but learning through them. The challenges have been real, and so has the effort. But through that work, we have gained a much clearer understanding of what makes agentic systems effective.

    What we have learned did not come from theory alone. It came from building, from struggling, and from paying attention to what actually works. And in that process, we have not just built better systems. We have come to better understand the structure that makes them possible.

  • Tyranny in Software Code

    Tyranny in Software Code

    Proper software development is complex. Some software engineers are creating complex systems without un

    Proper software development is complex. Some software engineers are creating complex systems without understanding the abstract hierarchy of dependencies between different pieces of software code. This can create what is known in complex social systems as tyranny.

    Tyranny in Complex Systems

    When people hear the word tyranny, they think of corrupt oppressive government rule. Particularly government actors that force arbitrary choices upon individual citizens. These choices, or actions, that are forced upon the individual might be arbitrary to the individual, but perceived to makes sense to the higher system domain (the government).

    An obvious example of tyranny is slavery. Governments or powerful citizens forcing back breaking labor upon a subset of individuals in society. Individual freedom, which is important and the lower level of dependencies within the social complex system, is abandoned or ignored by the government for perceived efficiency in the production of material goods or services.

    These systems that force higher level concepts onto lower level dependencies become fragile over time. Southern American states that relied on slavery for many decades are still recovering from the fragile state that the tyranny of slavery caused. Slavery weakened or destroyed individual growth and motivation. It violates the rules of tribalism which is vital for social cohesion. All of this leads to a fragile complex system.

    Tyranny is forcing concepts or actions at the wrong hierarchy of dependencies in a complex system.

    However, social systems that do not force concepts or actions at the wrong hierarchy of dependencies will be robust over time and will have higher probabilities of flourishing in harder times. The federal system is a great example of a social hierarchy of dependencies that has been robust over the years.

    Software Tyranny

    So if tyranny is forcing concepts or actions at the wrong hierarchy of dependencies, how does this relate to software code?

    Below I will provide an example of software code tyranny.

    Example Software System Overview

    The system is an article system, like Medium, that provides the ability for consumers to create articles and share them.

    The Problem

    We needed to enhance the system to use a caching system when users outside of the system read the articles, since there are way more users reading articles then editing. But we can’t use the caching system when users are editing the article since we want the current data available as quickly as possible.

    The Solution

    The article rendering system needs to use a separate cache system for retrieving the data needed to render the article.

    The system at the highest level knows about “editing” and “viewing” when a request comes in to render the article via a query parameter. If it is in an editor, the URL will look like this:https://articleservice.com/article?editMode=true.

    Below is the server code:

    const express = require('express')
    const app = express()
    const articleStorage = require('articleStorage');
    const renderEngine = require('articleRenderingEngine');
    
    app.get('/:articleId', (req, res) => {
      //get article data from storage
      let articleData = await articleStorage.getArticle(req.articleId);
    
      //convert the article data into HTML for rendering 
      let html = await renderEngine.renderArticle(articleData);
    
      //send the HTML back to the browser
      res.send(html);
    })
    

    This is the code of the server for rendering the article. It fetches the data from storage, converts the data to HTML and then sends it back to the browser for rendering.

    Solution by Tyranny

    Now we have our app, we need to update it to use the cache system. Below I will show you how to use tyranny to update the system to do what needs to be done.

    app.get('/:articleId', (req, res) => {
      //get article data from storage
      let articleData = await articleStorage.getArticle(req.articleId, req.params);
    

    We pass in the params from the request to the ArticleStorage (the ?editMode=true that was discussed above).

    Now we will update the dependency code to fetch the article data from the cache system when we are rendering for view mode vs edit mode:

    const cacheSystem = require(‘cacheSystem’);
    const databaseSystem = require(‘databaseSystem’);
    
    export class ArticleStorage {
      async getArticle(articleId, options){
        let articleData;
        
        if(options.editMode !== "true"){
          articleData = await cacheSystem.getCacheForArticleId(articleId);
        }else{
          articleData = await databaseSystem.getArticleByID(articleId);
        }
    
        return articleData
      }
    }

    Can you spot where the tyranny is happening? It’s the if statement

    if(options.editMode !== "true"){
    

    This is a concept (edit mode) that is being forced at the wrong dependency hierarchy. In Domain-Driven Design, the ArticleStorage is in a different domain and the concept of whether to use the cache system should not be coupled to the concept of “editMode”.

    “EditMode” is a higher level concept that does not make sense at the storage level code in the system.

    The High Quality Systems Solution

    The proper solution will look pretty similar, but will have a major impact for the future of the system.

    Since the ArticleStorage is in a different domain, the concept needs to be translated.

    export class ArticleStorage {
      async getArticle(articleId, options){
        let articleData;
        
        if(options.useCacheSystem == true){
          articleData = await cacheSystem.getCacheForArticleId(articleId);
        }else{
          articleData = await databaseSystem.getArticleByID(articleId);
        }

    The ArticleStorage should have an option to useCacheSystem . Now reading the ArticleStorage makes more sense.

    The article rendering route should translate the concept of “editMode=true” to “useCacheSystem=true”

    ...
    app.get('/:articleId', (req, res) => {
      //create article options
      let articleStorageOptions = {
        useCacheSystem: (req.params?.editMode == "true")
      };
    
      //get article data from storage
      let articleData = await articleStorage.getArticle(req.articleId, articleStorageOptions);
    ...

    Now we have a solution that does not force concepts at the wrong hierarchy of dependency.

    A Bright Future

    The pragmatist will argue that our argument above adds additional code that one will have to support in the future, which will make the future worse for maintaining and enhancing the application.

    However, forcing concepts like this in the wrong abstraction layer will only cause issues in the future. What if we want to use the ArticleStorage to retrieve article data for a different part of the system that doesn’t have the concept of “edit mode”? That other part of the system will have to have to translate what “editMode” means, which will add confusion when supporting the code at a later time. Where as the domain translation we introduced is logical and readable, which is more maintainable.

    This form of tyranny limits optionality in the future. It also limits the freedom of responsibility that dependencies need in order to create high quality systems (more on both of these points in future articles).

    Overview

    Tyranny is forcing concepts or actions at the wrong hierarchy of dependencies in a complex system. We have seen this over and over again in complex social systems, but this also takes place in complex software systems. Tyranny should be avoided in any system if that system is to endure the test of time.

  • Consumer Provider Conflict – Problem Solving In A Fractal System

    Consumer Provider Conflict – Problem Solving In A Fractal System

    Ever had a sales person sell a feature that your product didn’t have? Unfortunately this has happened to me many times throughout my software engineering career. If you have experienced this, you have experienced a conflict that is happening throughout your entire system: the Consumer Provider Conflict.

    Software Systems as Fractal Systems

    First I need to show that a quality software system is fractal in design. Software systems are usually hierarchical: higher level “consumers” solving problems using lower level “providers”. In that system hierarchy, a fractal pattern of property/method shows up.

    Starting at the top, the system solves specific problems. For example, a save button for your text document editor will convert your domain specific data into a markup format and save the data to disk. This is a very specific problem that has many steps.

    At the lower end, code is created to solve general problems. From the example above, there would be a piece of code in your system that would save a string to a file by path. This low lever algorithm is a general purpose piece of code that would be used in many other places in your code.

    Code solving specific to general problems in a fractal system.

    General/Specific Problem Solving Paradox

    The example above was only describing 2 dimensions, but we all know that software systems have many levels. This fact helps illustrate an interesting paradox:

    No matter where you lookin in a system’s hierarchy, higher level code is solving specific problems while lower lever code is solving general problems.

    This means that if you move your focus up, the code you were looking at before which looked like was solving specific problems now looks to be solving general problems. That lower level code that saves a string to a file, its using even lower level code that deals with byte management on disk, which makes the code that saves the string to a file look like its solving a specific problem.

    Throw a dart anywhere in the hierarchy and the code above looks to be solving specific problems while the code below looks to be solving general problems. If you move down the hierarchy and look up, the nodes that you saw to be solving general problems now look to be solving specific problems.

    But what’s even more interesting is that no matter where you are looking within the system hierarchy, there is a dynamic happening: there is an inherit conflict in problem solving between the higher level code and the lower level code.

    Problem Solving Conflict

    There is an inherit conflict within a fractal system such as the one described above:

    Higher level entities (consumers) will want lower level entities (providers) to solve specific problems, while lower level entities will want higher level entities to solve general problems.

    Back to our sales/engineering example: the sales person is at a higher level in the business. They are working with potential clients and helping them solve their specific issues. Engineers are at a lower level in the business, creating product that can solve many problems. The conflict comes when the sales person, rightfully representing their client, will champion their specific solutions while the engineer will reflect and push for the sales to adjust their solutions to use already created features.

    In code, the tendency is for lower lever code to sway towards solving specific problems, thus making them less reusable. The conflict usually shows itself over time and due to the fact that one person (a software developer) is writing the code at every level of the system. The software developer is thinking like the sales person: we need to solve a specific problem.

    Coding From The Bottom Up

    The first principles I teach junior developers is Inversion of Control (IoC). If you are not familiar with IoC, you can read a great tutorial at TutorialsTeacher.

    The specific part of IoC that I teach is to write code from the bottom up, not top down. This forces the developer to think about solving the lower level general problem solving code first, then work their way up to solving the specific problem that they have set out to solve.

    Then next principal I teach is the Single Responsibility Principle. For junior developers, I’ll make then summarize the class and method. If the word “and” is in the description, then the code needs to be split up. This helps the developer think in creating code that solves general problems.

    Unintended Consequences

    There is one big issue with creating systems in the way described above: general problem solving never solves 100% of the potential problems. It’s more like 80%. Because nodes within a fractal system solves 80% of potential problems, then we get Pareto Principle effects at the system level. Issues like “20% of the code has 80% of the errors” or “80% of a certain piece of software can be written in 20% of the total allocated time.” Wikipedia.

    Even though these are unwanted potential issues with a complex system, I believe currently there is no better way to build a complex system that is extensible and maintainable.

    Overview

    Within a fractal system, there is an inherited conflict between higher and lower level nodes: higher level nodes wants lower level nodes to solve specific problems and the lower level nodes want higher level nodes to solve general problems. This conflict is central to a developers growth in creating modular code that is of high quality.

  • Fractal Dependency Segregation – Creating Clean Code

    Fractal Dependency Segregation – Creating Clean Code

    Spaghetti code is something that all developers know is bad. They have an idea on how not to create it, but inevitably do. It’s like the governments definition of obscenity: you know it when you see it.

    There are some good patterns and practices to help prevent spaghetti code, but I’m still itching to have a good definition of what spaghetti code is.  I’d like to show one way of understanding what makes spaghetti code by looking at software systems as fractal systems that contains layers of code.

    Layers of Code

    Most places that I’ve worked at as a developer have their code organized in a similar way. Most places have heard or used the Repository pattern. DOTNET shops have plenty of experience creating “client” code for communicating to SOAP or WebAPI endpoints. UI projects all now have “controllers” or “view models”.

    These “types” of classes/code are different fractal layers within a system.  What I mean by fractal is that they look and act very similar but are at different levels in the system.

    Dependency Segregation

    Here is a simple example of types of classes that would be in a UI application (web or native) (dots representing classes):

    Class Layers

    Each level is a fractal layer: the classes look and act very similar, but each layer is a hierarchical level in the fractal system.  Views use Controllers, Controllers use Services, Services use Clients, etc…

    Class Layers Call Stack

    Each hierarchical layer uses as a dependency a class from the lower fractal level.  The call stack starts to look like a tree, or root depending on how you view it.  Nature’s best pattern at work!

    Spaghetti Code

    Spaghetti code is code that has references or makes calls to the same or above levels within the fractal system.

    SpaghettiIn this outline, the call stack looks more like a snake than a tree.

    Your code must fork, not snake!

    This creates many problems, one being the high change of circular references. The other issue is that this will highly limit optionality on future enhancements or bug fixes. We can’t make changes to one controller without it affecting another controller without our knowledge.

    Cross Same Level Communication

    There will be many times that one will need to communicate across the same level classes within a system, and there are some great patterns for this: Pub/Sub and the Observer Pattern are a couple.

    The two patterns have their differences, but the idea is the same. It provides a way for classes within the same fractal level to communicate via sending events.  This keeps all the classes highly decoupled and provides a way to not violate the fractal dependency segregation due to having a central messenger or event bus at a separate fractal level.

    However, one can still violate the fractal dependency segregation if they were to publish events from one fractal level and read it in another.  Events need to be kept within the same hierarchical level.

    Events need to be kept within the same hierarchical level.

    Overview

    The fractal dependency segregation description above is a simple way of viewing the hierarchy of your code to help prevent spaghetti code.  Spaghetti code is a call stack that is calling entities at the same or above level within the fractal system hierarchy. Communication between same level entities should use patterns such as Pub/Sub or the Observer Pattern.

  • AngularJs 1.x and the Lindy Effect

    AngularJs 1.x and the Lindy Effect

    A couple years ago I had to agonize over which version of Angular to use for my front end development of a brand new project: AngularJs with all my currently built up knowledge, or the new framework that’s the future.

    In deciding which technology to use in a project, we definitely need to be thinking of the future. However, is there a way to gage a technology’s longevity?

    The Lindy Effect

    In judging a longevity of an idea or non-parishable thing, there’s a concept called the Lindy effect that states:

    The future life expectancy of some non-perishable things like a technology or an idea is proportional to their current age, so that every additional period of survival implies a longer remaining life expectancy.

    AngularJs Probabilistic Future

    AngularJs was initially released October 20, 2010; 7 years ago.  According to the Lindy Effect, it should a valid technology for another 7 years.  That’s a long time in technology years.  If you’re taking into account how long a technology is going to survive when choosing a technology for a project, then AngularJs looks pretty promising compared to the newer Angular Framework.

    The Decision

    Full disclosure: I love AngularJs 1.x!  Another disclosure: I really love the new Angular framework as well.  This concept of longevity was taken into account when I decided which framework to pick, but the decision was pretty easy since the new Angular Framework was still in Beta.  I wasn’t going to start a new project with a beta technology.

    giphy

    Overview

    You can judge the probabilist longevity of a technology using the Lindy effect that states the life expectancy of a technology is proportional to its current age.  AngularJs has been around for a while and most likely will be around for just as long.

  • Optionality and Reusable Coding

    Optionality and Reusable Coding

    All developers have been told to write reusable code. I remember having that drilled into my head in college by my professors daily. The main reason we have to write reusable code: so we don’t have to write the same code twice. That is a perfectly valid reason and I can’t argue with that. But, what if there’s a bigger reason.

    Optionality and Reusable Code

    Optionality, a concept that Nassim Taleb has brought to us in his books Antifragile, is the ability to have many options at every layer of the system that lets us prepare for volatility, giving yourself the chance to not only withstand it but to succeed and prosper in a big way.

    Reusable coding should increase the number of options on how to use the code.

    Within software, one way of reaching optionality is to write your code, at every layer, to be reusable. Reusable coding should increase the number of options on how to use the code without breaking the Single Responsibility Principle. Let me show you with an example.

    Reusable Refactoring Example

    Couple developers on my team submitted a pull request for a rather large feature. In the code was a class who’s purpose was to convert identifiers from one value from the next using a array of old and new values.

    var ids = [
     { old: "162735", new: "8493273" },
     { old: "736482", new: "7427364" }
    ];
    
    class DeckIdConverter {
      convertDeckIds(ids, data){
        var jdata = JSON.stringify(data);
        ids.forEach( id => {
          jdata = data.replace(id.old, id.new);
        });
        return JSON.parse(jdata);
    }
    }
    

    Yes, this is reusable code. We can instantiate it and reuse it many places and not have to copy/paste code. However, within the context of Optionality, this isn’t very reusable: it doesn’t give us very many options on how to use it.

    When I saw this code, I asked the developers how we could make this more reusable. It’d be nice to use this code to swap out identifiers with other entities.

    They began to brainstorm on a more generic EntityIdConverter. However, one of them had a brilliant idea: It’s really just a simple multiple string replace, lets create a String extension called “replaceMany”.

    giphy

    Ten minutes later they changed the code to this:

    String.prototype.replaceMany = function(stringMaps) {
      var s = this;
      stringMaps.forEach((map) => {
        s = s.replace(new RegExp(map.source, 'g'), map.destination);
      });
      return s;
    }
    
    var ids = [
      { source: "162735", destination: "8493273" },
      { source: "736482", destination: "7427364" }
    ];
    
    var jdata = JSON.stringify(data);
    jdata.replaceMany(ids);
    

    This code is way more reusable and can be used with any entity or within any domain. This will allow for code that is more readable and maintainable.

    Overview

    To avoid volatility in a system, one should apply optionality at every level to give oneself as many options as possible to avoid or withstand large catastrophes. To do this in software, developers should write reusable code that will provide the highest number of options for reuse.

  • Open/Closed and Expected Outcomes

    Open/Closed and Expected Outcomes

    When I’m trying to be a good developer and apply SOLID principles to my coding practice, I usually get a little frustrated with applying something so abstract.  One issue that has frustrated me a lot is with the Open/Closed principle: when to say that a piece of code/entity is now closed to change.

    After many years of frustration and yelling “Come on!” to my monitor, my thinking about this principle has changed:

    An entity should be closed to changing already established expected outcomes.

    If some other piece of code or system is using your code that you wanna change, you cannot change anything that the calling piece of code/system is expecting.

    A very simple example is a webapi: if a webapi has a “name” property and some other client is using your webapi and is expecting there to be a “name” property in the return data, you can’t change the “name” property to “title”: you’re breaking expectations.  All hell would break loose!

    Limit expectations of the code/software entity as much as possible.

    So what helps me be a more proactive lazy developer is to try to limit expectations of the code/software entity as much as possible.  This has not only helped me with creating easier maintainable and extensible code, but it has also helped me with testing.

    Breaking Tests

    With this view of Open/Closed, I now have a different view of mocking dependencies: they add more expectations!

    I’ve been doing way more integration testing than unit testing.  Ya, I know, but hear me out.  The big reason I’ve been focused more on integration testing is to limit this issue of tests adding more expectations to my code entities.

    Webapi’s are the easiest thing to create integration tests for: create a seed database, have the test runner spin up the webapi service, and the tests make requests to the webapi’s.  Just assert expectations of the results of the request.  I have little mocking involved, only for mocking communication to other systems. This allows us to “change” webapis easily.  What I mean by “change,” is the ability to add additional functionality without worry of breaking old tests.

    If we need to change expectations of a webapi route, we simple create a new version of it.  I usually have v1,v2, etc. in the base of the route, but I digress.

    Lately we’ve been creating more asynchronous job workflows, which require a lot of processing and file I/O.  Full integration tests for these would take forever, so we need to do more unit testing for these.  This adds more expectations to the code which makes our unit tests more brittle: if I add another piece to the workflow later, all my other tests break because they didn’t know about any added dependencies.  Not I have to go back and add mock dependencies to old tests, which should never happen.

    Right now my answer for this is to create a new version of the workflow and start adding new tests to it, along with duplicating old tests for the original version.

    Extend or replace code/software entities if about to break expectations, even for mock dependencies.

    The benefit of a new version is that I’m not getting confused if the broken tests are tell me that expectations have been broken or the tests itself is broken.

    Overview

    Limiting expectations of a software entity will help you be able to easily extend it later. Mock dependencies within tests create additional expectations for your code so try to do more integration tests if possible to help eliminate unneeded expectations.

  • Why UI Automation Tests Are Always Breaking

    Why UI Automation Tests Are Always Breaking

    In my experience, UI tests are always very time consuming.  Every sprint a whole host of UI tests break after developers make changes needed for new features or bug fixes.

    Don’t get me wrong, I’m a big fan of automated testing!  But for my latest projects I’ve stayed a way from UI automated testing completely.  They are way too time consuming to maintain, let a lone extend.

    Below I want to propose why UI testing is a nightmare to maintain and a hypothetical solution.

    Stop Changing, Start Extending

    There’s a very important principle in software development that helps developers write code that isn’t brittle: the Open/Closed Principle.  It states:

    software entities (classes, modules, functions, etc.) should be open for extension, but closed for modification

    This simply means that a chuck of code, once deployed and in the world, should not be changed.  In order to change behavior of a chunk of code, one will need to either extend it (using object oriented concepts of inheritance/polymorphism) or replace it with a different chunk of code.

    Testing With Open/Closed Development

    The huge benefit of writing code in a open/closed way is that when one writes tests for a chunk of code, the tests won’t break later when the developer changes it’s behavior since the developer will never change the original code, but extended or replaced it.  The tests for the original code then won’t break because the original code didn’t change.  Pretty cool!

    UI Development and Open/Closed Principle

    With unit testing,  if the developers are violating the Open/Closed principle, then one will be getting a lot of broken tests to maintain.  This is exactly what is happening with UI development:

    Developers change the UI’s behavior, violating the Open/Closed Principle, and causing UI Tests to break.

    This is great, but how do we apply this principle to UI views?  Let me go through how we applied this to Web API development.

    Versioning Web APIs

    One practice that we have used to follow the Open/Closed principle with Web API development is to version them.  This allows me as a developer to extend or replace behavior without breaking integration tests.

    Here’s an example Web API route for retrieving news articles from a system:

    GET: /api/v1/articles

    The initial JSON response that was deployed to production was like this:

    [
      { name: "article name 1", author: "Author Name" },
      { name: "article name 2", author: "Author Name" }
    ]
    

    There were a bunch of integration tests written to make sure that the Web API returned the correct data in the correct format.  Later, the client wanted pagination.  So we needed to change the format to this:

    {
      results: [
         { name: "article name 1", author: "Author Name" },
         { name: "article name 2", author: "Author Name" }
      ],
      total: 32
    }
    

    Well, that would break all the tests.  To follow the Open/Closed principle (extend, don’t change), we’re lead to create a new version of the Web API:

    GET: /api/v2/articles

    The tests for the original Web API didn’t break and we could create new integration tests for the new version.  Awesome!!!  No broken tests and new functionality!  And no acid reflux as well!

    Now let’s try to apply this concept to UI view development.

    Versioning UI Views

    Let’s say we have a webpage that displays articles in a list view:

    /articles

    To help with following the Open/Closed principle with UI development, this path will need to be configured through the routing framework to go to the first version of the webpage:

    /v1/articles

    The tests should then be written against this webpage.  Thus the tests are written against a specific version of the webpage.

    Now let’s say that the client wants to change the view behavior from a list view to a grid view, thus breaking all the tests that were written for the list view version of the webpage. No problem, create a new version of the page!

    /v2/articles

    New UI Tests can then be written for the new version of the webpage and the old tests will continue to work.  Configure the routing framework to use the new version in the site.  Kaboom!!! No broken tests to maintain!

    The only problem to solve is when to retire old UI views and their tests.  But that one can do on their own time schedule, instead of racing to fit within a development cycle.

    Make It So.

    Maintaining broken tests adds so much stress and consumes so much time.  Hopefully this discussion helps shed a new light on UI testing and provides a step forward for you and your team in creating maintainable and extensible user interfaces.