Environmental fitness

I have a theory tying all this together. I don’t believe there is some luminous ground (Christopher Alexander’s term for the inherent beauty in forms), and I don’t believe determining the quality of things is a uniquely human pastime. I firmly believe quality is relative, but relative to something we cannot help but take for granted.

I am a staunch believer in the power inherent in the evolutionary process. Emergent complexity is natural and explains many more things than we even recognise as inexplicable. I see the impact of selection on television programs, CPU design, the rise of social media, and the origin of art. It’s not surprising to me that it impacts here, too. So much is affected by the selection process that to remain uninfluenced would be unusual. The revelation is not that it is affected by selection but how it relates so deeply.

Evolved species are survival machines. To survive, they must do better than others or at least not do worse than the majority. This selection weeds out those less capable of surviving by letting them die off. Remember, it’s not survival of the fittest but eradication of the unfit, so the system maintains variety. When you have a large variety, you have to build senses to detect the best for you in nuanced ways.

To explain my theory, I need to build a picture of what happens when you have a universe of selection and variety. I wish to introduce a thought experiment involving a species that lives on berries.

At first, the species could not distinguish a good berry from a bad one until long after they had eaten. They only knew the berry’s goodness by how much energy they had the next day. The species evolved when some developed the capacity to discern berry quality by taste. The tasters quickly outnumbered their tasteless ancestors. They evolved again when some began to discern by sight. After that, those who chose by sight were quickly outnumbered by those who could remember where they last saw some good berries.

The final evolutionary step happened when some of the species had inklings about where the best bushes might be. The feeling wasn’t magic; it was a genetic tendency to look in lightly wooded areas near water. It might have been a general preference for the look of trees, the sound of water, or the feel of the air. But when hunting for new berries, those with inklings were more likely to find berries than those relying on memory and hunting without knowing where to concentrate their efforts.

This is my theory of quality. Quality is an indicator of future value. Quality is an evolved inkling, a sense that picks up environmental indicators without committing to recognising them directly. We like seeing mountains and valleys, as they could provide protection. We fear the roar of a lion. We turn up our noses at the smell of rotten meat and salivate over the aroma of baked bread. These are all reactions to a potential future. None of these are reactions to the things affecting us directly.

I want to be very clear on this point. A lion is not a threat. A lion that is hungry and aware of us and how much meat we are made of is a threat because it intends to eat, and then the future is a lion ending our lives to satisfy its needs.

Putting our hand on a hot stove is not an immediate threat. Rationally speaking, our hand burning in the fire is not affecting our genome and only concerns what our genome produces: us. But we react to the fire because genes are instructions for assembling a being that can feel pain and respond to situations where its continued existence is threatened.

The sequence of instructions in DNA drives us to ensure the safety of the instructions in the DNA. It describes a process to create an entity that can tell what is favourable for it while conserving energy. That is quality. It is our reaction to things, driven by our configuration, which is itself driven by selection, which is in turn driven by the environment.

If selection defines quality, then quality is about survival. If being able to detect what is higher quality leads to survival, then why did Christopher Alexander’s paper strip experiment lead to a strong bias towards some patterns of black and white colours looking more coherent than the others? If patterns of black and white squares on strips never turned up as a fitness test in nature, then why do I think this bias is related to evolution and our genes?

I believe the strips are a mimic, like the many non-poisonous insects wearing false black and yellow stripes. The pattern recognition built into other creatures defends these less aggressive insects. Mimics don’t have to be about stripes or even animals. Mimicry is about producing the same phenomena as another source to reproduce beneficial behaviour in the beholder. Stick insects mimic leaves, and cakes mimic fruit. See, I told you I would explain cakes.

The paper-strip pattern harmony is an accident of overlapping domains. The strips of black and white patterns were an abstraction. The arrangements don’t signify anything, but our instincts still react to them and induce a feeling. Our inkling systems respond even when what we sense is not natural. We prefer things with symmetry because, in nature, asymmetry typically indicates damage or inferiority. We can trick our senses into having feelings about things that aren’t good for us, such as sweet, salty, or oily foods.

Before, you may have complained about my statement that DNA is not beautiful or that the process of molecular recombination is not pretty. I hope I have explained why it is not an honest beauty. It exploits our senses, tuned to a different purpose.

Environmental fitness affects more than just the real world. It affects any domain where there are variations and death in any form. Some people refer to this in terms of the market deciding the price. It’s what others will be talking about when it comes to creating artwork and having to kill your darlings. If something isn’t adequate, it will either be culled or not culling it diminishes your fitness.

When we talk about environments, one particular environment comes to mind for software engineering: the codebase. Who lives in the codebase? Does the computer or the compiler live there? To know whether something lives in an environment, you must first determine whether it can die. In the case of the compiler, it’s unlikely it’s inside the code environment. It might be within the larger setting of the organisation if there were a willingness to change the programming language or vendor. But realistically, it’s more environment than inhabitant.

We can delete the source code. So, it undoubtedly lives in the environment. But as in a natural setting, code is also the environment for other code. It makes the environment inhospitable to other code. Do people inhabit this environment? Some do. Their reputation and ability to get work done relies on its structure, so their career and ability to effect change in the environment are themselves impacted by the environment.

