Tech Tip #44: Delete dead code and unused dependencies

The greenest code is the code you delete.

Video created by explainapaper.com

The problem

Unused functions, abandoned feature flags and dependencies nobody calls are still built, tested, scanned, shipped and loaded. A heavy library pulled in for one helper adds weight to every build and deploy.

The fix you can use today

  • Remove code paths and flags that nothing reaches.
  • Generate a software bill of materials and remove dependencies nothing imports.
  • Replace a heavy library used for one small feature.

GreenCode researchers list dead code and unused libraries as an energy waste to fix.

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
  • SPDX: the open standard format for software bills of materials, listing every dependency with version and licence

How GreenCode helps

GreenCode helps tackle this by mapping a codebase into a searchable index with a complete SPDX software bill of materials, so unused and deficient dependencies can be found and replaced. More on this.

Tags

#code-quality#refactoring#cost

Sources

All GreenCode Tech Tips

  • Tip #44
  • For Developers
  • Category Code efficiency
  • Format short video
GreenCode

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

Get in touch