Green Coding 4/7: Green software craftmanship approaches

Thierno Diallo
Just-Tech-IT
Published in
10 min readMay 13, 2024

--

The Green Software Craftsmanship is an approach to software development that emphasizes the eco-responsibility of our applications by minimizing their environmental impacts.

This can include practices such as reducing energy consumption, efficient resource management, lowering greenhouse gas emissions, and minimizing electronic waste. In other words, it is about sustainable and eco-responsible software development, considering the environmental impact at every stage of the development process.

In this article, we will discuss about principles such as clean code, efficient frontend development, optimized algorithms, energy-efficient hosting, and eco-friendly practices. By integrating these practices, we can create applications that meet business requirements while reducing energy consumption, resource waste, and environmental impact.

By considering the principles of clean code, we quickly see that each principle helps to perfect our code and make it more efficient.
Here are six of these principles including:

  • Writing less but creating more
  • Code refactoring to keep it up to date.
  • Making our code clean and understandable
  • Proper error handling
  • Creating atomic methods/functions
  • Applying solid principles, specifically the Single-responsibility principle

Not only do these principles have a real impact on optimizing our code, but they also save time during maintenance, evolution, correction, and when new team members join the project. Less time spent understanding and adding code means less energy consumed by our equipment.

Here is an example of Green Software Craftsmanship in action within web application development to illustrate the concept thoroughly.

Here is an impactful way to implement the principles of Green Software Craftsmanship:

1- Optimise the Frontend development

a- Reduce the HTTP requests

There are seven techniques to reduce and optimize HTTP requests from the front-end.

  • Use CSS sprites.

Combining multiple images into one reduces the number of HTTP requests needed to download the images.

  • Concatenate CSS and JS files

Combining all CSS and JS files into one reduces the number of HTTP requests.

  • Use caching.

Storing files on the user’s browser eliminates the need to download them on each visit, reducing the number of HTTP requests.

One way to better apply caching is to use the PWA (Progressive Web App) approach, in order improve the offline and background works.

Don’t hesitate to read more on PWA here.

  • Use a CDN (Content Delivery Network)

Distributing website content from servers worldwide reduces page loading times and the number of HTTP requests, especially when implementing lazy loading for resources.

b- Optimizing image usage:

  • Image compression

One of the most common ways to optimize an image is by reducing its file size, thus reducing loading time while maintaining acceptable visual quality.

  • Reduce image size.

Compressing images reduces their size and the time needed to download them without sacrificing image quality, done efficiently.

  • Choose the right image format.

Image formats like JPEG, PNG, and GIF have advantages and disadvantages in terms of quality and file size. By selecting the right format for each image, you can optimize file size and image quality.

Furthermore, we can use more appropriate and optimised formats like WebP and Avif, or other ones according to your needs and contexts.

In order to learn more how to choose the right format for the right context, please have a look to this page, on which there are more details about the formats, the advantages and inconveniants.

c- Lazy Loading

This technique loads images only when needed, improving website performance, and reducing the initial loading[AG1] [DT2] time.

Here is an example of lazy loading in React (Apologies to the React pros, I am not React Native :D)

Then, we can use this component to add the lazy loading technique to our React application by loading the images asynchronously.

2- Efficient Backend Treatment

a- Optimized algorithms

Selecting the most efficient algorithms in terms of spatial and temporal complexity, as well as computational time, is crucial for common tasks such as search, sorting, and bulk data processing.

Here are two examples of optimized algorithms, as well as the combination of the two to solve slightly more complex problems.

Sorting Problem

When sorting an array, it is advisable to favor the Quicksort algorithm, which has a complexity of O(n*log(n)).

This makes it the most effective algorithm in most cases.

Search on a sorted array

To perform a search in a sorted array, it is advisable to favor binary search, which has a complexity of O(log(n)).

Here is an example.

In any case, we need to be familiar with the several types of algorithms applied to our field and know how to use them efficiently according to the contexts and needs.

This knowledge is not innate or static, so we must continue to learn to stay up to date.

b- Implement Caching

Implement caching mechanisms to reduce the need for repetitive calculations, unnecessary HTTP calls, and database queries.

However, the caching mechanisms should be used with caution and after analyzing the requirements.

We must know our context, to use the right options for the right service.

c- Databases Optimization

It is also essential to optimize databases to maximize performance, resource utilization, and efficiency.

