Regardless of the library, framework, or code with which you work, you’re likely going to encounter the concept of a boilerplate at some point.
There are a handful of them for WordPress, right 🙃?
But it seems to be an increasingly popular trend that people are creating more and more boilerplates, which isn’t inherently a bad thing, but that there may be confusion as to the purpose of a boilerplate.
So, as defined by Wikipedia (which I think offers a great definition):
In computer programming, boilerplate code or boilerplate refers to sections of code that have to be included in many places with little or no alteration. It is often used when referring to languages that are considered verbose, i.e. the programmer must write a lot of code to do minimal jobs.
But notice there’s a phrase that should not be missed. Specifically:
…that have to be included in many places with little or no alteration.
And in some observations I’ve seen within the WordPress economy, at least, boilerplates seem to require that code be removed, modified, or stripped away rather than simply included or added.
That’s what I hope to clarify.
The Purpose of a Boilerplate
As defined above, the purpose of a boilerplate is, more or less, to provide code in a project that provides little-to-no alteration.
In my mind, that means it’s a foundation of code that we can drop into any project and begin building our solution. It’s a bit like a drop-in library, perhaps, except that it provides a level of functionality such as interfaces, abstract classes, and so on that we can use.
Starters
Secondly, I think that we also conflate the terms starter packages, libraries, and boilerplates such that they are all interchangeable when they really aren’t.
For example, look at Underscores. It’s meant to be a starter theme for WordPress theme development but there are plenty of aspects of it that can be stripped away when building a theme.
That doesn’t mean it’s bad. On the contrary.
But because of that, I’d argue that it is a starter theme just as they describe (and not a theme boilerplate as some refer to it) precisely for the reason above.
Libraries
Third, I view libraries are meant to be precompiled binaries or libraries that we are able to add to our project that add full functionality without us needing to write anything.
This doesn’t mean we can’t hook into them and apply them in our work because they come in various forms:
- there are libraries for styles,
- there are javascript libraries that introduce functionality,
- there are PHP libraries that handle a wide variety of things for us,
- and so on.
Depending on the nature of the language in which you’re working, sometimes libraries will be precompiled binaries that you drop into your project; other times, they may be something you add via something like Yarn or Composer.
So What is The Purpose of a Boilerpate?
In short, think of a boilerplate as a foundational level of code. It provides a consistent base for a certain type of project that should require at-most a minimal change (if any change at all).
Ultimately, it allows you to focus on the problem you’re trying to solve from the problem domain, user interface, and its experience, in a repeatable way should you need to create a similar solution in the future.
Like, you know, a plugin or something. 🙂