Boilerplate code

Boilerplate code

Boilerplate code is program text that always looks the same and has to be written anew in many projects, even though it doesn't accomplish anything unique. It's necessary so that a program can start at all or fit together with other software – no original thought went into it.

A program consists of instructions that a computer executes one after another. Part of these instructions is the actual idea: the calculation, the rule, the special thing about the software. Another part is mere scaffolding that looks the same in almost every project. This scaffolding is exactly what programmers call boilerplate code. The name comes from the printing trade: newspapers used to receive ready-cast metal plates with always-identical texts, which they printed unchanged. Boilerplate code is the software version of that – you type it out without really thinking about it.

Why developers hate boilerplate

Boilerplate costs time without making a program any better. Anyone who spends an afternoon typing out standard scaffolding hasn't solved a single problem by the end. In small projects that's annoying; in large ones it becomes a real cost factor.

Worse is the second effect: boilerplate makes the code confusing. If there are three lines of real logic buried among twenty lines of scaffolding, the important part is hardly findable anymore. Bugs like to hide in such text deserts. And because the standard text looks the same everywhere, deviations are easily overlooked.

That's why "little boilerplate" is a selling point for programming languages and tools. Modern languages like Kotlin or Python advertise that you achieve the same result with noticeably fewer lines than in older languages. A typical mistake, however, is to automatically consider short code as better code. Overly condensed code can be harder to understand than a few lines of honest scaffolding.

Where the always-identical text comes from

Boilerplate arises wherever an environment demands fixed formalities. For a program to work together with a database or a web server, it has to conform to prescribed forms. These forms are the same for everyone – so everyone writes the same lines. A classic example is Java, where for every stored data field one used to create two extra mini-functions for reading and writing.

There are three common answers to this problem. First, templates: development tools generate the basic scaffolding of a project at the push of a button. Second, libraries, i.e. ready-made collections of code that hide the recurring parts behind a single call. Third, code generators that automatically produce the scaffolding from a short description.

Boilerplate should be distinguished from plain code duplication. Duplicated code is one's own logic that was written twice out of laziness – that can be consolidated. Boilerplate, by contrast, is an externally imposed requirement. Often you can only hide it or have it generated automatically, but not simply omit it.

Boilerplate in AI tools and contracts

The topic is currently most visible with AI coding assistants like GitHub Copilot. Such tools suggest entire chunks of code as you type. This works especially well with boilerplate, because the text is predictable and appears millions of times over in training data. That's exactly what the manufacturers advertise: the machine takes over the routine, the human thinks about the logic.

Anyone who reads business news encounters the word outside of software too. Lawyers also call standard clauses in contracts boilerplate – for instance paragraphs on jurisdiction or liability. There too, it's about text modules that no one formulates anew.

For assessing company announcements, the term is useful. When a vendor claims its AI already writes large portions of the code, it's worth asking which portions those are. Producing boilerplate is considerably easier than correctly nailing tricky domain logic. Lumping both into a single percentage makes progress appear greater than it actually is.

Subscribe free. Unsubscribe the second it sucks.

High-signal news across AI, business, UX, and tech. Every morning.