How this helps

There’s a lot going on in this process. We need to step back a bit and ask, how does this help us understand design patterns? First, we can recognise patterns as something akin to features of an evolved species. They are documented inklings. Second, we can use fitness to define whether patterns are high quality. Third, we know we can look for patterns in any environment, which means we need to recognise which environments we’re operating in.

We can assess whether a code configuration is healthy based on its fitness with the surrounding code, business practices, and tools. We know some developers will perceive quality differently due to their wisdom about a particular configuration’s impact. This wisdom indicates how well the developer understands the environment and its complexities.

But more usefully, we can now question the quality of the outer environment. Consider outer environments as compilers and tools, the operating system, company policies, or the hiring process. Any environment influences how we measure quality, whether in the code or the developers writing and maintaining it. The fitness of an environment affects its output and the evolution rate for the entities within. So, we can judge it. Anything we can judge can be removed, so we can find patterns here as well.

An environment competes against other environments when entities can migrate between them. You can’t quickly get a drink in the desert, but you can migrate to a wetter climate. You can’t always follow best practices at one organisation, but you can find a new job. You can’t write expressive code in your current language, so instead, you can write a DSL. If you’re aware of other environments, those environments now exist in a meta-environment and begin to jostle for fitness because an environment without entities is a dead one.

Positive only

Rather than inspect all patterns, including anti-patterns, let’s concern ourselves with how to find and use the best positive patterns to write better code. Finding them will be difficult because we do not have the right instincts to tell good code when we see it. Great or perfect code can look like a mess to our eyes. We cannot gauge it because it belongs to a world with different rules of survival.

None of our existing instincts apply, as those were developed in response to the rules of physics in our three-dimensional world plus time. The world of computer software has a very different number of dimensions and a very different set of laws of physics. Therefore, when I ask you what type of feature is attractive in core code, you must rely on cultural or rational evaluations.

We want an innate inkling system for good code and bad code, but we don’t have one. We almost have the opposite. Our inkling systems were developed to appraise the physical world, not that of software design. Our instincts prefer symmetry and repetition, which do not relate to quality in code.

Programs are not buildings, art, or Turkish rugs, but something unfamiliar. Programs are more like plans, laws, or recipes. Programming languages reflect our expectations or judgements. We need to find the properties supporting our goals.

The source of beauty

Organisms evolve a sense of beauty as a mutual adaptation present in the expression of the wielder and the appraisal of the beholder to promote survival. The earliest bees had limited concern for flowers, and the flowers didn’t prioritise bees either. Over time, their appraisal and expressions co-evolved into an unbreakable bond.

Our reaction to excellent code is weak. We need to accelerate the process of recognising its beauty. What will code look like in a million years if we consistently select code that keeps us safe and productive?

Most patterns will make sure any problematic code is removed or repaired. They would suggest code forms that are easy to mend or never need maintenance. The patterns would reinforce exponential growth and force multipliers, making further development easier or helping developers decide with confidence. They can be better processes, revealing the unknowns earlier in a series of development steps.

In this way, the Agile Manifesto[AM01] looks like a hypothesis for, or a description of, software development’s laws of physics. The manifesto is not a process but presents the metrics for selecting good processes.

Beautiful code

Code is more like prose, so it is less well-defined concerning survival. We react to bad poetry, but code is more like non-fiction. Its value comes from unambiguously revealing the answer to questions. Code needs good form, but we need to evaluate it in an alien way. One way to think about code is through our closest analogy in biology.

Business logic or gameplay code follows the same formal rules of beauty as DNA, as it constructs the final form. It must be simple to safely recombine, splice, and experiment with. Changes ought to affect the final form in well-defined ways—they must be safe and cheap. Experiments must be non-destructive and isolable. Our inkling should align with enabling confident, quick changes.

The metric of quality is different for core code, framework, platform, or engine code. We may wish to follow the same beauty rules as the cell construction and replication engine driving the unfolding process. These foundational components must have robust, error-free mechanisms and be extraordinarily reliable. Experiments in business logic can only happen on top of solid foundations. We should define goodness by the certainty of behaviour. Unit tests will rule and deny damaging changes from escaping into the world. This kind of code must have proof it works as intended, meaning all code of this type must document its intention.

Beautiful processes

DNA is an environment in an environment. It is a peak fitness form for life on this planet. But that only means DNA is a good environment and was better than the rest when it first appeared. We may never know what came before DNA, but with code, we can see multiple environments, languages, and development practices. One may emerge and dominate the way DNA dominates, but it’s hard even to name a leader today.

We could consider Agile to be leading at the organisation layer right now—or at least the real-world manifestation of the term. The one put forward by those who signed the Agile Manifesto is reasonably well defined, but the diluted term is faring better.

Agile, as it is, is winning as an environment in the environment, but it lacks a definite boundary in its current form. It’s hard to say what is Agile and what is not, which is itself a self-defence mechanism. This makes it difficult to differentiate it from the competition or even identify whether there are any competitors.