What is boilerplate code?

Viewed 226199

A coworker had never heard of this, and I couldn't provide a real definition. For me, it's always been an instance of 'I-know-it-when-I-see-it'.

Bonus question, who originated the term?

15 Answers

In a nutshell, boilerplate codes are repetitive codes required to be included in the application with little to no change by the program/framework, and contribute nothing to the logic of the application. When you write pseudo codes you can remove boilerplate codes. The recommendation is to use a proper Editor that generates boilerplate codes.

in HTML, the boilerplate codes in the interface.

<!DOCTYPE html>   
<html>   
   <head>   
      <title></title>   
   </head>   
   <body> </body>   
</html>

in C#, The boilerplate codes of properties.

class Price
{   
  private string _price;   
  public string Price
  {   
     get {return _price;}   
     set {_price= value;}   
  }   
}  

A boilerplate is a unit of writing that can be reused over and over without change. By extension, the idea is sometimes applied to reusable programming, as in “boilerplate code

Repeatable sections of code which just adds an unnecessary layer of typing to get the job done.

Are these necessary?

For the most part, these are structural and decorative markups. It provides consistency on how a code, function, language could look like.

So its kind of redundant as developers because we have seen it multiple times, but does convey some actual meaning to non-developers and compilers.

Related