Being Experimental

Experimentation is defined as “a procedure carried out to support, refute, or validate a hypothesis. Experiments provide insight into cause-and-effect by demonstrating what outcome occurs when a particular factor is manipulated.” 1

Taking an experimental approach to solving problems is profoundly important. I would argue that science, and the experimental practice at its heart, is what differentiates our modern, high-tech society from the agrarian societies that preceded us, more than anything else. Human beings have existed as a distinct species for hundreds of thousands of years, and yet the rate of progress that we have made in the last 300 or 400 years since Newton or Galileo, periods that most people would mark as the beginning of modern science, has outstripped everything that went before by many orders of magnitude. There are estimates that the whole of human knowledge doubles every 13 months in our civilization. 2

In large part this is because of the application of humanity’s best problem-solving technique.

Most software development, though, does not really work this way. Most software development is consciously carried out as an exercise in craft where someone guesses what users may like. They guess about a design and/or technology that could achieve their product goals. Developers then guess about whether the code that they write does what they mean it to, and they guess about whether there are any bugs in it. Many organizations guess about whether their software is useful or made more money than it cost to build it.

We can do better. We can use guesses where they are appropriate, but then we can design experiments to test the guesses.

  1. Source: Wikipedia, https://en.wikipedia.org/wiki/Experiment

  2. Buckminster Fuller created the knowledge doubling curve: https://bit.ly/2WiyUbE .

This sounds slow, expensive, and complex, but it is not. This is really only a shift in approach and mindset. This is not about “working harder”; this is about “working smarter.” The teams that I have seen that have worked this way and taken these ideas to heart are not slow or overly academic. They are, though, more disciplined in the way that they approach problem-solving, and as a result, they find better, cheaper solutions to problems more quickly and produce software with greater quality that pleases their users more.

What Does “Being Experimental” Mean?

One of the key ideas that is at the root of scientific thinking is to move away from decisions made by authority. Richard Feynman, as ever, has a great quote on this topic:

Science is the belief in the ignorance of experts.

He also said:

Have no respect whatsoever for authority; forget who said it and instead look what he starts with, where he ends up, and ask yourself, ‘Is it reasonable?’

Despite the somewhat sexist language of his time, the sentiment is correct.

We must move away from making decisions based on what the most important, charismatic, or famous people say, even if it is Richard Feynman, and instead make decisions and choices based on evidence.

This is a big change for our industry and not how it usually works. Sadly, this is also true of society at large, not just software development, so if we are to succeed as engineers, we must do better than society at large.

What made you pick the programming language that you use or the framework or the editor in which you write your code? Do you have conversations in which you argue about the relative merits of Java versus Python? Do you think everyone who uses VI as their editor is smart or a fool? Do you think that functional programming is the one true way, or do you believe that object orientation is the best thing ever invented? Yes, me too!

I am not proposing for every such decision that we should create an exhaustive, controlled experiment, but we should stop having religious wars about these things.

If we want to make the argument that Clojure is better than C#, why not do a little trial and measure the stability and throughput of the result? At least then we could decide on some basis of evidence, even if not perfect, rather than make decisions like this on the basis of who was most persuasive in the argument. If you disagree with the results, do a better experiment and show your reasoning.

Being experimental does not mean basing every decision on hard physics. All sciences are based on experiment, but the degree of control varies. In engineering, experimentation remains at its heart, but is a pragmatic, practical form of experimentation.

Four characteristics define “being experimental” as an approach:

  • Feedback : We need to take feedback seriously, and we need to understand how we will collect results that will provide us with a clear signal and deliver them efficiently back to the point at which we are thinking. We need to close the loop.

  • Hypothesis : We need to have an idea in mind that we are aiming to evaluate. We are not wandering around willy-nilly, randomly collecting data. That is not good enough.

  • Measurement : We need a clear idea of how we will evaluate the predictions that we are testing in our hypothesis. What does “success” or “failure” mean in this context?

  • Control the variables : We need to eliminate as many variables as we can so that we can understand the signals that our experiment is sending to us.

