Do you think about Green Code?

No, this isn’t about the code you write after celebrating St. Patricks Day :stuck_out_tongue:

Green code is a term that has emerged in recent years to discuss environmentally friendly coding practices – whether that refers to the infrastructure your code runs on, the applications you’re coding, how long your builds take to run (and how much energy they use…)

It’s an emerging topic, and something we’re looking into for our own products (we’re even seeing related community plugins pop up).

What’s your take? Can developers achieve a meaningful impact on energy consumption by being conscious about the code they’re writing? Is it just a drop in the bucket? (You can say the same thing about turning off the lights when you leave a room, but we still know we’re supposed to!)

5 Likes

No, this isn’t about the code you write after celebrating St. Patricks Day :stuck_out_tongue:
Shame :smiley:

It’s an interesting idea for sure, though I’m not sure how much impact programmers can make vs the hardware manufacturers increasing efficiency and reducing the power consumption of their hardware…

Having said that, I am old enough to remember the good old days of having to write efficient code because you only had 8k or 16k (not a typo for younger readers - K yes, not Mb :slight_smile: ) to play with so you were forced to eke every last ounce of performance out of your hardware and be as memory efficient as possible…but over time that seemed to give way to “meh, just get a bigger machine to run it on”

I guess if engineers place more emphasis on writing efficient code in general then this would in turn reduce the hardware requirements and contribute to a more environmentally friendly solution, more as a positive side-effect than an actual goal of a project.

That is a long way of wondering if we need a specific “green” code initiative at all or if we simply need more comprehensive code smell analyses to highlight more ways of writing better code.
Or, as Anna Rampton put it in W1A "The fact is this is about identifying what we do best and finding more ways of doing less of it, but better,” :slight_smile:

4 Likes

This reminds me of a project I did for school. I think it involved calculating distance between (lots and lots) of points on the outside of a torus and taking some action when they were within range of each other.

The problem was that the PC I had at home at the time was a woefully outdated, slow-as-snails, piece of poo. So every time I ran my program it took like 20min to do all the calculations.

So to save my own sanity I optimized to avoid doing the calculations for certain obviously-inelegible pairs.

On show-and-tell day, running on the school’s moderately modern classroom PC it flashed through the few calculations it had to do, to show the right outcome almost immediately, surprising both my peers and the prof IIRC.

So the obvious moral of the story here is to give devs shitty hardware. :smiley:

4 Likes

This should be a top priority for all of us. It might be a drop in the bucket if you think only about server side optimizations. Analysing front web sites or mobile apps code could have significant scaled impacts. As we know that the main weight in our environmental footprint is the production of devices, reducing their use and their energy consumption should reduce their production.
You guys have a great tool and great teams to work on it, so please be there!

3 Likes

Green code for the moment is not a standard code, some developers are acquainted with the environmentally friendly coding practices and some other no.
Their company must relay a green IT culture to all the employees and specific to the tech employees
Like the software craftmanship, to have a clean code approach, the communities must create a manifest for the Green IT and communicate widely about it.
Our practices must changed, we must think differently, for example how have a trace log in a file and have a Green system ?

1 Like

So the obvious moral of the story here is to give devs shitty hardware. :smiley:

LOL, this is one of those things that has no good solution - on the one hand, you should give devs lower spec equipment so they will optimise for that…on the other hand, you don’t want to be paying devs to sit there all day watching a compile…

So I guess if SonarQube highlights ways to make your code more efficient/better performing then it doesn’t matter what hardware that was on…and you should get greener “for free” by requiring fewer resources.

Also it is probably an easier sell “I want to spend X amount of time making the application better/stronger/faster” (which happens to make it greener) than “I want to spend X amount of time making the application greener” - for a start, people will understand the former but will likely need the latter explained to them - at first read you do wonder “how can an application be green?”.
A hard thing to sell I think, (in companies at least, unless they are really invested in green), is “I want to make this application perform less well but it will be greener as a result”.

1 Like

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

7 Likes

Hi,
As final product consumer, we have been contact by one of your Account Manager to reply to this post.
I will not repeat what was have been already said previously about the paradigm shift. (Thanks to Cyrille who gives us a complete view).
I will explained what we do. In our enterprise, since 2020/2021, on top of your radar vision of apps (Maintainability, Reliability, Security, …) we have adding a new component the eco-design notion.
We actually clearly know what we have implemented have low impacts to the final picture but this prepare to change mindset teams about what they consume as hardware. It’s soft power. And at the end, we can internally more negotiate about provisioning and discuss tradeoff on vertical/horizontal scaling or accept performance risks, just in time without be treat as fool (Hoping that’s not what they think of me :joy:)

Since publication of your new iac-plugin, I’m really exciting about possible implementing rules to treat this aspect. By the past, as DevOps facilitator, i have seen to many misconfigurations from developers, too many RAM or space disk lost on this field. Ex:

  • usage Docker jdk/jre 8 without experimentalOption (to delegate ram jvm affectation to container size)
  • commandline docker run without memory option
  • usage jdk image to production java apps
    And I think, we may have to look implementation rules from best practices SRE fields. (Replicate rate pods : Min vs Max, etc)

In France, Accessibility and the GreenIT are two new domains faciliting by new laws, and polemic actualities (from IT or others trends).
Hoping, that’s will give define roadmaps and priorities of what we expecting.

Regards,
Louis, Enedis Client

3 Likes