Best practices for programming

In this article, we will talk about best practices for programming in any language.

  • Add readability to your code as much as possible.
  • The function name should tell what this function does.
  • One function should do one thing and that thing properly.
  • Logging is very important.
    • You should choose the level of logging very wisely. A lot of logging will make your application slow.
    • Less logging you may miss out required info for debugging.
  • Failures are normal. Fail as early as possible and as loud as possible.
  • Metrics provides you with a way to keep track of what your code is working with respect to how it was working earlier.
  • Try to structure your code in such a way that if you want to add something new you can do it in minimum effort.
  • Documentation is very important. Try to document project you are about to build in advance this will make your thought clear about what you are going to make and how you will achieve it.
  • Comment wherever is necessary. Your comments will help the person who will take over code to understand it easily.
  • Your program should be config driven. Don’t hardcode anything in your code.
  • Test cases are very important.
    • You will have confidence in your code and less bug will go to production.
    • Edge cases are important to consider.
    • There are people who actually do test-driven development. This means they write the test case first for what they want to achieve and then they write the code for it.
  • Always think that your software may need to interact with other software in the future so write it in a way that others can interact with it.

These are a few pointers you can use to write good code in any programming languages. If you want me to add more please mention in comments and I will add them.


Gaurav Yadav

Gaurav is cloud infrastructure engineer and a full stack web developer and blogger. Sportsperson by heart and loves football. Scale is something he loves to work for and always keen to learn new tech. Experienced with CI/CD, distributed cloud infrastructure, build systems and lot of SRE Stuff.

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.