Discover the “GREENEST” PROGRAMMING LANGUAGES

Discover the “GREENEST” PROGRAMMING LANGUAGES
Days ago, at the coffee machine, some of our developers got into a debate. They were estimating the ecological impact of their programming languages, to find out which one is the greenest.

This inspired us, and we decided to investigate further to figure out the answer (which is a good way to “excel in the high society of digital”), but also, we wanted to point what are the main factors that can increase the carbon footprint of a code language (size of the code, storage, time spent, energy …)

We are not the first one to wonder, this question has led some eco-minded software companies and individuals to start considering if the programming languages they coded with was harming the environment. Subsequently, it got them to openly ask: which programming language was the “greenest.” This soon gave birth to the concept of “green coding.”

There wasn’t much research done on the idea of green coding, leaving software engineers to draw their own conclusions on the greenest programming language – and the link between performance and energy efficiently. That is, however, until a joint research project conducted by experts from three Portuguese universities researchers measured the energy efficiency of 27 programming languages.

In this post, we summarise the findings of this research project to answer the question of which programming language is the greenest. By contrast, we’ll also look at which languages performed worst in the study and, by extension, do the most harm to the environment.

Green Coding Principles

Green coding refers to using languages and software development practices to preserve the environment. As the research presented in this post shows, some programming languages consume more energy than others, resulting in more carbon emissions. Subsequently, if software engineers engage in development practices that prolong project development lifecycles, that also results in excess energy consumption. Factors like these are called structural green coding considerations.

On the other hand, small adjustments to the way software are developed can make it more energy-efficient. For instance, if a mobile app has an intuitive user interface, people will require less time to use it, leading to lower battery consumption. This then results in the user needing to charge their device less frequently, resulting in fewer carbon emissions. These, in contrast, are considered behavioural green coding considerations.

Green coding is based on the idea that small changes in the way digital solutions are developed can make a significant difference to environmental sustainability.

 

Criteria to be a Green Language

To determine the greenest programming language, we first have to establish the criteria by which they’ll be measured. The research project’s primary method of measuring each programming language’s energy efficiency – and eco-friendliness – utilised the Computer Language Benchmarks Game (CLBG). The CLBG provides a compressive framework for running, testing and comparing solutions for a wide range of compressive well-established programming problems. The CLBG allows for consistent benchmarks across all the tested programming languages.

The three metrics used to measure each programming language’s energy efficiency were Energy (J), Memory Used (Mb) and Run Time (ms). The 27 languages produced the following range of results across each metric:

  • Energy: 1 – 79.58 J
  • Memory Used: 1 – 19.84 Mb
  • Run Time: 1 – 82.91ms

Now, let’s look at which programming languages rank as the greenest.

 

– – – The Most Green – – –

C

C is a general-purpose programming language used to develop everything from enterprise applications and operating systems to games and databases.  It’s still one of the most popular used programming languages, currently sitting at #2 on the TIOBE programming language index.  Notable projects developed in C include UNIX, Windows, and large parts of Google.

 

C++

C++ has a wide range of applications, including web and android apps, games, operating systems, and browsers. Like the language it’s derived from – C, it’s one of the most popular programming languages utilised by software engineers today. Notable projects written in C++ include MS Office, YouTube, and Amazon.

 

Rust

The newest language of those featured in this article, Rust was designed by Mozilla Research with performance and safety in mind. Famous applications developed with Rust include Firefox, Dropbox and Cloudflare. However, perhaps due to the fact it was only launched in 2010, Rust isn’t as popular as C and C++, sitting in the middle of the TIOBE index.

 

 – – – The Least Green – – –

 

Python

Sadly, Python isn’t as green as the animal its named after – but that hasn’t prevented it from becoming the most popular language on the TIOBE index. Python can be used for scripting applications, web apps, task automation, conducting data analysis, as well a wide range of other tasks. NASA, Google, Netflix, and Spotify are among the huge organisations that make use of Python’s immense functionality.

 

Perl 

Perl (Practical Extraction and Report Language) is referred to as the “duct tape of the interest” or “the Swiss army knife of scripting languages” because it’s so handy for quick, simple fixes of data-related problems. Perl also makes it simpler for software developers to integrate third-party interfaces. It used to be the most popular programming language but now it barely sits in the top half of the TIOBE index.

Ruby

Ruby is a highly portable general-purpose language that can be used to build desktop applications, static websites, data processing services, web servers, DevOps, and web scraping and crawling. The powerful web development framework Ruby on Rails is built on Ruby and has been used to develop Airbnb, Shopify and Soundcloud, among others. Ruby sits around the middle of the TIOBE index in terms of popularity.

If you’re interested in how other languages, like JavaScript, Java, PHP, Go, and Swift performed in terms of energy efficiency, you can read see the full table ranking green programming languages here.

 

Best Practices for Green Coding 

 As mentioned earlier, the benefits of coding in a green language are significantly reduced if coupled with inefficient development methodologies. General green coding best practices also need to be followed. Here are some green coding principles that environmentally company software engineers and development companies can abide by.

  • Efficient code development: write reusable, modular code, using intuitive naming conventions, clear commenting, etc. Not only does this reduce initial development times, but it reduces the timeframe and cost of future updates.
  • Regularly review code: clear code of unused features, a.k.a., code minimisation, reducing the number of lines compilers have to parse.
  • Reuse existing code: As well as reusing your own code, make use of code from free open-source software on GitHub and the open-source development network (OSDN)

 

     Though in its early days, green coding is an emerging field that takes a programming language’s energy efficiency into account when choosing them for development projects. To adopt green coding practices, software development companies need to choose programming languages for their projects according to their specific needs.

  Subsequently, companies with a commitment to corporate social responsibility, and environmental stability, in particular, need to select software development companies based on their adherence to green coding practices.
 
“This is your last chance. After this there is no turning back.
Will you take the green pill ?” 
 
Leave a Reply