I am not very clear about the word boilerplate when it comes to programming. How is it different to other similar terms such as template and prototype? I would appreciate some examples that clearly explain the difference.
- Anybody can ask a question
- Anybody can answer
- The best answers are voted up and rise to the top
Well, this is the meaning of the three words you asked, in a programming context:
Template: it is usually referred in web design or programming as a base you take to make your own fixes. But you do not usually use a template witouth your own fixes/changes.
Note that in the general case, template is something you take from others (posted on the Internet, for example), while prototype or boilerplate is something you make on your own.
Boilerplate has a negative connotation and refers to repetitive code that does't really contribute to the logic of the program, but is required by the language or the framework. It indicates tedium and a violation of the "Don't Repeat Yourself" programming ethos.
For example, in Java, it's common to provide getter and setter methods to access certain properties on an object. Say we want a class to represent brands of hot sauce:
This is a simple data object without any real internal logic. However, the standard practice is to provide "getter" and "setter" methods in case we want to add logic later or use the object with frameworks that make use of the getter and setter pattern:
These methods are boilerplate. They take up most of the file, yet they contain no real logic and do not tell us anything more about the HotSauce class. They are tedious to write, and are often automatically generated by the editor program.
Boilerplate can also come from a buildup of declarations that normally save effort. For example, when using the Spring framework with Java, one must declare several things at the top of every unit test class:
The declarations at the top of the file convey important information: that we want these tests to be Spring-enabled, and to be initialized in the given context with the given active profile. The Spring framework uses those lines to do a great deal of initialization, yet they are still a bit verbose, and they must be repeated at top of every test class. Thus, even though they are useful, they become boilerplate.
In the context of programming, I do not believe that boilerplate is strictly a technical term like prototype and template.
An actual boilerplate is something that was placed on a boiler. It is usually pre-printed with the exception of a serial number, boiler capacity, etc. In this respect, it is closer to a template.
With respect to programming, a template can have a very technical meaning, which usually involves a class that has some type parameters, and boilerplate is just a piece of code that is inserted verbatim (both these uses respect the non-technical meanings).
There are, of course, many definitions. As we can see in these answers, even in programming it can have different meanings. I'm here to provide a web development perspective.
The New Oxford American Dictionary (via Dictionary.app) defines "boilerplate" as follows (among other definitions, but this one applies to technology):
To me, as I put on my developer hat, it can be described as a starting point. When I hear boilerplate, I immediately think of the HTML5 Boilerplate, which describes itself as a "professional front-end template for building fast, robust, and adaptable web apps or sites." It's consists of a simple folder structure and some basic files (most importantly the feature-rich and cross-browser compatible CSS and HTML)—a very useful starting point to kick-start web projects.
Basically, these are my personal definitions in the context of the great Interwebs:
A prototype is a bare-bones version of a specific project. I may make a simple prototype of an application and include only the most important features to send to colleagues or a client to look at—a demo. We may then evaluate if and how to move forward, perhaps with the help of some UX testing.
A template is a generic file or snippet that can be used in a project—often providing some sort of structure to build upon. For example, it can be a basic home page consisting of some HTML and CSS. Or, it can be a generic resume or contract (often an NDA) that you change according to your needs. Its purpose is to save time, and the point is to not have to write it all from scratch.