How to write bug free code

Let’s get serious, our lives depend on it!
Reading Time: 5 min

This is the intro to a WIP series of articles about software development and how to write bug free code. I already know that it is completely impossible and anyone who says otherwise is totally clueless. I accept the challenge 🙂.

The biggest question mark is if I can make sense to you, dear reader. Everyone will read and filter my words through a unique set of personal experiences, assumptions, opinions. Even the definitions of the words will be different.

I have tried to keep it general which unfortunately mean that it might generate more questions than answers, luckily there is a comment section for that!

Here is the lineup so far:

This is how it looks at the moment, things will surely change the deeper I get into the topic. This is the first time I try to get these thoughts in writing and I will probably not get it right the first or second time. Your feedback will be of immense help in clarifying my ideas.

So without further ado, here is an introduction to the topic.

Hello World!

If debugging is the process of removing software bugs, then programming must be the process of putting them in — Edsger Dijkstra

Writing code beyond “Hello world!” soon becomes pretty complex. It takes years to leave the junior level, maybe not by title but by level of proficiency.

Bugs are seen as an unavoidable part of software. Surely the numbers of generated bugs falls with seniority. And there seems to be some unicorns out there that have proved that it is possible to get close to zero.

But totally bug free code, is that even possible? Most will answer this with an empathic NO, and call anyone who says otherwise clueless.

The thing is: I don’t think we have a choice.

A digital reality

Would you upload your mind to a computer running Windows XP SP2?

Digital has become such a big part of our lives that we don’t even think about it, like air. It is only when it doesn’t work we notice. And the consequences when it breaks are getting bigger and more systemic for each year.

I have covered this and some future scenarios in an earlier article. Spoiler alert: it is pretty serious (not the article, the consequences).Digital “things” are not built to lastWill we lose our minds in the Cloud?

The bottom line:

Digital is inherently fragile. Digital things break
if they are not constantly maintained.

This is a fact that no one talks about. One could wonder why…

Fragility as a business model

When a car manufacturer sells a car the last thing they want is a customer expecting maintenance during the years covered by the guarantee. They lose money on maintenance. The space industry has even stronger incentives, buggy soft- and hardware make them lose astronauts!

We in the software industry on the other hand can sign maintenance agreements and actually earn money when things break, sometimes more than the cost for the initial production.

For consultancies there are no incentives whatsoever to create software that requires a minimum of maintenance. There are not even any incentives to simplify the development process, if everyone agrees that digital is complicated shit and are prepared to pay for it, why change a winning concept?

For companies developing their own digital products and services there should be incentives, but since it is “impossible” and whoever says otherwise is “clueless”, you would have to be a fool to question consensus 😜.

In any case, the result is that we don’t talk about it, we don’t even think about it. And while we are busy patching our digital reality we are sleepwalking into a world where fragility is built into the very foundation that our modern life is built on.

So maybe we should give it a try, waddaya say?

So what is a bug?

Unless you suffer from Entomophobia bugs sound kind of cute and just a tiny bit annoying, no big deal, like Wikipedia’s definition of a software bug:

A software bug is an error, flaw, failure or fault in a computer program or system that causes it to produce an incorrect or unexpected result, or to behave in unintended ways

Sounds like a typo, something easily fixed. In reality there are an infinite number of ways that the code can generate “incorrect”, “unexpected”, “unintended” results on a larger scale.

The code itself can run perfectly but if it doesn’t do what it is supposed to do, then it is pretty useless. Like an app that takes ages to start, or drains the battery in minutes, or is easily hackable.

So it is not only about writing code that behaves, it should also perform in all other aspects. Bug free code in its widest sense.

Chrome broke the Internet again!

How to approach an impossible task

So this is where we start. Everyone says it is impossible and there are no signs that points in a different direction. Digital things are just getting more and more complex and the number of bugs is an exponential function of complexity (or so it seems). The digital evolution has just started accelerating and will continue to do so. I can go on and on.

It seems like an impossible task, but one we just need to figure out!

Impossible problems have an almost irresistible attraction to me. The complexity is almost infinite so in order to untangle the problem we need to start in the right end. By solving the challenges in the right order other problems will dissolve, and we will get closer and closer to the core.

Starting from…

Maybe you think writing bug free code starts with the code? Ha! Far from it.

Obviously the code cannot contain bugs (duh!), but there are much more fundamental challenges that need to be addressed first. So we will start from the bottom and create a rock solid foundation on which it is possible to build equally robust, i.e. bug free, applications.

And there is no cheating, if the foundation is shaky then good luck with all the rest. So let’s jump into the basics in Part II: It’s the principles stupid!


Do what I mean, not what I say!

Leadership through mind reading — a practical guide

Escape Dependency Hell!!

How to write bug free code Part III

Code is for humans, computers don’t care

How to write bug free code part IV

Join the Dinahmoe Newsletter

Every sometimes we post about what we have been up to, about new projects, articles and products.

We will never flood your inbox, most likely the opposite (?). But it’ll be fun, we promise!

We use MailerLite as our marketing automation platform.By clicking below to submit this form, you acknowledge that
the information you provide will be transferred to MailerLite for processing in accordance with their Privacy Policy and Terms of Service.