
Lean Code
Lean code refers to a way of working in which programs are written with as little superfluous effort as possible: little baggage, little repetition, only what is truly needed. The goal is software that stays understandable, runs fast, and is cheap to maintain.
A program consists of instructions that a computer works through in sequence. These instructions can be written down in a cumbersome way or in a concise and orderly way. Lean code is the name for the second variant: you write only what the task truly requires. Anything nobody needs is thrown out, or never comes into existence in the first place. This concerns duplicate passages of text, functions that no one calls anymore, and intermediate steps that accomplish nothing. “Lean” means slim or trim.
What slim code saves in costs
Software is read far more often than it is written. A team changes a program again and again over the course of years. Every unnecessary line has to be read along, tested along, and understood along with the rest. In large projects with millions of lines, this quickly becomes the biggest cost block. Companies often spend more money maintaining old software than on new features.
On top of that comes error-proneness. Every line is a place where something can go wrong. Anyone who removes half the code roughly halves the number of possible error sources as well. Security vulnerabilities particularly like to hide in parts that hardly anyone still looks at. A well-known example is old libraries — ready-made code building blocks from others — that a project keeps dragging along even though it no longer uses them.
Finally, speed plays a role. Less code usually means smaller programs, shorter load times, and lower memory requirements. With an app on a phone, you notice this directly at startup. In data centers, it shows up on the electricity bill.
The rules behind the slim program
The most important principle is: don’t repeat yourself. If the same calculation appears in five places, you write it once and call it five times. If the rule changes later, you only have to touch one spot. The second principle is not to build functions just in case. Programmers tend to plan for cases that never occur.
A central tool is refactoring. This means restructuring existing code without changing its behavior. Long functions are broken down into short ones, unclear names are replaced with descriptive ones, dead code is deleted. To make sure nothing breaks in the process, automated tests run alongside. These are small check programs that verify after every change whether everything still works.
A common misconception is that lean code means as few characters as possible. Often the opposite is true. An extremely condensed one-liner that nobody understands is not lean code but a trap. What is meant is little substance, not little text. A comparison: a good essay is not the shortest one, but the one without filler sentences.
Lean code in apps, start-ups, and AI tools
In job postings and company reports, the term usually appears as a promise of quality. A start-up that advertises a lean codebase wants to say: we can deliver new features quickly. For investors this is relevant, because messy code slows a company down. In the industry, this is then referred to as technical debt.
In everyday life, you notice the difference in apps. Some start immediately and need little memory, others take ten seconds to load. Websites are also a good example: many load several megabytes of code for a few paragraphs of text. Lean pages are noticeably faster on mobile networks.
New is the debate surrounding AI assistants that write code. Such tools generate a great deal of text very quickly and tend to create things redundantly. As a result, the amount of code in projects grows noticeably. This is exactly why developers are talking about lean code more often again right now.