Importance of Using Best Coding Practices.

Navoda Nilakshi
The Startup
Published in
5 min readNov 10, 2020

I’m gonna start out with a famous quote:

“Any fool can write code that a computer can understand. Good programmers write code that humans can understand.” — Martin Fowler

To be honest, whatever I might say, I can’t stress this enough. Writing a working code is clearly not enough nowadays. Code quality plays a vital role in making your project stand out from the rest. Following up with best practices in the industry and maintaining a standard in your code can help you and your teammates, both current and future, when working collaboratively. Let’s dig into some coding standards that you should give a thought to incorporate when you code along. Also, these informal rules are independent of the language you use. Therefore I haven’t used examples from source code which can obstruct some readers from yielding the maximum benefit from this article.

  1. Less and simple code.

Golden rule here is to “Think more and code less”. When you’re coding you’re bound to come across instances where you can simplify your chunks of code to make it more clean and simple. Here are few ways by which you can achieve it:

  1. Refactoring — This feature is provided by many text editors including Visual Studio Code, IntelliJ, Eclipse, etc. This is helpful especially when you want to restructure your code in a more readable manner without hindering the output. Refactoring can make bug fixing more easy as well.

2. Using OOP / basic concepts when possible — This makes it easier to maintain codes, makes it easier to add any future changes without consuming much time and to eliminate duplicated code fragments. Let’s make it clear with an example:

Eg: If you use inheritance concept, it allows you to reuse code fragments and thus prevents code redundancy. This is possible because all the recurring data members and functions can be included in parent class. As these are inherited into child classes, we don’t have to repeat them again.

You can use Abstraction concept in OOP to reduce the complexity of an application by hiding unnecessary details from the end user.

3. Using design patterns — Use of design patterns makes communication between software designers easy. Also, these design patterns make the system less chaotic and makes it easier to maintain. Design patterns are reusable and they add a pinch of transparency into the design of application.

4. DIE: Duplication Is Evil. Duplicated lines of code can make your project unnecessary long and bulky and can make it hard to review the code. It’s a best practice to avoid code duplication whenever possible and define functions if operations need to be duplicated.

5. Give functions/classes one purpose — This can lessen the headache you get when you read through code lines of some functions which have thousands of lines of codes to do hundreds of tasks. One function performs only one action and a class has single responsibility.

2. Readability > Cleverness

Many programmers conflate “clean code” with “clever code”. They are tempted to think that if they can squeeze 10 lines of codes into one line using some clever trick, it’s cleaner. But more often than not, it’s not the case. Cleverness is solving puzzles and not creating more. Readability is equally important to less code and here are few points that you should keep in mind while you’re coding to make your code more readable to other parties.

  • Commenting saves many headaches! — Comment is a programming language dependent specially marked text which explains the source code. Adding comments makes the code more readable and also helps in bug fixing. But the bottom line is too much commenting makes your coding standard decrease. You’re not supposed to add comments for each line of source code or for obvious parts of the code. Remember, comments are for clarification and not for spoon-feeding. There are three main types of comments in most languages: in-line, multi-line and documentation comment.
  • Maintaining proper indentation — Having necessary parts of the code indented is a mandatory requirement in some programming languages such as Python. But it’s always a good idea to use indentation because it makes your code readable as it visually represents loops and selection statements.
  • Using whitespaces when necessary — Do you like reading bunched-up, smashed together code? Well, the most common answer is no. Actually, adding whitespaces is soothing to the reader’s eyes and doesn’t require much effort. This is one of the most underrated practices and is highly powerful.

3. Use naming conventions and maintain a consistent naming scheme.

Using meaningful and descriptive names when naming data members and methods is something which is commonly overlooked but very important. This is really helpful when someone else is referring to your code.

4. It’s advisable to avoid long lines of code as much as possible.

You can use styling and indentation to your advantage when dealing with lengthy lines of codes which can be exhausting to read.

5. Avoid deep nesting.

Nested loops are frequently (but not always) a bad practice because it can make your code less reader friendly and can invoke unexpected results. Likewise using too much if statements is a bad code smell and might require refactoring.

6. Maintain folder structures.

Whether in coding or in real life, organisation is important in everything that we do. Organisation makes coding and reviewing more efficient and enjoyable.

7. Review your code regularly.

Remember your job is not done with the last semicolon. You have to review your work often to maintain it and to improve it. You’ll gain a lot of experience when you go ahead with the project so it’s always advisable to use that expertise to make initial codes to that standard as well.

8. Use industry principles.

Use of design principles like the SOLID principle reduces dependencies and thus make it possible to change parts of your code later without messing up with your entire system by making it more adoptive. So it’s a very underrated coding practice which you can use to make your code function at its best.

9. Using code smell tools such as Checkstyle, ESLint, Findbug.

10. Document everything.

Yes you heard it right! Make it a point to properly document everything related to your software application development from Readme Texts to Design notes and Decision documents. This will make your life a lot more easier in the long run.

11. Keep an eye for security concerns related to software development.

Always use encryption, data loss prevention and other information security techniques if your system deals with sensitive information from your client. Always remember “Prevention is better than cure”.

It’s time to roll up your sleeves and write some clean cut code. Cheers!

--

--