Here are five key points that can help optimize your database:

  • Effective indexing
  • Query optimization
  • Use of materialized views
  • Regular cleaning and maintenance
  • Performance monitoring

By combining these optimization practices with others, we can significantly improve database performance and efficiency, contributing to more effective resource utilization.

3- Energy-Efficient Hosting and Infrastructure

a- Clouds Providers choice

When assessing a cloud provider, we should consider.

  • The energy sources used for their data centers (if they are renewable)
  • Their efforts in terms of eco-responsibility
  • The commitments made to reduce environmental impact and preserve biodiversity.

By selecting cloud providers that prioritize renewable energy sources, businesses can reduce their carbon footprint and contribute to a more sustainable digital future.

b- Serverless Architecture

Implementing serverless architectures is a wonderful way to minimize energy and resource consumption.

Serverless allows for the development and execution of applications and services without the need to manage the underlying infrastructure.

Here are four examples of how serverless can help reduce costs and resource consumption:

  • Dynamic resource allocation
  • Pay-as-you-go model: This will lead us to rethink our ways of reducing consumption and costs.
  • Efficient auto-scaling of resources
  • Optimized infrastructure management: The management is delegated to the underlying cloud provider, and it is transparent.

c- Containerization and Native image build

Using containerization technologies to optimize resource utilization and improve efficiency.

We can use,

  • Native image build to reduce storage impact and improve boot time and runtime efficiency.
  • Docker as well can be used to define the resources according to the need of each container, and to reduce the servers/vms utilization.
  • Kubernetes to orchestrate all our services and to better the resources allocations.

4- Optimization and Monitoring

a- Performances Monitoring

Monitoring before, during, and after is the main key to have more sustainability in it. Because:

  • It allows for the real-time observation of performance and resource usage,
  • It enables the identification of inefficiencies, over-utilization, or under-utilization of resources.

By using tools such as

  • Dynatrace
  • New Relic
  • Datadog
  • Prometheus
  • Kepler

we can monitor the performance and actual resource utilization in production.

This observation can provide valuable insights, allowing us to adjust our needs to the essentials, and to reduce our resources and energy consumption.

b- Profiling and Optimization

The best way to identify performance bottlenecks and optimize the application, accordingly, is to use profiling tools.

Here are ten tools that we can use based on our language :

  • Python: cProfile, line_profiler, memory_profiler, Py-Spy
  • Java: VisualVM, YourKit Java Profiler, Java Mission Control
  • C/C++: gprof, Valgrind, Intel VTune Profiler
  • Node: profiling

c- Auto-scaling

If we combine performance monitoring to provide the exact number of resources needed and implement auto-scaling mechanisms.

Not only do we ensure dynamically adjusting resources up or down as needed, but we also save resources and energy.

This makes the application more efficient and environmentally responsible.

5- Use eco-friendly software development practices.

a- Agile Method

Adopt agile development methodologies like,

  • Scrum
  • Kanban
  • Extreme programming (XP)
  • Adaptative Software Development (ASD)
  • Dynamic Software Development (DSDM)
  • Feature Driven Development (FDD)
  • Behavior Driven Development (BDD)

To promote continuous learning, step-by-step improving, and add green coding feature on every step according to the market advice or our understanding.

  • Iterative Development

By focusing on incremental and iterative development, Agile reduces the risk of large-scale project failures and enables continuous improvement, thereby reducing waste and promoting sustainability.

  • Adaptability

Agile allows teams to adapt to changing requirements, thus reducing rework and unnecessary resource consumption, contributing to sustainability.

  • Collaboration with Clients

Agile emphasizes close collaboration with clients, ensuring that software products meet real needs, and reducing the likelihood of developing unnecessary features that could contribute to waste.

  • Continuous Improvement

Agile fosters a culture of continuous improvement, enabling teams to identify and rectify inefficiencies, leading to more sustainable software development processes.

  • Empowered Teams

Agile empowers multidisciplinary teams to make decisions, fostering a sense of engagement and accountability that can lead to more sustainable practices and outcomes.

This approach makes it easier to integrate sustainable software engineering practices into our delivery processes. More importantly, we must continue to learn and adapt our green practices to evolving knowledge, practices, and state of the art.

b- Continuous Integration and deployment (CI/CD)

By using continuous integration and deployment (CI/CD) practices efficiently, we can contribute to making our software more sustainable through the following benefits:

  • Waste Reduction

