3 Timeless Principles of Quality Code

Coming back to the good old question, “What does it mean to write good quality code”?

Madhav Bahl
The Lean Blogs
5 min readJul 25, 2019

--

Different people have different perspectives on what all conditions must your code satisfy before you can call it good code. And to be honest, it’s a personal viewpoint, I might have my own checklist of things to follow while writing code, you might have your own!
So in this short blog, I am going to write about the 3 things which I consider to be very important when it comes to the code quality. Hope you like it!

Why go back to this timeless question?

Earlier this evening a friend of mine asked me “Hey Madhav, how to know whether my code is good? Do give me some tips on that and tell me some good coding practices!”

Again, as I said above, the answer depends on person to person and company to company. There is no universal set of guidelines that you can follow and then say that “Yes, my code is the best, no one can write better code than me”.

But then again, there are some things which must be satisfied if you are aiming for code quality which I call the “3 Timeless Principles of Quality Code”. No don’t confuse it with the coding practices, there are tons of coding practices which one can follow, in this blog, I am going to talk about 3 coding principles which (according to me) are essential for good code.

P.S. If you are interested only in the good practices, I have another article for you guys, go have a look —

Alright, so let’s move on to the main topic!

The 3 Timeless Principles of Quality Code

My summer internship was quite an awesome learning experience, special thanks to my mentor who used to tell me some good practices and through his pieces of advice, I was able to figure out these things, which I am sharing with you all today. Keep these principles in your mind while coding!

1. Readability

A very important aspect while writing code is to keep in mind that you are not going to work on that same project throughout your life. Someone else will be given the job to take the project forward, or improve it, or add some feature in it. So please keep in mind that to do anything with that code, he will have to read it, and if the code is not readable, he is going to curse you! Just kidding, he might not curse you, but put yourself in his condition where you have to understand a code which is not at all readable, bad trip right? So don’t let anyone else experience it.

Photo by Chris Ried on Unsplash

Although you might find many tips on how to make your code more readable when you search on google, some tips from my side would be

1. Proper comments and documentation
2. Proper indentation
3. Follow style guides
4. Keep your code DRY
5. Avoid Nesting
6. Meaningful variable names
7. Proper project directory structure
and so on…

2. Scalability

This is the most important principle of quality code. For any application you develop, it is an important aspect that how well can it be scaled. Even if the application you are working on has a very small user base, you never know the number of users might increase significantly in the future! At that point of time if your code fails to run efficiently you can’t make an excuse that “This piece of code runs only for a hundred users at a time”.

Therefore, it is highly essential to keep in mind the scalability of code while writing it. Again you will find tons of resources on google on how you can make your code more scalable, but I would also like to give one advise — optimize your code in such a way that space and time complexity is minimized.

Source: Google Images

Read more about code scalability here.

3. Maintainability

Maintainable code is code that exhibits high cohesion and low coupling. Cohesion is a measure of how related, readable and understandable code is. Coupling is a measure of how related code is, low coupling means that changing how A does something shouldn’t affect B that uses A. Generally lower coupling means lower cohesion, and vice versa, so a developer need to find an appropriate balance between the two.
Source: softwareengineering.stackexchange.com

As I mentioned in the first principle, you are not going to be coding on your project forever, someone else will take it over. Once the project is complete, your code must be easy to maintain, modify or update. So make sure you write code that can be easily understood, modified and tested.

That’s it! Hope you found the article helpful and gained some insights on the principles of quality code.

Feel free to reach out to me anytime if you want to discuss something :D

I would be more than happy if you send your feedbacks, suggestions or ask queries. Moreover, I love to make new friends and we can be friends, just drop me a mail.

Thanks a lot for reading till end. You can contact me in case if you need any assistance:
Email: madhavbahl10@gmail.com
Web:
http://madhavbahl.tech/
Github:
https://github.com/MadhavBahlMD
LinkedIn:
https://www.linkedin.com/in/madhavbahl

--

--

Madhav Bahl
The Lean Blogs

I help 90,000 students and software professionals enhance their lifestyle, stay fit and grow in career 🚀