Sustainable Coding: What it is and why it is so important

Marina Bechtle
Mercedes-Benz Tech Innovation
2 min readMar 3, 2023

--

Sustainability can be found in every area of ​​work and life. We thought about questions like: How do you create a clean code? Also, with a focus on working in the cloud: What makes coding sustainable? All in all, five categories play an important role in sustainable coding:

· security,

· efficiency,

· durability,

· reusability and

· understandability.

You can find these five categories in many places in a data project within the cloud which we are going to explain in the following, using practical examples. For this, we divide a project process into code management, infrastructure, data loading and reporting.

What are green coding practices?

When it comes to code management, Git usage and clean code play a major role. Both are very important for the reusability and the understandability aspect of sustainable coding. Git has set itself sustainable goals, such as 100% renewable energy and zero-waste offices by 2025. There are many advantages of using Git: other developer tools are easy to connect, automation of the CI/CD pipelines, working alone or in a team, advancing projects and reusing things. In order to make code reusable, it is important to comment it sufficiently, summarize things that belong together, use speaking variables as well as functions and classes. With these approaches, spaghetti code becomes clean code.

Some security scans are also important in code management in order to comply with license guidelines, not to push secret information’s into the public or simply to intercept best practice violations (black duck scan, Best Practice Analyzer from Tabular Editor). These security scans are important aspects of security and durability in sustainable coding.

How does data loading affect sustainable coding?

Data loading is probably the most important part of data projects in the cloud that can influence sustainable coding. Various loading methods can save resources, time and money. In one project, we were able to reduce the data load from 192 hours to less than 2 hours by moving to the cloud and using cache, keys, ordering and aggregation tables. Thus, this part clearly contributes to the efficiency of sustainable coding.

Finally yet most importantly, cloud providers offer monitoring tools to monitor CO² and energy consumption as well as costs, in order to check and lower them repeatedly.

Conclusion: How can we code sustainably?

To code more sustainably we should all be stingy with resources, time and money and very generous with knowledge, sharing, documentation, comments and creativity. Question the here and now and think of better solutions for the future!

If you have any questions, please do not hesitate to contact Tobias Digeser (tobias.digeser@mercedes-benz.com) or Marina Bechtle (marina.bechtle@mercedes-benz.com).

--

--