When I became a full-time developer, I determined to be the best developer I can be. I set out to learn what best-practice means in my chosen profession, and then to learn to apply it to my practice. Thus far, it has been an interesting and largely enjoyable journey.
Of course, I’ve made some fundamental mistakes. One reason for this is that different developer’s ideas of what best-practice actually means is often quite different. Another is that best-practice is often assumed applied on a one-size-fits-all basis.
One way through this morass is to understand the principles on which best-practice is founded. One of those principles is that best practice must be determined by your overall purpose. Today, I came across an article by Eric Lippert that sums up our purpose as well as anything I’ve come across up to this point:
The purpose of code is to create value by solving a business problem. Eric Lippert
Best practice, then, is that which most effectively enables us to add business value. However, different software projects add value to the business in different ways. For example, a one-off data conversion is very different from an OLTP application, which is in turn very different from an overnight batch job. For this reason, best-practice will vary between different projects.
Going a little deeper, Lippert identifies 3 areas in which code displays fitness for purpose:
- Good code is code which “works correctly according to its specification to actually solve the stated problem”
- Good code “communicates its meaning to the reader who needs to understand its operation”
- Good code “allows for relatively low-cost modification to solve new problems as the business environment changes”
The relative importance of these 3 areas can vary between projects. A quick throw-away data conversion script needs to be functional, but less emphasis can be placed on modification and readability. On the other hand, an application like Microsoft Word will be worked on by many developers and maintained through numerous development cycles. As such, readability and maintainability need to be emphasised more than providing every possible bell and whistle that would benefit a very small minority of your customers.
In summary, then, best practice is any practice that adds business value by balancing requirements for functionality, maintainability and adaptability. Knowing this, we can evaluate the applicability of any so-called “best” practice in the context of our own situation,