Principles Are Timeless, Best Practices Are Fads
Join the DZone community and get the full member experience.Join For Free
best practices are subjective and depend largely on context, while principles are eternal and universal.
after writing the more i know the less i know , i received a few emails talking about how there are absolute best practices that should always be followed in software development.
i had already intended to write about principles, but that confusion made it clear to me that there should be a distinction made between best practices and principles. we don’t want to throw the baby out with the bath water.
looking at some examples of best practices
first let’s take a look at some software development best practices, then we’ll contrast them to principles to better get an idea of the difference.
one of the most common best practices today in software development is the idea of unit testing. i’ve written about how i have my doubts about blindly following this best practice in the past, but whether or not we should follow it , is not what i am concerned with today.
unit testing is extremely contextual. what i mean by this, is that almost anyone would agree that there are a certain set of circumstances that makes unit testing have value.
if you work in an environment where the execution of unit tests takes a really long time, or you are developing your software in a waterfall approach where you have a big upfront design and detailed requirements, unit testing starts to lose value rapidly.
but rather than get trapped into the argument of when unit testing loses its value, it is better to address when it has the highest value—we are much more likely to agree there.
unit testing has the highest value when we are working in agile environments where changes are being introduced into a software system rapidly and refactoring is taking place. it also greatly increases in utility when you are able to execute and write the tests quickly, because that feedback loop makes it much easier to write the tests in a step by step approach, especially when doing tdd.
there are plenty of other best practices that have fallen out of favor, like heavily commenting code and documenting requirements with uml diagrams, but context also greatly played a part in the value of these practices.
when most developers wrote very short variable and method names, comments were really important. before agile processes became prevalent, getting detailed requirements upfront was critical.
but, most best practices are good!
yes, you are right, most best practices do apply pretty broadly and are generally helpful in a large number of different contexts.
for example, it is considered a best practice to use a source control system and it doesn’t seem like there are many situations where this wouldn’t be the case.
so doesn’t that make it a concrete rule or a principle?
no, it is still too specific to be generally applied in all cases and the act of putting your code in source control does nothing to improve the quality of your software or software product.
if you were to blindly follow any best practice and not apply that best practice in a way that brings out the underlying principle, you would be very unlikely to actually receive any benefit.
you see, most best practices are actually derived from universally applicable principles that never change. that is why most best practices are good.
the problem is applying the best practice itself in no way assures the benefit of its underlying principle.
to put it plainly, there is something greater at work that makes it a good idea to check your code into a source control system. it is entirely possible to follow the action, but completely miss the spirit of the action.
more and more today, i see software development teams that are:
- writing unit tests
- using continuous integration systems
- using source control
- having scrum meetings
- pair programming
- using ioc containers
yet they are getting little to no benefit from it. just a bunch more pain and hoops to jump through. the reason is simple…
it’s not the best practice that is effective, it is the principle behind the best practice
principles are everywhere. they apply in all aspects of our life. you cannot go through the day without being affected by the results of 100s of different principles that have a constant influence on your life, just like the law of gravity does.
gravity is actually a great way to understand principles. as far as we know, it is a universal force that is always in effect. it is impossible to escape the law of gravity, wherever you go in the universe it affects you.
principles are like laws of nature except bigger. principles are more like the laws of reality. even though you may not be able to describe them fully or understand how they work, they always work.
take for instance, the law of the harvest. most people are familiar with this particular principle. it basically goes like this.
you reap what you sow.
how universal is this truth? how can anyone avoid it? how many times have you found yourself subject to this inescapable law about how reality works?
many software development best practices are actually based on this principle. think about best practices that have you make efforts to improve the quality of software early on in the process.
tdd or test driven development, is such a best practice. the basis of tdd is to introduce quality into the software development process as early as possible, so that the finished product is better.
if you apply the practice of tdd without understanding this principle, you are just following the motions and you won’t actually gain the benefit of the practice.
if you can’t understand at some level that the point of doing tdd is to sow some good seeds in your software that you will harvest later on, you won’t be writing the right kind of tests.
there is nothing magical about writing tests before writing code, but there is something valuable in purposely investing in upfront quality with the end goal of getting a big yield on that investment in the right season.
by the way, that is why i like bob martin’s book agile principles, patterns and practices in c# ; it discusses many principles of software development that are timeless. books like this one and the book i have mentioned probably 10 times in this blog, how to win friends and influence people , are full of principles.
also, check it out, you just learned what agile really is. with principles in mind, now read the agile manifesto . it was never designed to be a detailed process and set of best practices for developing software, it was always meant to be a recognition of a set of principles that guide software development.
so, just remember the next time you are arguing with someone over a best practice, or consider applying one to a project you are working on, if you don’t understand the underlying principle, no amount of ceremony and procedure will have the smallest amount of benefit.
Published at DZone with permission of John Sonmez. See the original article here.
Opinions expressed by DZone contributors are their own.
DZone's Article Submission Guidelines
Is Podman a Drop-In Replacement for Docker?
Microservices With Apache Camel and Quarkus