Standard best practice

Standard best practice

I recently came across an interesting phrase: "standard best practice". It got me thinking "what does this actually mean?" So I did a bit of research and found the following article. I think the Dilbert comic explains it perfectly!

The difference between best practice and standard practice

Then, last week I was using a banking app and a transfer amount that I entered was changed by the app before the final submission. Let's say the value I entered was $10.84. At the point of submission it had become $10.83, i.e. one cent less. However, going back and editing the value to $10.85 results in an unchanged amount of $10.85. How could this occur? There are two possibilities: either 1. a calculation was being performed on the values I entered, or 2. the values were being converted from one format to another in an inexact way which only sometimes produced the correct result.

There's no logical reason to perform a calculation on a transfer amount and such a design flaw is usually easily caught. Let's assume that's not the case here and look instead at the second case. Computers need to know what format the data they are working on is in. Humans work with symbols, which we use as text when interacting with computers, whether they are words or numbers. So, I type the number as text but the program needs it as a numeric value. It converts the characters to a number, but since binary can't represent most fractional decimal values to the same precision, a tiny error creeps in. My value is now stored as 10.839999...

"So what?" you think, "it's close enough, and rounding will give you the original value." The problem is that a second conversion occurs, changing the final value to 10.83. One possible way this could happen is to multiply the value by 100 giving 1083.9999... and then truncating it to 1083 before dividing it again giving 10.83. These sorts of bugs are very subtle and can lurk in a system for years before being detected.

Unfortunately, this is also standard practice when handling currency amounts. It's much easier to think about currency in terms of fractional amounts of dollars, euros, rupees, etc. than as whole values of cents because we use dollars, etc. as the default units of currency in our day-to-day lives. So this is what programmers do too while they are coding. However, best practice is to handle all currency amounts as cents because there are no rounding issues when adding and subtracting (and multiplying by whole values). You now only need to handle special cases when you have fractional values of cents, which is much rarer than fractional values of dollars. The code simply needs to divide by 100 just before displaying the amount, and this is the only time currency amounts should be in dollars, i.e. discipline is required to not perform calculations on dollar amounts, only cent amounts.

This is only one example and of course there are an unlimited number of other issues that can benefit from best practices. Standard practice is relatively easy which is why almost everyone does it. Best practice is hard. Very hard. Best practice requires constant discipline from every person working on the project. It takes time to explain to each person the issues that standard practice causes and to make sure that they both understand and agree. If a contractor or someone from another team is temporarily working on your project it's important that they're on the same page as everyone else.

By definition, standard practice can never be the best and best practice can never be standard because you can't have everyone being the best at the same time. "Standard best practice" is an oxymoron; it is self-contradictory. Best practice is the optimal solution for your problem, not necessarily for someone else's. Sometimes best practice will differ on a case by case basis, whereas standard practice is always the same. Standard practice is merely good enough; it works most of the time. Best practice is when good enough isn't good enough; it needs to work all of the time.

What can you do if you are not the decision maker on your project and you spot opportunities to turn standard practice into best practice? Raise the issue to the people who are the decision makers and pass the responsibility to them. If they insist on sticking with standard practice, you've done everything you can and you have discharged your responsibility.

To view or add a comment, sign in

More articles by Daniel Klein

  • Software craftsman now on Twitter!

    I've created a Twitter account: @craftyware Follow me for my thoughts on software design and being a professional…

  • I want to be a...

    Back in January 2017, I wrote an article titled I'm sick of being a programmer. I explained that I like programming…

  • I'm sick of being a programmer

    I want to change my job title. Not my job, just how I describe myself.

    2 Comments

Explore content categories