Is it morally wrong to write inefficient code?
tomgamon.com
tomgamon.com
> Therefore, increasing your consumption of computing resources increases your contribution to the suffering of others.
Yes, this is technically true. I think there's an easy way to trump this:
The amount by which your extra compute cycles increase global warming is much less than both of (the opportunity cost of spending your time tweaking your code instead of some other method of fighting global warming) and (the amount that some single-digit percentage of your salary could contribute to fighting global warming).
At some point, you will be punished for prioritizing performance-tuning code over producing business value. If you use your dollars to fight against global warming in some way, this is a net negative. Likewise, if you do this off the clock, I believe there are other volunteer actions you could take that would decrease carbon emissions more than spending that time optimizing code.
It's very difficult to compare these kinds of things, so common practice is to assign dollar values to things that are infungible. Perhaps the author needs to advocate for higher costs of carbon emissions rather than try to argue about the morality of such an abstract thing.
There are exceptions. There is a reason why people spend years staring at micro-benchmarks of sort to save one cycle: they can save tons of CO2 every years. However for most of us sort is just a function in our library and we shouldn't think about it. Your typical programmer thinking about sort will waste far more CO2 due to a worse algorithm than someone else already put into the standard library.
Writing quickly a very inefficient code that will run a handful of time is much better than spending 2 months full time optimizing it. And straightforward codes are also easier to debug. It may be a concept quite linked to Python, be premature optimization is where the crux of the problem is. Except we are now talking about an optimisation in processing power with an impact that is much wider, and thus with a more complex link.
In the real world O(n) is faster than O(log n) on all real data. (that is data that fits in RAM)
I can only assume you have 4KB of ram.
Nearly all of this would be solved by incorporating quantified externalities into energy costs, but that's a tricky sticky wicket.
If it works, and everyone likes it, it isn't inefficient code. You just applied the best of time, resources and delivered what the end customer wanted.
--
What about something more dicey, like the incarceration of humans, or even eventually deciding which ones deserve more treatment, or not? Or regarding insurance policies that are dependent on legal geographic location of the customer and risk mitigation policy of the ORG that hired you to conserve overall lifetime cost per customer?
What I think you could say is that writing inefficient code when it would be exactly as easy to write efficient code is immoral, assuming you derive no other benefit from the code being inefficient, and assuming you believe that global warming is likely to increase net suffering, and assuming your moral system values net suffering. But even then it's very marginal unless your code is being run on hecka computers.
But then one needs to consider whether being alive is indeed a net positive (as opposed to just selfish self preservation). Then the question becomes much deeper in terms not only of whether writing code is efficient, but also a question of life choices in general, with regards to the utility the individual brings to the world as well as whether said utility advances moral goals (as opposed to e.g. growing a human economy in some unsustainable way).
Going down the rabbit hole really illustrates the hypocrisy of this line of reasoning: what of the immorality of some small task when one can be judgmental of virtually everything in the same way to such an extent that civilized society as a whole might be considered immoral if put under the same level of scrutiny.
The breadth of amazing and terrible things that this statement can apply to makes it all a bit meaningless.
For people who are created product for an end user, being far off from optimal efficiency is very excusable. You have deadlines to hit, you can't afford to iterate forever on the thing, users won't like that either, their want their stuff.
But as your software moves further down the stack to being a more fundamental tool: a library, a compiler, and operating system, a database, things that other software will depend on, those things I think deserve way more attention on performance. And of course they generally DO get way more attention. There are some glaring exceptions though, such as the huge degree of inefficiency that popular, interpreted (or badly jitted) languages have. None of that is strictly necessary. Languages could exist with the same productivity as those (maybe more!) with good runtime performance. Another example would be our industry's dependence on using a web browser to build multi-platform guis. We could fix that, and create more efficient, easier to use things. The effort level is very high but the payoff very big.
I think looking for those popular, inefficient, software building blocks, and improving them, or replacing them, is the fastest way towards positive change.
Another easy leverage point we have is to quit discouraging curious programmers from thinking about performance. I see it all the time here, on reddit, on stack overflow. Using the Knuth quote to discourage performance investigation and curiosity. Let people learn! The cost of writing fast code goes down with practice.
Moreover, the storage requirements continue to increase as I save more personal videos, photos, and other media content and save them to the cloud. This then produces even more data centres situated along dams, causing more local area flooding and environmental damages.
Of course, we know there's no right answer to all of this. My demanding of these products and services also help hundreds of thousands (if not millions as we work up the supply chain) as it employs them in the overall IT industry. The money they get is used to pay for bills, save for children's college funds, and more.
If we look at the scope of the argument within itself, it is possible that inefficient code is morally wrong. Weighing it against the factors that gave rise to that code (ie. real world), it is a byproduct of society's demand on technology -- of which one could argue there are many more morally questionable cogs in the machine.
Now, there are benefits to code being more efficient, and computers being more energy efficient, but I don't think computation time on personal computers is a substantial contributor to household energy use, nor a relatively easy/kwh to reduce contributor to it.
And even then, I wouldn't be surprised if "getting people to power off their pcs when not using them" could have more of a contribution than "making the programs they use run faster".
That being said, striving for excellence is a virtue, and I think wanting one's code to be efficient is good on those grounds.
Philippians 4:8, NIV: "Finally, brothers and sisters, whatever is true, whatever is noble, whatever is right, whatever is pure, whatever is lovely, whatever is admirable--if anything is excellent or praiseworthy--think about such things."
Efficient code is more admirable and praiseworthy than inefficient code, for the most part, I think.
Regarding getting people to power off their PCs, the PC itself may do a pretty good job of that on its own. It goes into a low power state whenever possible, and depending on your power management settings, may also put itself on standby after some idle time.
The energy usage for ads and tracking are unimaginable.
If the only factor in the energy consumption of a program was the efficiency of the code, then maybe. But different languages have different development and maintenance costs as well (both in terms of human and computer time). Different design decisions as well.
Hand-tuned assembler with mostly static bounds on memory consumption could lead to much more efficient executables (in terms of raw cycles). And compilation would be a relatively simple translation step, much faster than compiling every other language. But at a severe cost of often non-reusable code (so more time is spent writing the same things over and over), more time debugging the code (unless you're really good at assembly or working on small programs).
At a minimum we could consider a "simpler" (by various measures) language like Pascal or C where it's relatively straightforward to reuse code, and compilation isn't as time consuming and can be fairly well optimized. But then we have to remember, there are reasons other languages are made. Usually having to do with programming ergonomics for particular problem domains. Then you build your Datalog or SQL interpreter on top of one of these languages and we're back to something "inefficient" (not fully optimized).
And on this goes. We could ask much better questions like: Is most code worth writing/running? Should we have several of the biggest tech companies in the US be, fundamentally, advertising companies? They produce and promote much more energy waste with their software than any programmer's inefficient code is going to produce.
this statement is a true fact in and of itself: i suffer get physical pain every time i come in contact with shitty software. no need for logical mental gymnastics or global warming shenanigans.
edit: for the sake of correctness, i'd rephrase the statement above:
>shitty software increases your contribution to the suffering of others
Last night watching the election, CNN.com just sitting open in my browser was using 60% of my CPU. I tweeted about it asking if CNN was mining bitcoin. Surely that alone had a non-negligible effect on global warming.
In all seriousness. Everything you do have an impact on global warming.
But optimizing code for the sake of reducing emissions is ridiculous. There are other things you can do in your life to reduce emissions. Using led lights or dialing up your AC a couple of degrees during summer probably offsets all my bad code.
"...for all have sinned and fall short of the glory of God ..."
One is not justified by one's works.
_____
But as to your overall point, I agree.
Only then does this question becomes relevant. Of the programs that are necessary, they should of course be written as efficiently as possible. The work to write it efficiently is fairly trivial compared to deciding what programs are necessary.
The only effective way to stop climate change is a very aggressive global carbon tax. And good luck with that.
/s
Assuming a fixed amount of data being processed. You can easily imagine that a more effective algorithm X might increase the amount of data for which it makes economic sense to process with X.
If you spend too much time optimizing something that will not be used much, you lose the opportunity to automate something else and make a greater difference overall.
That's like forcing someone to sign a contract (possibly without reading it.)
if you want to consider the environment in your engineering decisions, that's fine, just bring it up front and put it in there with the NRE vs operational costs, etc.
probably more cost effective to just do whatever engineering you were going to do anyways and then send the money that it would cost to write "efficient" code to some tree planting charity.
they'd get the money up front, and you could start profiting X months sooner.
Someone has to change Trump's face for Guido van Rossum's.