language-icon Old Web
English
Sign In

Boilerplate code

In computer programming, boilerplate code or just boilerplate are sections of code that have to be included in many places with little or no alteration. When using languages that are considered verbose, the programmer must write a lot of code to accomplish only minor functionality. Such code is called boilerplate. In computer programming, boilerplate code or just boilerplate are sections of code that have to be included in many places with little or no alteration. When using languages that are considered verbose, the programmer must write a lot of code to accomplish only minor functionality. Such code is called boilerplate. 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 boilerplate manual code). 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 ready plates way were usually 'fillers' rather than 'serious' news, the term became synonymous with unoriginal, repetitive 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. One form of boilerplate consists of declarations which, while not part of the program logic or the language's essential syntax, are added to the start of a source file as a matter of custom. The following Perl example demonstrates boilerplate: The first line is a shebang, which identifies the file as a Perl script that can be executed directly on the command line (on Unix/Linux systems.) The other two are pragmas turning on warnings and strict mode, which are mandated by fashionable Perl programming style. This next example is a C/C++ programming language boilerplate, #include guard.

[ "Java", "Software engineering", "Programming language", "Code (cryptography)" ]
Parent Topic
Child Topic
    No Parent Topic