Write Green Programs

By | January 23, 2020 | Performance | 10,455 | 11

It’s not about setting the background green of your code editor or setting up all the code lines to green or about having green background on your apps, but this about how you write your programs which would be more greener from environment perspective.

Background

Global warming is a happening right now, even if we can’t feel it. I will not go much into details about the Global warming but those changes are so small we don’t feel day to day. However if we take a look at the data for many years in past, we can see the pattern.

Greta Thunberg is young and sharp climate activist. If you haven’t heard her speech at UN on climate change, please watch it here.
Satya Nadella, Microsoft CEO, mentioned that how Capitalism would be in trouble if we don’t act on Climate Change.

Climate Control

Credit: Shutterstock.com KWest

Personally, I was fascinated by Solar energy when I was in elementary school. I couldn’t understand the technology but was thinking why not everyone uses solar. Later on I came to understand that it’s cost, which stopped people and still does to go for solar. I even had a crazy idea that put a solar panel on the scooter and run it without ever putting gas  May be that was too naïve but it would be reality someday.

Coming back to programming, how can we be green?

We would need to change our point of view on the design and programming to include more thoughts on how well our program does for environment. What is the carbon footprint of my program?

When you write any program think about how you can make some small adjustments and the value it could provide. Think overall ecosystem of entire product lifecycle and try to find a way to reduce the consumption of the energy. It might have a upfront more need of energy but all of those would be added up in the long run.

Write code which is Quicker to execute – Try to make your code quicker by using all sorts of different tools which are at your disposal

Code Push Down – Try to use all the code push down techniques: Use SQL functions for aggregate, Use CDS views to only get the data in calculated data back. This would make sure less data is transferred from the server to front end and hence it would save the bandwidth and would use less electricity to transfer that data (1KB vs 5MB of the data to get the 1 KB at last)

Add explicit check when using the for all entries to verify if the FAE table has the records to verify. Who knows in future, this check would save bunch of MW electricity as it doesn’t select all the data

Avoid selecting all the fields – This is valid from way old to even today but still many programs use that. Even standard SAP programs have SELECT *, even though they might be only using few fields. Write a code without selecting all fields would take a bit extra time, but that would not be optimal and would take long time to run and would consume more energy in long run.

Design Simpler Apps with less user interaction – When there is less user interactions, users would be quicker to perform the task. Like set some default values for the fields which user runs every-day. Moreover find this type of opportunities and automate them to save the time. Effort spent on designing this type of apps would improve overall usage of power. Certainly users would lose the coffee break 🙂 However they would appreciate the extra time they are getting and use that as they chose instead of sitting in front of the screen.

Remove print buttons from most of the screens/Lists – Removing print buttons from the app would force the user to download the data and massage if required. Hence would reduce the accidental chance of firing the print on a report with millions of records.

Keep your code smaller as it would help you refactor and reuse your code often. Also it would prevent people – who likes to print the code to read instead of researching in the code editor – to print entire 10000 lines code.

Keep your documentation / code cleaner – This would reduce the need for going through the commented code and spending time of analyzing on what had happened all those years ago. Cleaner documentation with single version of truth would improve readability and in turn reduce energy consumption.

Take Away

You might have your doubts on the impacts of all these, but I would just say this:

कर्मण्येवाधिकारस्ते मा फलेषु कदाचन

This verse if from The Bhagavad Gita,probably the most famous verse of The Bhagavad Gita. This translates to: You have every right to work but not expecting fruits out of it. Do not focus on the fruits and never be inactive.

Thanks for reading. Let me know your thoughts on going GREEN.

Like It? Share!!

Don't miss an Update

Get notified of the new post, right into your inbox

Naimesh Patel{274 articles}

I'm SAP ABAP Consultant for more than a decade. I like to experiment with ABAP especially OO. I have been SDN Top Contributor.
Follow :

Explore all of his 274 articles.

Load comments

11 Comments

  • cj

    Naimesh, welcome back.

  • Leo

    Hello Naimesh,

    Good message! and very warm welcome back! This here is one of the best sites (if not the best) regarding good ABAP 🙂

  • Yellappa

    Welcome back. It’s been long time since I read your last blog.

  • Gaurav

    Naimesh!

    Welcome back!

    So glad to see you back.I had messaged you on twitter also to be active again here. zevolving has been very helpful. Thanks a lot!

    Hope to see more of you in 2020!

    Gaurav

  • Thank you CJ, Leo, Yeallppa and Gaurav.
    It’s also good to be back and connect with you all.

    Thanks.

  • Vaishali Shinde

    Naimesh,

    I have been reader of your blog for a while and it is very inspiring to read your posts regarding better programming. This is one of the very concise blog post about programming going green. I am going to be more vigilant about these aspects in my programming, as going green is way bigger motivating factor. Thank you! And hope to see more posts from you.

    Thanks.

  • Vinay Udekar

    It’s a pity sometimes programmers don’t use the full capability of the language as well as their own potential. Be it SAP or any database, use of code to bring in all data without intelligently putting some conditions or filters is always not a good idea.

    Your blog is to the point. Very concise. Like the concept of “Green code”. Looking forward to read more blogs 🙂

  • Jakob

    By far the best ABAP OO Blog.
    Hope to see more blogs of you in 2020!

    cheers Jakob

  • Ankit Agarwal

    Your blogs are awesome. Hope to see more blogs in 2020!

  • V B V RAVI KIRAN

    Hi Naimesh

    Welcome Back.

    …Ravi Kiran

  • Raghu G

    Nice way to guilt some programmers into better code 🙂 I will definitely share this post with others.
    BTW, I think you are missing the second half of the Sanskrit scripture.

Comments on this Post are now closed. If you have something important to share, you can always contact me.

You seem to be new here. Subscribe to stay connected.