Many of us agree that best practices are generally good and that it helps produce quality code, easier to maintain code, etc. But what aspect of the best practices gives it this characteristic?
I’d like to answer that with an analogy. Imagine you are driving uphill on a two way traffic street. Single lane on each side, separated by just a painted line with no physical median separating the bi directional traffic. You can’t see the oncoming traffic until after it’s too late to avoid an accident. Yet, we manage to drive without accidents time and again. As long as everyone does what is expected of them- driving on the correct side of the traffic indicated by the painted line- everything is fine and everyone is safe.
In software programming, how do we know what is expected of us to keep things moving smoothly? The best practices fills that gap. It is not just the generally accepted practice, it is also the generally expected practice. When we see a hint of a design pattern in the code, such as a class named after singleton, factory or visitor, or expressing the intent of the code in a test, or naming a variable to indicate its purpose, we know what to expect from that point on. It also increases our confidence and comfort level with that code. Once we are comfortable with the code, we are also more likely to attend to and refactor any ailing code, reducing the technical debt and improving the overall health of the system.
In the fast paced world with aggressive timelines, we could avail the help of anything to save us some time and increase our productivity. Best practices is one of the things that can help us.