Feedback

It is important, from an engineering perspective, to recognize the effect that speeding the efficiency and quality of feedback can give.

The Need for Speed

I once worked at a company that produced complex, financial trading software. The developers were very good, and the company successful, but still they knew that they could do better, and my job was to help to improve their software development practices.

When I joined, they had adopted a reasonably effective approach to automated testing. They had lots of tests. They operated an overnight build, and the bulk of their offering consisted of a large C++ build, which took nine-and-a-half hours to complete, including running all the tests. So they ran the build every night.

One of the developers told me that in the three years that they had been working this way, there had been only three occasions when all the tests passed.

So, each morning they would pick the modules where all the tests had passed and release those, while holding back modules that had produced a test failure.

This was fine, as long as one of the passing modules didn’t rely on changes in one of the failing modules, and sometimes they did.

There were lots of things that I wanted to change, but as a first step, we worked to improve the efficiency of the feedback, with no other changes.

After a lot of experimentation and hard work, we managed to get a fast-stage, commit build to run in 12 minutes and the rest of the tests to run in 40 minutes. This was doing the same work as the nine-and-a-half-hour build, only faster! There were no other changes in organization, process, or tooling, beyond speeding up the build and getting the results more efficiently to developers.

In the first two-week period following the release of this change, there were two builds where all tests passed. In the two weeks after that, and for as long as I worked there, there was at least one build per day where all tests passed and all the code was releasable.

Making no other change than improving the speed of the feedback gave the teams the tools that they needed to fix the underlying instability.

The “war story” in the box “The Need for Speed” is a good demonstration of the effectiveness of applying the techniques of experimentation to our work, as well as optimizing for good feedback. In this case, we experimented to improve the efficiency and quality of the feedback to developers. During the course of this work we established better measures of build performance, controlled the variables with improved version control and infrastructure as code, and A/B tested several different technical solutions and build systems.

It was only through taking a fairly disciplined approach to applying this kind of experimental thinking to this problem—a problem that various attempts had tried to improve on before—that we were able to make progress. Several of our ideas didn’t pan out. Our experiments showed us that it was no good investing lots of time and effort on certain tools or techniques, because they wouldn’t give us the speedups that we needed.

Hypothesis

When talking about science and engineering, people often talk about “eliminating guesswork.” I am guilty of using that phrase in the past, too. It is wrong, though. In one important sense, science is built on guesswork; it is just that a scientific approach to problem-solving institutionalizes the guesswork and calls it a hypothesis . As Richard Feynman so eloquently put it in his wonderful lecture on the scientific method 3 :

We look for a new law by the following process, first we guess it!

Guesses or hypotheses are the starting point. The difference between science and engineering, compared with other less effective approaches, is that the others stop there.

To be scientific, once we have a guess, in the form of a hypothesis, we start making some predictions, and then we can try to find ways to check those predictions.

  1. Nobel Prize–winning physicist Richard Feynman on the scientific method: https://bit.ly/2RiEivq

Feynman goes on, in that great presentation, to say this:

If your guess disagrees with experiment, then it (your guess) is wrong!

That is the heart of it! That is where we need to get to in order to be able to claim that what we do is engineering rather than guesswork.

We need to be able to test our hypotheses. Our tests can take a variety of forms. We can observe reality (production), or we can carry out some more controlled experiment, perhaps in the form of an automated test of some kind.

We can focus on getting good feedback from production to inform our learning, or we can try our ideas in more controlled circumstances.

Organizing our thinking, and our work, to proceed as a series of experiments to validate our hypotheses is an important improvement in the quality of our work.

Measurement

Whether we are collecting data to interpret from reality (production) or carrying out a more controlled experiment, we need to take measurement seriously. We need to think about what the data that we collect means and be critical of it.

It is too easy to fool ourselves by trying to “fit the facts to the data.” We can achieve some level of protection from such mistakes by thinking carefully, as part of the design of our experiment, what measurements we think will make sense. We need to make a prediction, based on our hypothesis, and then figure out how we can measure the results of our prediction.

