Hacker News new | past | comments | ask | show | jobs | submit login
[flagged] Is it morally wrong to write inefficient code? (tomgamon.com)
26 points by headalgorithm on Nov 4, 2020 | hide | past | favorite | 46 comments



In my opinion, this is ridiculous. The failure of this argument is here:

> 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.


Dont forget there is a presumed value in writing the code in the first place. Sometimes having inefficient code is better than having no 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.


Yes, and, sometimes code does not make the world a better place, or makes the world less better than those other things one could be doing to save the world that the GP alludes to.


You have to put this into perspective. I am working on an MMO gane and not only can good code half the server amount but just as well the internet traffic, which in turn reduces mobil traffic consumption on the mobile device. Just like the optimized client (game) saves power on the mobile device. And if you scale this to thousands of servers and millions of players, I am sure it time invested is well worth it.


Yes, but if it's worthwhile, people will already do it for other reasons, like the ones you listed (decreased cooling costs, decreased server costs, decreased bandwidth costs)


Even worse, most programs are not run very often. The CO2 you spend working on making it more efficient (all the test runs) is more than the total CO2 you save in many cases. Thus making your first working draft of code (working meaning bug free enough for your purposes) uses less CO2 over the lifetime of your code than you would spend working on making it faster

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.


Code is not the only element in the process generating GHG. The coder's way of life, the coder's tool, the resources needed should all be taken into account. What matters in the end is the global footprint of the code.

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 case of C++ it is often noted by library writers that simple implementations often beat their most complex efforts in the real world: between the compiler optimizing better, and simple algorithms leading to less CPU stalls because of a cache miss

In the real world O(n) is faster than O(log n) on all real data. (that is data that fits in RAM)


I would encourage you to benchmark linear search and binary search on a dynamic array (std::vector) of a million elements. You may be in for a surprise.

I can only assume you have 4KB of ram.


What about all the ways that code has helped reduce suffering of others? If writing less efficient code allows people to iterate faster and improve lives then wouldn't it be morally wrong to spend years trying to write perfectly optimal code instead of solving imminent problems today?


Yeah the article is extremely one-sided and seems to assume zero cost for efficient code and creates false dichotomies along the axes of morality and efficiency.

Nearly all of this would be solved by incorporating quantified externalities into energy costs, but that's a tricky sticky wicket.


Sometimes you just write inefficient code because you don't know better, or because to improve efficiency you need to use a new workflow or framework which won't exactly pull or revolutionize what you're fixing/doing.

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?


Breathing also produces greenhouse gasses. :( Considering only the costs without the benefits is not a workable approach to moral analysis.

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.


> Breathing also produces greenhouse gasses. :( Considering only the costs without the benefits is not a workable approach to moral analysis

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.


> 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

The breadth of amazing and terrible things that this statement can apply to makes it all a bit meaningless.


I think about this question a lot, less because of wasting energy though, and more because of wasting user's time, or battery life, or even wasting your own profits should your product start getting more load than you anticipated!

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.


Interesting philosophical question. The blog post got me thinking as well. If by extension developers aim to please by releasing features as fast as I (the user) wants them, is the act of requesting feature a morally wrong? Therefore, my demanding the company (who puts pressure on the developers to churn out code) would therefore be in direct conflict with protecting the environment, as I am then the driving force behind this evil behaviour.

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.


I'm rather unsure of premise 5. If the program takes longer to run, but the computer would still be turned on for the same amount of time, how much does that change the amount of power used? And, if the program finishes sooner, will some other program be run in its stead?

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.


Modern computers don't use a fixed amount of power. Just listen to the fans spin up to blow away heat when your laptop or desktop is running a compute-intensive program. And if it's a laptop, notice how it warms up at that time.

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.


I had the same idea; a computer that is done with the task you've given it will run some do-nothing idle code that doesn't take appreciably less power than the task you gave it. The article did mention a case where the difference would be noticeable though - if the program is running on a shared server like AWS, another useful program might take over once yours is done.


That do-nothing idle code uses much less power. Computers are always ramping their power consumption up or down depending on the task they're given.


Energy savings of being able to idle the CPU are substantial.

The energy usage for ads and tracking are unimaginable.


I'm reminded of The Good Place's Chidi. If you go down this route, you're likely to become paralyzed as you consider all the possible ways you might be harming others.

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.


>inefficient code increases your contribution to the suffering of others

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


There are a number of comments on here that assume your code isn't going to be run very much, but let's talk about the opposite.

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.


You've fallen for the rhetoric that us consumers have meaningful impact on global warming.


If that’s the case, I’m going to hell.

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.


> If that’s the case, I’m going to hell.

"...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.


By this logic it's morally wrong to write any code at all, since running any code produces greenhouse gases.


There seems to be a bigger problem lurking: surely it's better to instead write as little code as possible for only absolutely necessary programs. The program that doesn't run contributes the least amount of suffering. That of course opens up a whole can of worms of what's necessary.

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.


Sometimes inefficient code uses fewer computing resources. As long as it's inefficient enough that the user doesn't even want to run it.


This argument assumes that the demand for CPU cycles is inelastic, i.e. that more efficient code will reduce consumption rather than increase demand. History shows this not to be true. If you provide extra capacity by whatever means, code efficiency included, people will find a way to use it.

The only effective way to stop climate change is a very aggressive global carbon tax. And good luck with that.


When exactly did code go from being an art form, a way to express yourself, to a duty and then to a series of moral obligations?


I guess the natural next step is "Is it morally wrong to hire dumb people to write inefficient code?"

/s


"5. Inefficient code increases your consumption of computing resources."

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.


Premise 5 is the most uncertain for me. Inefficient code takes longer per a run, but it also imposes a time cost on running it that makes it less popular. A more efficient library induces demand. I have no idea what the balance point is.


In most cases it will be hard to calculate if the extra effort will be worth it.

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.


Ergo, is JavaScript deplorable?


No, but it's morally wrong to force people to use your code! Especially if they aren't allowed to read it.

That's like forcing someone to sign a contract (possibly without reading it.)


But exactly the same logic, running code at all is immoral. Maybe it’s ok if your code is doing sufficiently useful work though... but what about games? What about adtech?


There's only ever one answer to a headline that is a question: no.


Is there only ever one answer to a headline that is a question?


more garbage that mentions benefits while ignoring that costs even exist.

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.


https://static.independent.co.uk/s3fs-public/thumbnails/imag...

Someone has to change Trump's face for Guido van Rossum's.


no


This is so woke, I can't even...




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: