Good Coding Practices I wish I had known sooner

A gateway to developing good quality, maintainable and scalable firmwares and softwares.

Nandan Ghawate
4 min readMar 30, 2023
Photo by Marvin Meyer on Unsplash

For a long time, my codes/programs looked like a disaster movie directed by a toddler with a keyboard - one single main file with thousands of lines of code (and hundreds of lines of redundant stray code), long and complex functions with a lot of hardcoded values and almost no comments. Don't even get me started on the lack of documentation! Everything was working great until I had the opportunity to sell the first ever product (intellectual property) I designed. I had to conduct a knowledge transfer session for the other party and that is when I explored and learned the importance of good coding practices and documentation which have helped me in developing quality, maintainable and scalable firmwares and softwares.

Lets go through some of the coding practices which have helped me and I continue using:

Follow Coding Standards :

I was fortunate enough to stumble upon Google Coding Style Guidelines and those have been my favourite coding standards ever since.

  • Coding standards are some specific guidelines to writing a code in a particular programming language.
  • There are a lot of coding standards you can follow, and many times you may find yourselves following different guidelines and maybe eventually making your own set that you follow but it is always suggested to follow only one style.
  • Some of the other popular coding standards for different languages and domains include MISRA-C for C and C++, Embedded C Coding Standard by Barr Group, PEP8 for Python, PSR1 & PSR2 for PHP, etc.

Use Version Control :

When a dear friend of mine introduced me to GIT, honestly I thought of it as waste of time and a hassle (I would rather create copies). Today, I would fight tooth and nail to defend the use of version control.

  • A version control is a system that helps developers to maintain and manage changes to the codebase over the time.
  • Version control system also allows collaboration, tracking changes and reversion to previous versions of code.
  • Some of the other popular version controls include Subversion (SVN), Mercurial, Perforce etc.
  • There are various platforms like Github and Bitbucket which provide hosting for Git repositories and support for Git client. A Git Client is a software application that provides a graphical or command-line interface for interacting with Git repositories and perform Git related tasks. More details about git usage can be found at https://git-scm.com/.

Keep Code Modular :

For a long time I avoided creating modular code and custom libraries for different projects, it was a combination of fear and laziness. But with proper guideline I started creating modules and custom libraries for every project which made my projects easier to understand, test, debug, modify and also to reuse.

  • Creating a modular code involves breaking down long, complex logic into smaller, independent modules or functions. Creating a modular code helps in cleaning the redundancies out of code when needed.
  • Creating libraries is a key aspect of keeping code modular. Libraries are collections of pre-written code that can be reused in multiple projects, providing a standardised set of functionality that can be easily integrated into different applications.

Document Your Code :

Someday you’ll have to maintain or debug a code that you wrote long ago, and the only entities who understand it are your past self and God. So, good luck with that! Maybe you can try praying to the coding gods for help. Or you can document the code from the start!

  • Documenting code involves adding comments, documentation, and other metadata to the codebase.
  • A Clear, concise, and consistent code documentation helps in debugging, maintenance, and scaling, not to mention that it helps in conducting proper knowledge transfer.

In addition to the coding guidelines discussed above, I have recently started focusing on code optimisation during alternate commits. Commits refer to a snapshot of the code at a specific point in time, which is saved in a version control system like Git. By optimising the code during alternate commits, we can reduce resource usage and improve application performance, resulting in faster, more efficient, and more scalable applications.

Another important coding practice is creating test cases on the go. This involves creating tests alongside the code as it is being developed, which helps in identifying and fixing defects and issues before they become major bugs. By reducing debugging time and ensuring the code works as expected, creating test cases can improve the overall quality of the software or firmware.

Key Points of a Good Code. Image by author.

“Even though our codes will eventually become obsolete and replaced by new technologies and languages, the good coding practices that we pass on will remain timeless. By sharing our knowledge and experience, we can help to ensure that future generations of developers continue to build upon a strong foundation of good coding practices. In this way, we can contribute to the ongoing growth and evolution of the firmware and software development industry, and help to create a better future for all.”

Thank-you for reading !

--

--

Nandan Ghawate
Nandan Ghawate

Written by Nandan Ghawate

Electronics Product Designer | Project Manager | Embedded Systems | Internet Of Things (IOT) | Battery Management Systems (BMS)

Responses (1)