I can think of lots of examples of measuring the wrong things. At one of my clients, they decided that they could improve the quality of their code by increasing the level of test coverage. So, they began a project to institute the measurement, collected the data, and adopted a policy to encourage improved test coverage. They set a target of “80 percent test coverage.” Then they used that measurement to incentivize their development teams, bonuses were tied to hitting targets in test coverage.

Guess what? They achieved their goal!

Some time later, they analyzed the tests that they had and found that more than 25 percent of their tests had no assertions in them at all. So they had paid people on development teams, via their bonuses, to write tests that tested nothing at all.

In this case, a much better measure would have been stability. What this organization really wanted was not more tests but better quality code, so measuring that more directly worked better.

This difficulty in measuring the wrong things does not only apply to “metrics” and human beings’ cleverness at gaming the system.

I spent more than ten years of my career working in low-latency finance systems. When we started out, we were very focused on measuring latency and throughput, so we worked hard to capture measurements, setting ourselves targets like “The system should be able to process 100,000 messages per second with no more than 2ms latency.” Our first attempts were based on averages, which we later found out were meaningless. We needed to be more specific; there were times in the subsequent trading cycle when our peak load far exceeded the equivalent rate of 100,000 msg/sec, peaking in numbers that were equivalent to millions of msg/sec. Average latency didn’t matter if there were outliers beyond certain limits. In the real world of high-frequency trading, 2ms wasn’t an average—that was the limit!

In this second example, we started out being experimental, but, in part due to the accuracy of our measurement, even though we were measuring some of the wrong things, we quickly started to learn and improve the quality and accuracy of our measurements and to better target our experiments. It’s all about learning!

Not everyone cares to this degree of precision in measurement, but the principles remain the same, whatever kind of software you are building. Being experimental demands that we pay more attention to the measurement of our system, whatever that means in our context.

Controlling the Variables

To gather feedback and make useful measurements, we need to control the variables, as far as we practically can. When Jez Humble and I wrote our book Continuous Delivery , we subtitled it Reliable Software Releases Through Build, Test, and Deployment Automation . I don’t think that I thought of it like this at the time, but what this is really saying is “control the variables to make your releases reliable.”

Version control allows us to be more precise about the changes that we release into production. Automated testing allows us to be more precise about the behavior, speed, robustness, and general quality of the software that we produce. Deployment automation and ideas like infrastructure as code allow us to be more precise about the environments in which our software operates.

All these techniques allow us to be much more sure that when we put our software into production, it will do what we intend.

My take on continuous delivery as a generalized approach to software development is that it allows us to proceed with much more surety. It eliminates, to a large extent, the variables around the quality of our work so that we can concentrate on whether our product ideas are good. We can get a much clearer picture of “are we building the right things” because we have taken control of “are we building the things right.”

By controlling many of the technical variables in software development, continuous delivery allows us to make progress with significantly more confidence than before. This allows software development teams to take real advantage of the techniques of optimizing for learning that are at the heart of this book.

For example, a continuous delivery deployment pipeline is an ideal experimental platform for learning about the changes that we want to make to our production systems.

Working so that our software is always in a releasable state, the idea at the heart of CD is an idea that maximizes the feedback that we can get on the quality of our work and one that strongly encourages us to work in smaller steps. This, in turn, means that we are pretty much forced to work iteratively and incrementally.

Having software that is always in a releasable state, well, it would be foolish of us not to take advantage of that! It means that organizations can release more frequently and gather a lot more feedback, a lot sooner, on the quality of their ideas and build better products.

Automated Testing as Experiments

Experiments can take many forms, but in software we have an enormous advantage over every other discipline in that we have this fantastic experimental platform: a computer!

We can run literally millions of experiments every second if we want. These experiments too, may take a variety of different forms; we can think of the compilation step as a form of experiment: “I predict that my code will compile without any warnings” or “I predict that none of my UI code accesses a database library.” By far the most flexible form of experiment, though, in the context of software, is an automated test.