CI/CD automates the build, test, and deployment processes, reducing error-prone manual activities and minimizing resource waste, thereby promoting more efficient and sustainable software delivery.

  • Faster Feedback Loops

By automating tests and often integrating code changes, CI/CD shortens the feedback loop, enabling developers to identify and resolve issues earlier in the development cycle, thus reducing rework and resource consumption.

  • Efficient Resource Utilization

CI/CD allows for efficient use of computing resources by automating provisioning and deprovisioning of development and test environments, resulting in reduced energy consumption and overall environmental impact.

Additionally, we can use open source tools like Daily Clean and SlimFaas to improve our infrastructure efficiency.

We can also use plugins like:

To measure and improve our apps resources and energy consumption during the build and runtime.

  • Reduced Time to Market

CI/CD streamlines the software delivery pipeline, enabling faster and more frequent releases, which can reduce waste and supply a more sustainable response to changing market demands.

  • Continuous Improvement

CI/CD promotes a culture of continuous improvement by automating the feedback loop and enabling rapid iteration, leading to more sustainable software development practices over time.

c- Mob Programming, Code Review and Refactoring

Collective code review is an excellent tool to ensure a prominent level of adherence to sustainable development best practices or other good practices.

Not only does code review enable rapid skill enhancement and shared learning, but it also helps identifying areas for optimization and improvement.

We can also use the “Mob programming” concept, to ensure that the collective smartness is used to have more sustainable ideas. You can find the full French article here

6- Conclusion

Integrating these practices at all levels of the software development chain will enable the creation of applications that meet business requirements while improving energy efficiency and reducing resource consumption and environmental impact on biodiversity.

Furthermore, technological watch let us informed about emerging technologies and best practices in sustainable software development.

By following technological advancements and sustainable development methods, we will contribute to reducing the environmental footprint of our information systems.

In the next chapter we will discuss about Ethics, Green and Sustainable IA, on how to collect data, to train/build/run models sustainably, the patterns and principles to achieve this goal.

Thanks to Ana Gamito, my principal review and Axa Software Sustainability track co-lead.
Thanks to my first reviewers the Axa France Green Champions Community, Maxime Leuleux, Thiery Behin, Amandine Calier, Sofiane Oudina, Pascal Nicolette, Amaury Preclin, Daniel Salomé.
Thanks to Sarah GUTSATZ, Gilles CRUCHON, Abir JELLAD, David Graca, Guillaume CHERVET.

Thanks to Annick Le Ber for constantly supporting and providing interesting and thought provoking topics and papers on IA, Sustainability and responsible computing.

While waiting for the next article, I am providing you with some interesting blogs articles and some links:

1- Green Coding ou comment construire des logiciels durables | by Thierno Diallo | Just-Tech-IT | Medium

2- Green Coding Sustainable Data Management principle

3- Green Coding 3/7: native image build as path to reduce our digital carbon footprint | by Thierno Diallo | Just-Tech-IT | Mar, 2024 | Medium

4- J’ai du mal à dire “Non” au travail, mais je me soigne ! | by Gilles Cruchon | Just-Tech-IT | Medium

5- Faut-il privilégier la performance ou la lisibilité ? | by Johnathan MEUNIER | Just-Tech-IT | Medium

6- Green software engineering with agile methods | IEEE Conference Publication | IEEE Xplore

7- 59138.pdf (scitepress.org)

8- Sustainable Software Development: What is It, Best Practices | Beetroot

9- Software Craftsman : une culture du développement — Cegid Jobs

Bibliography

1- Green software engineering with agile methods | IEEE Conference Publication | IEEE Xplore

2- https://developer.mozilla.org/en-US/docs/Web/Media/Formats/Image_types#common_image_file_types

3- https://nodejs.org/en/learn/getting-started/profiling

4- 59138.pdf (scitepress.org)

https://developer.mozilla.org/en-US/docs/Web/Progressive_web_apps/Guides/Caching

6- Sustainable Software Development: What is It, Best Practices | Beetroot

7- Software Craftsman : une culture du développement — Cegid Jobs

8- Global research on the thermal energy storage industry in 2024–2032: — News Paris50 (paris50degres.fr)

--

--

Thierno Diallo
Just-Tech-IT

Staff Engineer/Technical Leader And Green Champion at Axa France