Tech Tip #13: Clean code is greener code

Ordinary refactoring saves 10 to 30% energy, studies report.

Video created by explainapaper.com

The problem

Quality work is treated as a cost with no visible return. But the structures that make code hard to maintain, like repeated queries, recomputed values and stale dependencies, are often the ones that make it expensive to run.

The fix you can use today

  • Fund quality work (duplication, complexity, missing tests) as part of normal maintenance.
  • Track energy alongside quality metrics so the saving is visible.
  • Do quality first, then energy-specific optimisation.

Studies of code clean-ups report energy savings of 10 to 30%, before any energy work. GreenCode's climate case is built on this range.

Tools that help

  • GreenCode Constitution skill (GreenCode researchers): open-source energy principles and a catalogue of 37 energy anti-patterns that an AI coding agent can follow to find and fix waste like this
  • SonarQube: static analysis for code smells, bugs and security issues, with quality gates in CI
  • Green Metrics Tool: measures the energy of whole software scenarios run in containers, so runs can be repeated and compared

How GreenCode helps

GreenCode helps tackle this by checking a codebase for quality, security and green software patterns in one pass. Wasteful code comes out as a ranked defect, alongside the bugs and security findings. More on this.

Tags

#code-quality#refactoring#cost

Sources

All GreenCode Tech Tips

  • Tip #13
  • For CTOs and technical leads
  • Category Testing, CI and code quality
  • Format short video
GreenCode

Want this checked on your own system? Talk to the GreenCode team.

Get in touch