Any automated test to validate our software could be considered an experiment if you try hard enough. However, if you write your automated tests after you have written the code, the value of the experiment is reduced. An experiment should be based on some kind of hypothesis, and deciding if your code works or not is a pretty lame hypothesis.

What I am thinking of is organizing our development around a series of iterative experiments that make tiny predictions about the expected behavior of our code, and that will allow us to incrementally increase the function of our software.

The clearest form of such an experiment is software development guided by tests, or test-driven development (TDD).

TDD is an effective strategy where we use tests as executable specifications for the behavior of our system. Precisely defining the change in behavior that we are aiming to achieve is our hypothesis: “given this specific context, when this thing happens, then we expect this outcome.” We create this prediction, in the form of a small, simple test, and then confirm that the predictions of our test case were met when we complete the code and carry out the experiment.

We can operate this TDD approach at different levels of granularity. We can begin by creating user-centered specifications, using the techniques of acceptance test–driven development (ATDD), sometimes also referred to as behavior-driven development (BDD). We use these high-level executable specifications to guide the more fine-grained, more technical unit testing.

Software developed using these techniques has significantly and measurably fewer bugs than software developed more conventionally. 4

This is a welcome improvement in quality, but we don’t really see the value until we also factor in the impact that such reductions have on productivity. Presumably, as a result of this reduction in defects, development teams spend significantly less time on other activities, such as bug detection, triage, and analysis.

The result is that high-performing teams that employ techniques like TDD, continuous integration, and continuous delivery spend 44 percent more time on useful work. 5 These teams are much more productive than the norm while, at the same time, producing a higher-quality outcome. You can have your cake and eat it!

The practices of extreme programming in the context of continuous delivery, specifically continuous integration and TDD, provide a wonderful, scalable, experimental platform in which we can evaluate and refine our ideas in design and implementation. These techniques have an important, significant impact on the quality of our work and the rate at which we can produce good software. These are the kinds of outcomes that in other disciplines we would ascribe to engineering.

Putting the Experimental Results of Testing into Context

Forgive me for being a little philosophical for a moment, but then I expect you are getting used to that by now.

Let’s think about what a body of tests, like those I just described, really means.

I am making a claim for scientific rationality as a guiding principle of the approach that I am attempting to describe here. A common mistake of software developers, and maybe people in general, is that as soon as we mention “science” we almost always think “physics.”

I am an amateur physics nerd. I love physics and the mental models it allows me to construct to understand the things around me. I sometimes joke about physics being the one true science, but I don’t mean it.

Science is much broader than only physics, but outside the realms of the simplified abstractions that we use at the heart of physics, other sciences are often messier and less precise. That does not diminish the value of scientific-style reasoning. Biology, chemistry, psychology, and sociology are all sciences, too. They don’t make predictions with the same accuracy as physics because they can’t control the variables quite as rigorously in experiment, but they still provide deeper insight and better results than the alternatives. I am not for a moment expecting us to be as thorough or as precise as physics.

  1. There are several studies, academic and informal, on the impact of TDD on defect reduction. Most studies agree that defect reduction is in a range from 40 percent to well over 250 percent. Source: https://bit.ly/2LFixzS , https://bit.ly/2LDh3q3 , https://bit.ly/3MurTgF

  2. Source: “State of DevOps” reports (various years) and Accelerate: The science of Lean and DevOps by Fosgren, Humble, and Kim. See https://amzn.to/369r73m .

Nevertheless, in software we have some profound advantages over nearly every other form of engineering, and several of the sciences, where experiments are often difficult for ethical or practical reasons. We can completely create and control the “universe” that our software inhabits. We can exercise delicate, precise control if we choose to do so. We can create millions of experiments, at low cost, allowing us to use the power of statistics to our advantage. Simplistically, this is what modern machine learning really is.

Computers give us the opportunity to take control of our software and carry out experiments on it at scales that would be unimaginable in any other context.

Finally, there is one more, quite profound ability that software gives to us.

