When I became a full-time developer I determined to learn what constitutes best-practice in my profession and 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 on the way. One source of error has been difficulty in determining what constitutes best practice in the context of the projects I’m working on. Clearly, best practice in any endevour 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.
Best practice, then, is that which most effectively enables us to add business value. Not all code adds value in the same way, so best practice will vary between projects.
In the same article, 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 script that is used by a single develpoper 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 as much as correct fuctionality.