Kenny's Blog

06 Feb 2015

Dev Word of the Day -- Boilerplate

Here’s my developer word of the day: “Boilerplate”. If you’re a new software developer or a student you’ve probably seen the word everywhere.

![Boilerplate Screenshot](/assets/boilerplate_word_screenshot.png)

But what the heck does it actually mean? Here is what Wikipedia says:

Boilerplate is any text that is or can be reused in new contexts or applications without being greatly changed from the original.

Apparently the term “boiler plate” used to refer to the sheet metal that was used to make boilers, but started to be used to reference printing press templates that were stamped in metal.

![Printing Press Boilerplate](/assets/print_press_boilerplate.jpg)

In reference to code

Wikipedia also does a pretty good job explaining boilerplate code, but if you’ve been following you should be able to guess what the term ‘boilerplate’ is referring to in a software perspective.

Boilerplate code is similar to it’s printing press cousin: it is some piece of code that can be used over and over again. There is an important difference, however. In software we seek to reduce the amount of repetitive code, mostly because it’s a pain to write and maintain. There is a pressure towards reducing boilerplate, since it often adds more work for developers. In this context, ‘boilerplate’ used in the context of code can have some negative connotations.

Take for example, a typical Java program:

    public class HelloWorld {
      public static void main(String[] args) {
        System.out.println("Hello, World");

There is some boilerplate here - setting up the class and the function requires us to write some language specific phrases. Now, let’s look at a simple android program:

    package com.helloworld.android;

    import android.app.Activity;
    import android.os.Bundle;

    public class HelloWorld extends Activity {
        /** Called when the activity is first created. */
        public void onCreate(Bundle savedInstanceState) {

A little more boilerplate in this case, since there are some extra things that need to be setup in comparison to a standard Java program. Let’s look at a simple Scala program (which runs on the JVM):

    object HelloWorld {
        def main(args: Array[String]) {
          println("Hello, world!")

One of the features of Scala is that it’s supposed to reduce the amount of boilerplate that a developer has to write. This is a very simple example, but look at the class declaration in Java: public class HelloWorld is a little longer than object HelloWorld. Similarly, the main method declaration in Java is a little longer than in Scala: public static void main(String[] args) vs def main(args: Array[String]).

Hopefully you’ve gotten a good idea what developers are referring to when they’re talking about boilerplate now - it’s a fancy word for referring to code that has to be re-used over and over again.

Some afterwords

Personally, I find it pretty fascinating how the software world has taken hold of this word and morphed it to fit a needed description. ‘Boilerplate’ used to refer to something physical, now it references something digital.

Makes you think and wonder how many words have slowly sneaked their way into the 21st century, huh?