Is it morally wrong to write inefficient code?

Posted on Nov 3, 2020

Update

There was a bunch of interesting discussion about this post on Lobsters and some quite spicy discussion on Hacker News. There was also this interesting post arguing against my position. I also read this recently that suggests that the carbon footprint from sites such as Netflix is probably less than we thought.

On reflection, I still think the core idea under discussion is interesting, though I would emphasise that I am not trying to suggest that we will save the planet just by increasing code efficiency.


In this post I will explore the idea that because running code contributes to global warming, writing inefficient code is morally wrong1. I will start by outlining the argument, before working through each of the premises in turn to see how they hold up. I will then conclude that even if we cannot concretely defend every premise in this first iteration, then it is sufficiently plausible that it should at least make us pause for thought. With that said, let’s dive in!

The argument I am considering, in summary, can be presented as:

  1. Running code produces greenhouse gasses, proportional to the computing resources it requires.
  2. Greenhouse gasses contribute to global warming.
  3. Global warming increases the suffering of others.
  4. Therefore, increasing your consumption of computing resources increases your contribution to the suffering of others.
  5. Inefficient code increases your consumption of computing resources.
  6. Therefore, inefficient code increases your contribution to the suffering of others.
  7. Increasing your contribution to the suffering of others is morally wrong.
  8. Therefore, writing inefficient code is morally wrong.

I believe the argument as laid out above is valid, in that the conclusions follow from the premises, so we will focus our energies on determining if it is sound, that is all the premises are true. We will now break it down and look at each premise more carefully.

  1. Running code produces greenhouse gasses, proportional to the computing resources it requires.

The first premise is based on the fact that running code requires electricity. Electricy, in large, requires the burning of fossil fuels, which releases a number of greenhouse gasses. There are cases where this is not the case (solar energy, wind energy), and in such cases, this argument is invalid. However, if you run your code on AWS, then it is very likely that you are running on fossil fuels2. As AWS is the largest provider of cloud computing, this is likely to be true in a good number of cases.

  1. Greenhouse gasses contribute to global warming.
  2. Global warming increases the suffering of others.

With regards to the second and third premises, these are statements which are consistent with the overwhelming scientific consensus, and as such are uncontroversial. For the sake of completeness, here are some supporting statements from the 2014 climate change report summary from the Intergovernmental Panel on Climate Change, emphasis mine.

Human influence on the climate system is clear, and recent anthropogenic emissions of greenhouse gases are the highest in history. Recent climate changes have had widespread impacts on human and natural systems.

Warming of the climate system is unequivocal, and since the 1950s, many of the observed changes are unprecedented over decades to millennia. The atmosphere and ocean have warmed, the amounts of snow and ice have diminished, and sea level has risen.

Continued emission of greenhouse gases will cause further warming and long-lasting changes in all components of the climate system, increasing the likelihood of severe, pervasive and irreversible impacts for people and ecosystems. Limiting climate change would require substantial and sustained reductions in greenhouse gas emissions which, together with adaptation, can limit climate change risks.

Cumulative emissions of CO2 largely determine global mean surface warming by the late 21st century and beyond.

Climate change will amplify existing risks and create new risks for natural and human systems. Risks are unevenly distributed and are generally greater for disadvantaged people and communities in countries at all levels of development.

I believe these to be enough to support the argument that greenhouse gasses contribute to global warming, and that global warming will increase suffering of the human and other animal populations.

  1. Therefore, increasing your consiumption of computing resources increases your contribution to the suffering of others.

So here we come to our first conclusion, that increasing ones consumption of computing resources increases ones contribution to the suffering of others. It is based on at least two implicit premises. The first is that if A contributes to B, and B causes C, A contributes to C. The second is that in such a transitive relationship, if you increase your contribution to A then you increase your contribution to C. To illustrate, we can imagine a much more straightforward case. Imagine that I have a dial which, when turned, increases the voltage supplied to an electric chair. There are several such dials, and their contributions are additive. It would be fair to say that if I turned up my dial, I am contributing to the suffering of whoever is in that electric chair.

Given this assertion, it would seem reasonable that if running code produces greenhouse gasses, and greenhouse gasses contribute to global warming, then running code contributes to global warming. Global warming increases the suffering of others, so it follows that running code increases ones contribution to the suffering of others.

  1. Inefficient code increases your consumption of computing resources.

Premise five seems relatively uncontroversial, though to simplify let us just consider the length of time some piece of code takes to run (in a similar way we assess algorithmic complexity). If an efficient version runs in 1 minute, and an inefficient version runs in 1 hour, it stands to reason that the inefficient version would consume more electricity.

  1. Therefore, inefficient code increases your contribution to the suffering of others

With point six we again come to a relatively straightforward conclusion. If you agree with the earlier conclusion at point four and the premise at point five, then this falls out as a result of the logic of the statements.

  1. Increasing your contribution to the suffering of others is morally wrong.

Point seven is the real crux of the argument, and on the surface intuitively plausible. In the above example with the dial, it would generally be considered morally wrong for you to dial up the dial and increase the suffering of the individual in the chair. However, if we are merely counting contributions to suffering, this casts a wide net. Would it be morally wrong not to buy an energy efficient bulb when an energy efficient one is available at the same price? How about breathing? This expels carbon dioxide, a greenhouse gas, but would generally not be considered a morally reprehensible action.

It seems that there is some inherent provision that increasing your contribution to the suffering of others is not morally wrong if it causes equal or greater personal suffering. For example, if there was some shared well of water, it would be reasonable to claim that it is not morally wrong of you to take a sip of water in order to save yourself from dehydration, even if that means other may become more dehydrated. However, if you drained the well, and threw that water away, causing another to die to dehydration, that seems morally wrong.

I think for the purposes of this post, we can consider this sufficiently true (there is definitely some sense in which it is true), even if is vulnerable to reductio ad absurdum in it’s current form. Consider it the alpha version of the premise - solid enough to be useful, but not without it’s bugs.

  1. Therefore, writing inefficient code is morally wrong.

Here we come to the conclusion of the argument, that writing inefficient code is morally wrong, which follows from the logic set out in the conclusion at point six and the premise at point seven. So what does this mean?

As discussed, I am aware that this argument is probably not watertight, and perhaps with some more time spent on it we could tighten it up3. I think the premise at point seven could definitely be better defended, and there almost certainly some implicit premises and caveats that need to be put in place. However, I think it is reasonable enough that it should make us pause and reflect. Whilst a lot of code performance issues can be covered up with bigger and better hardware, these come at a greater cost than just an increased AWS bill. The decisions we make as developers have real world effects.

If there are ways that we can reduce ‘programming waste’ we should strive to do so, whether that is changing an algorithm to be O(1), scaling down some cloud instances or killing of that Heroku dyno that’s not really doing anything useful4. Collectively we can make a real difference.


  1. I have had this idea knocking around for a while, but reading this post motivated me to explore it further. Definitely check out the blog if you haven’t read it. ↩︎

  2. https://www.youtube.com/watch?v=N4hiqGwTRBU ↩︎

  3. Perfect is the enemy of good. ↩︎

  4. After posting this, I am going to finally kill a bot that has been producing random inspirational quotes and posting them to Twitter for the last 6 years. ↩︎