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

Transcript

The greenest code is the code you delete. Old code does not sit still. Unused functions and abandoned feature flags still get built and tested. Libraries nobody calls still get scanned, shipped and loaded. A heavy library pulled in for one helper adds weight to every build. And to every deploy, again and again. Here is the fix you can use today. First, remove code paths and flags that nothing reaches. GreenCode's Constitution skill can help an AI coding agent find waste like this. Next, list every dependency in a software bill of materials. SPDX is the open standard format for that list. Remove the ones nothing imports. Then replace a heavy library used for one small feature. GreenCode researchers list dead code and unused libraries as an energy waste to fix. Less code shipped means less to store, send and load. GreenCode helps tackle this by mapping a codebase into a searchable index. Its full bill of materials shows which dependencies to drop or replace. That was GreenCode Tech Tip number forty-four. Follow for the next tip, and find more on greencode.ai/tech-tips.

All GreenCode Tech Tips · All GreenCode videos

  • Tip #44
  • For Developers
  • Length 1:14
  • Category Code efficiency
GreenCode

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

Get in touch