Ko-fi

Wednesday, 27 March 2019

Is your code eco-friendly?

Do you realise that poorly written software is a contributor to global warming?

Although I have absolutely no data to base this on, please, read on... I assure you that you will not only conclude that this is a true statement; if you code, you may even feel compelled to write better code. If that's not enough of a hook, I will introduce to and encourage you to use, this hashtag in your code reviews:


#cowfart

Let me set the scene...


There's a lot of software out there, running on billions of devices across the globe, and sadly, a lot of that code is not optimised.

Back in the day when we wrote in assembler on tiny 8-bit computers we would count clock cycles (honestly; it wasn't just me!) and refactor, refactor, refactor... until we got the best oomph out of the CPU that we could.

As if by magic, computers started popping up everywhere and hardware started to get really fast. And cheap. Suddenly, it was not about clock cycles. It was all about time-to-market. Get the code cut fast, get it released, and if it didn't run very well, upgrade the hardware!

It really was that simple for a long time; certainly for most business software anyway. Games, well that's different because if you have lag... you suck. Well, your game does, and it won't sell. In business software, having things take a while isn't necessarily a problem... more time at the water cooler, more time to do all the admin things.

Sidenote: I would encourage every budding programmer, and even seasoned programmers, who have only worked in business application development, to do some games programming. The techniques you will learn in order to survive out there are transformational.

Technology has moved along at a rapid pace. Astonishingly fast, and astonishingly cheap. And the world, largely, depends on it being that way.

The plot thickens...


Thing is, we've got big problems out there.

With climate.

Okay, not just with climate; other big problems are available.

You don't have to just believe in it anymore either; it's fact, evidenced in the starkest possible ways.

We take a tangent...


Before we get back to my main point, I did promise you a cool hashtag to use in code reviews.


#cowfart

Why? Well, because it is believed that cows are a significant contributor to global warming because there are a lot of cows out there. And they fart. Quite a lot actually. There are many articles and research studies about it.



Okay, okay... cows fart, hardware got better, people stopped counting clock cycles, and released products faster... get to the point already!

So, here's the thing...


If you write sloppy code that does not perform as well as it could, it will take longer to execute. If it takes longer to execute, or if it requires additional processing power just to make it run, you are using more hardware, more electricity, and creating more heat. On a single PC, meh... what's the difference, right? Time to hit the water cooler.

If you scale that up to run on billions of devices across the planet, well... that's a staggering amount of electricity, time, and heat being wasted by your code.

Although your code might not get to be in the next kernel of Linux, Windows, Android, or some other place like Facebook, where it might be executed trillions of times, that's not a good reason to write sloppy code.

Always write the best code you can, and educate yourself on performance tuning.

The end is nigh...


And so, without further ado, next time you review some code or give yourself a TODO:, and see code that you know the could be better performing...

do the polar bears a solid...
keep some habitat for the bees...
think of the children...

Won't somebody please think of the children?

And, as a fun way to say "Hey, this bit of code you wrote. It sucks. It might work, it might even read like a poem. Thing is, it could perform much better. So sort it out."... just put #cowfart in there.

Because the planet's worth it.

Fin.