Blog

How important are ‘Best Practices’ Really?

As the title suggests, I’m going to try and explain what I found about best practices means in the real world. And just so you know, there isn’t a single book / bible / guide of so called ‘best’ practices. Lets dig in to find out why!

Best Practices

So people have this idea, that best practice means you write your code, space it, tab it or comment it just like the best programmers in the world. All the time I hear things like;

“You use semi colons?! Well (insert name) doesn’t use them and they’re the best in the world!”.

Sound familiar? All to often when you see people better than you program, you tend to pick up on their programming mannerisms, habits and methods. Now this is a good thing, but I’d like to try and explain why this isn’t always a useful in the real world.

In The Real World

A new guy started working with you. They’re bright, switched on and aced the technical tests. You check over their first commit and find a whole bunch of weird short hand programming, one liners and convoluted code. You are then faced with three choices:

  1. Leave the code alone, and mix up two different styles
  2. Take time out of your work day and change the code
  3. Ask the developer to change everything to the way you program

Some of you may already know where I’m headed with this, but if not just hang on you’ll see my point soon enough.

When the code is mixed in, both developers have to fight with each others code because it’s not that easy to read for the other person. Taking time out of your day to constantly change someone else’s code is just never a good idea. Get the new developer to change his way of programming? Really?

Well, actually yes! Why? Because there is already a code base, and not sticking to one convention leads to confusion, and confusion leads to technical debt. Use your common sense, and adapt your code to those who work around you. Try not to change things unless you can put a compelling argument forward that holds value to doing it ‘your way’. (but it’s always good to ask why!)

Good Manners

I feel that best practices should perhaps be approached more like manners. Every culture has it’s own, and each are different from the other. Let me ask you this; Would you do something offensive to someone sat across the table from you, even though isn’t offensive in your own country? I would like to believe most people would answer “Of course not!”.

Getting back to the point at hand, I believe we should be approaching best practices much in the same way as manners. You use them situationally, and everybody has different ideas of what they consider to be ‘good manners’. In the same way, most programmers have different ideas of what they consider to be ‘best practices’. That’s why there is never a single book on the ‘best’ way to program in any language.

Take a few examples of how to write an if statement in javascript.

active && document.write("it is active"); 
//
if (active) document.write("it is active");
//
if (active) { document.write("it is active"); }
//
if (active) {
	document.write("it is active");	
}

Do me a favour, point out to me which one is best practice? Oh you can’t, that’s because there isn’t one. The thing with best practice is that it is subjective to whom ever is writing / reading / reviewing the code.

Polite Programming

Say you’ve just started a new job, you’re on a fairly skilled team of 8 other developers. You’re a mid-level developer, so skilled yourself. Then you notice straight away that none of the other developers use semi-colons to end their statements. Red flags start flying and alarm bells start ringing because everything you read in that blog, or saw in that YouTube video tells you that best practices are to end every statement with a semi-colon.

What do you do? Actually, nothing. Adopt the way THEY do things. At the end of the day, this is their house, their domain.. their company. In fact, I feel that by asking a new team your joining how they prefer to sugar their code; you will make a very good impression very early on for being aware of your team and want to play as part of one.

Which brings me to conclude a summary of what I think best practice programming should be:

Conclusion

Best practice is defined by the environment you are in. Write code that conforms to the way those you work with do. Then everybody will benefit far more from your work, yourself included.

If you find yourself looking at some code, and you can’t decide what the best practice to write it is, ask yourself this.

  1. Does it make any difference to how the code functions?
  2. Is it confusing to someone less skilled than you?
  3. Is it easy to read?
Tags

Nicholas Mordecai

Just your friendly neighbourhood programmer!

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Close
Close