So we aren’t going to be physicists, but let’s imagine for a moment that we are. If you and I come up with a new idea in physics, how do we know if it is a good one? Well, we need to be sufficiently well read to understand that it fits with the facts as physics currently understands them. It is no good suggesting that “Einstein was wrong” if we don’t know what Einstein said. Physics is a vast subject, so however well read we are, we will need to get the idea clearly enough described that it is reproducible by others so that they can test it, too. If any test of the idea fails, after checking that it wasn’t a mistake in the testing, we can reject the idea.

In software, we can do all of that with our tests, and instead of it taking months or years for our ideas to bear fruit, we can get results in minutes. This is our super-power!

If we think of our software existing in a tiny universe that we create, however big or complex the software, then we can control that universe precisely and evaluate our software’s role in it. If we work to be able to “control the variables” to the extent that we can reliably and repeatably re-create that universe—infrastructure as code as a part of a continuous delivery deployment pipeline, for example—then we have a good starting point for our experiments.

The full set of all the tests that we have written, including the collection of experiments asserting our understanding of the behavior of our system in that controlled universe, is our body of knowledge of the system.

We can give the definition of the “universe” and the “body of knowledge” to anyone, and they can confirm that they are, as a whole, internally consistent—the tests all pass.

If we want to “create new knowledge” in the system, we can create a new experiment, a test, that defines the new knowledge that we expect to observe, and then we can add that knowledge in the form of working code that meets the needs of the experiment. If the new ideas are not consistent with previous ideas, meaning the “body of knowledge” in our mini, controlled universe, then experiments will fail, and we will know that this idea is wrong, or at least inconsistent with the recorded statement of the knowledge in the system.

Now, I recognize that this is a somewhat idealistic representation of a software system and its associated tests, but I have worked on several systems that got very close to this ideal. However, even if you got only 80 percent of the way there, think of what this means. You have an indication, within minutes, of the validity and consistency of your ideas, system-wide.

As I said earlier, this is our super-power. This is what we can do with software if we treat it as an engineering process, rather than one based on craft alone.

Scope of an Experiment

Experiments come in all sizes. We can do something tiny, almost trivial, or we can do something big and complicated. Sometimes we need both of these things, but the idea of “working in a series of experiments” sounds daunting to some people.

Let me describe one common type of experiment that I regularly perform in my own software development to put your mind to rest.

When practicing TDD, I begin an intended change to my code with a test. The aim is to create a failing test. We want to run the test and see it fail to check that the test is actually testing something. So I begin by writing the test. Once I have the test as I want it, I will predict the exact error message that I expect the test to fail with: “I expect this test to fail with a message saying ‘expected x but was 0’” or something similar. This is an experiment; this is a tiny application of the scientific method.

  • I thought about and characterized the problem: “I have decided on the behavior that I want of my system and captured it as a test case.”

  • I formed a hypothesis: “I expect my test to fail!”

  • I made a prediction: “When it fails, it will fail with this error message….”

  • I carried out my experiment: “I ran the test.”

This is a tiny change from how I worked before, but it has had a significant, positive impact on the quality of my work.

Applying a more disciplined, experimental approach to our work need not be complex or onerous. If we are to become software engineers, we need to adopt disciplines like this and apply them consistently to our work.

Summary

A key attribute of working in a more experimental way is the degree to which we exert control over the variables involved. Part of the definition of “experimentation” at the start of this chapter is “demonstrating what happens when a particular factor is manipulated.” To work more experimentally, we need our approach to our work to be a little more controlled. We’d like the results of our “experiments” to be reliable. In the technical context of the systems that we build, working experimentally and taking control of what variables that we can, through effective automated testing and continuous delivery techniques like infrastructure as code, make our experiments more reliable and repeatable. More profoundly, though, they also make our software more deterministic, and so higher quality, more predictable, and reliable in use.

Any software engineering approach worth its name must result in better software for the same amount of work. Organizing our work as a sequence of many small, usually simple, experiments does this.