Community Comment: Part 37 - All code is disposable; only some code is trash

  • All code is disposable; only some code is trash
  • The word "trash" has negative connotations
  • All portions of given code base have life cycle
  • Avoid miscommunication by being clear!

The comments I provided in reaction to a community discussion thread.

Software Architect at Design & Construction Product Firm:

All code is trash.

Don't hesitate to throw out what you originally wrote. The outcome is what matters.

Throw away iterations.
Throw away prototypes.
Throw away your favorite code.

Source control will have it if you really need it. But, YAGNI.

Simplicity is achieved by removing unnecessary code — not by adding more.

Code is a tool to achieve an outcome.

Once it no longer serves the needs of the application or could be done simpler, it’s trash — no matter how beautiful or elegant it is.

Refactor it, simplify it, or delete it to serve the needs of the application better.

Become comfortable letting go of your code. You’ll be free to make simpler code.


Owner & Programmer at Lisp Development Firm:

Just because you have never written beautiful code worth keeping, doesn't mean it's impossible. Skill issue. ;P

Software Architect at Design & Construction Product Firm:

[Owner & Programmer at Lisp Development Firm] I write beautiful, clear, concise code. I get there by writing less clear code that I prune.

I’m still not afraid to throw it away if it doesn’t support the changing needs of the program.

Owner & Programmer at Lisp Development Firm:

[Software Architect at Design & Construction Product Firm] Well, that seems to contradict your "all code is trash" notion, unless you think your "beautiful, clear, concise code" is also trash…

I think you meant "disposable"?

Software Architect at Design & Construction Product Firm:

[Owner & Programmer at Lisp Development Firm] “trash” doesn’t mean ugly. Disposable is a good, less hyperbolic, synonym.

I use hyperbole to emphasize that no matter how beautiful code is, it’s trash once it no longer serves the needs of the application. It’s trash once the same outcome can be achieved with less code and complexity.

So, beautiful code is also trash.

Owner & Programmer at Lisp Development Firm:

[Software Architect at Design & Construction Product Firm] Well, if your code has such a short useful life, perhaps it is trash. But not all code is.

Software Architect at Design & Construction Product Firm:

[Owner & Programmer at Lisp Development Firm] it’s not about the lifespan of the code. It’s about the lifespan of the problem being solved.

If you could solve the same problem in your codebase with less code than before, would you delete the old beautiful code to do so?

I find elegance in simplicity. If I discover better, simpler, more performant ways to do the same thing, I don’t hesitate to delete what came before it.

The new code is beautiful. The old code was beautiful, but able to be thrown away. In other words, trash. As you say, disposable.

Senior Software Engineer at AWS:

I was gonna say something but then realized [Software Architect at Design & Construction Product Firm] already said it better. The cleverness or beauty of the code itself isn’t even a 1% factor in the decision process of whether to keep it or not

Gfesser:


In this context, the word "disposable" is much more accurate than "trash", because the word "trash" typically has negative connotations whereas "disposable" doesn't. As with programming languages, it's important to be particular with human language usage to help prevent miscommunication. What we're really talking about here is the life cycle of a given area of a code base: sometimes it ends up no longer meeting one's needs, so don't get too attached to it, but this doesn't mean that *all" code meets the same fate.

Subscribe to Erik on Software

Don’t miss out on the latest issues. Sign up now to get access to the library of members-only issues.
jamie@example.com
Subscribe