A lot of great things have been said already.
A bit of context from my point of view
Just to shed some light on the “green” thing in code, most of the environmental impact comes the user side (as opposed to data centers and networks). What does cause that impact? Basically, it’s the manufacturing of our devices: when you get a new smartphone, before even unwrapping it, it has had 80% of the footprint it’ll have on environment during its whole lifetime. So our main purpose when we want to do “green software” would be to make sure we won’t be the cause of users replacing their devices (most devices are replaced while they still work, because “they lag,” or because of marketing, but that’s another issue).
Making our code clean/efficient/whatever is good, but it’s the last resort, actually. The first and foremost is at design: do I truly need this feature, is this an adapted architecture, do I need a Google-like infrastructure with 99.99% availability for a service that will be used twice a year? Basically, be frugal when designing the solution, functionally and technically. That’s about 60% of what you can do. The 25 next % go to hosting (green, mutualized, etc.) and only 15% remain for code. That doesn’t mean we shouldn’t take care of that, just that raising awareness goes way beyond some good practices.
I also prefer to speak about Sustainable IT rather than green coding, because “green” makes us think primarily about the eco-friendly aspects. Sustainable is also about people: can everyone use the service I’m creating? Spoiler: no. Many developers/service producers forget about accessibility, so handicapped people won’t be their customers, and even without this, there is still an important part of the world population who doesn’t have access to digital technologies or are not at ease with it (yes, I’m sure it’s true in your country too, just check if there are national stats).
Some resources
I wrote a series of post about sustainable IT on my blog. It’s a bit outdated and I’d like to rewrite it in a more digestible style, but it can give you some food for thoughts to begin with.
Also, GR491 by Institute of Sustainable IT gives a lot of pointers (like, a lot a lot, about 500 best practices for IT projects). It’s generic and inspired by experiences in web development, but they’re open to suggestions.
I won’t go into a list right here, but there are many other great resources and this short selection is totally arbitrary.
To build on what was said
Making more efficient code to make greener code
Yes, green and performance often go hand in hand, but not always (one obvious example is that a well-designed, horizontally scalable solution will obviously be faster/stronger, but probably not greener since it will run on more machines).
Most often, “sustainable” a balance to find: what’s my requirement (functional and non functional: acceptable performances, availability and so on), and what’s the best way to achieve it with the minimal footprint? In other words, what’s the solution with the smallest footprint to provide the service I need to provide, and not more?
So yeah, this sobriety/frugality can seem to be something from another age, but it’s actually a concern for those interested in Sustainable IT. (When presenting green coding/ecodesign/sustainable IT to colleagues a few years back, a common response from the most experienced ones was “so what, we should be careful just like we used to when we were using Cobol and counting CPU cycles?” Yep, you should. “RAM is cheap, let’s buy some” is the response from someone who doesn’t know anything about the green topics or who’s just plainly lazy.
Slower hardware for better code
About hardware: I concur that we developer tend to forget that we often have powerful machines because we need a lot of resources (to compile, virtualize, start a whole ecosystem and what-nots). Using older computer would be costly for those who pay and frustrating for those who code (experienced it first hand).
My approach is that we should test in realistic conditions, and a second device, dedicated to test, might be a good thing. There was a time when Google asked to test Android on gen-2 devices, which would help developers not falling into the “well, we got lots of resources and our software can bloat it like perfect gases” trap.
Yes, that’s an investment on devices, and yes, that’s some more pollution through their fabrication, but if this helps keeping user devices longer, then the balance is positive. That’s assuming developers test their productions, but we all do, right?
As a way to conclude this already-too-long post
To my mind, one key factor to implement a greener or more sustainable IT is awareness. Not only of developers/technical leads, but also of deciders. We already hear too often to slow down on quality because we think we’re saving money (yes, I’m sure everyone here knows we’re contracting some technical debt that we’ll pay with interests down the road).
Same thing goes for tests, documentation, security: too expensive, too unpleasant for devs… Green/sustainable is just another concern to people who are not convinced of its need. It’s the job of those of us who are to share it. (Yup, you guessed it, I’m one of those.)
Thanks to those of you who took the time to read this.
Note: This post reflect my own mind, not some universal truth.