Lably
Skip to content

Boilerplate code

Code that has to be included in many places with little or no alteration

  • 7 min read
  • 4 chapters

Related on Lably

Through Class (programming), Newspaper and Printing

The need for boilerplate can be reduced through high-level mechanisms such as metaprogramming (which has the computer automatically write the needed boilerplate code or insert it at compile time), convention over configuration (which provides good default values, reducing the need to specify program details in every project) and model-driven engineering (which uses models and model-to-code generators, eliminating the need for manual boilerplate code).

It is also possible to move boilerplate code to an abstract class so that it can be inherited by any number of concrete classes. Another option would be to move it into a subroutine so that it can be called instead of being duplicated.

Origin

The term arose from the newspaper business. Columns and other pieces that were distributed by print syndicates were sent to subscribing newspapers in the form of prepared printing plates. Because of their resemblance to the metal plates used in the making of boilers, they became known as "boiler plates", and their resulting text—"boilerplate text". As the stories that were distributed by boiler plates were usually "fillers" rather than "serious" news, the term became synonymous with unoriginal, repeated text.

A related term is bookkeeping code, referring to code that is not part of the business logic but is interleaved with it in order to keep data structures updated or handle secondary aspects of the program.

Sign in to keep reading

3 more chapters are free with a Lably account.

More in Computing and communication