CHAPTER 2 Writing Maintainable, Future-Friendly Code
foRKing ThiRD-PaRTY CoMPonenTS
After you’ve selected some third-party components for your Web applica-
tion you may find that they don’t quite do everything that you need. At
that point, you have a decision to make. You can either start your search
again for a new component or you can try to make this component work
the way you need it to. Unfortunately, many developers tend to take the
latter approach which means forking the original code. Forking is any
activity where the third-party component is modified by someone other
than the maintainer. It doesn’t matter if you are adding a new function,
removing an existing function, or changing existing functionality, all of
these are considered forking.
Forking a third-party component is a bad idea. By doing so, you ensure
a non-linear upgrade path for that component. Upgrading the component
should be as simple as removing your current file and dropping in a new
file. Sometimes the component API will change slightly and so you will
need to adjust your code accordingly. Good components, however, mini-
mize this type of occurrence. A drop-in upgrade is considered linear.
A non-linear upgrade path is one where dropping in the new version is
only the start of the upgrade. You then have to trawl your code and make
appropriate fixes for the new version. If you have forked the component,
then you dramatically increase the likelihood of a non-linear upgrade
path. There are all kinds of different issues that can arise. For example, you
might have added a new method on the component only to find that the
next official version of the component has a function with that name that
does something different. That means not only do you need to change the
name of your function, but you also have to change all the places where it’s
used in your code.
When you decide to use a third-party component, it’s best to avoid
forking it in any way. Preserving a linear upgrade path is very important
for these components. Remember, the whole point of using a third-party
component is to eliminate maintenance overhead.