Archives
- Newer posts
- November 2024
- April 2024
- November 2023
- October 2023
- August 2023
- May 2023
- February 2023
- October 2022
- August 2022
- July 2022
- May 2022
- April 2022
- March 2022
- February 2022
- June 2020
- March 2020
- February 2020
- January 2020
- December 2019
- November 2019
- October 2019
- September 2019
- August 2019
- July 2019
- June 2019
- May 2019
- April 2019
- March 2019
- February 2019
- January 2019
- December 2018
- November 2018
- October 2018
- September 2018
- August 2018
- July 2018
- June 2018
- May 2018
- April 2018
- March 2018
- February 2018
- January 2018
- December 2017
- November 2017
- October 2017
- September 2017
- August 2017
- July 2017
- June 2017
- May 2017
- April 2017
- March 2017
- February 2017
- January 2017
- August 2016
- June 2016
- April 2016
- March 2016
- February 2016
- January 2016
- July 2015
- June 2015
- Older posts
Did you know these coding guidelines???
Code readability is an important aspect of programming and it is one of the first things we learn as programmers.
Following are few coding guidelines every programmer should keep in mind when writing good code:
- Commenting and documentation
While coding we should follow certain standards for commenting the code and adhere to those. If we stick to a particular method of commenting the code, it helps in maintaining good knowledge of the overall working. If proper comments are placed, then, any other developer working on the same piece of code will find it much easier to understand your code. - Consistent indentation
There is no “best” style for indentation that everyone should follow. What we can conclude is, the best style is a consistent style. If you are part of a team or if you are contributing code to a certain project, you should follow the existing style that is being used in that project rather than using your own. - Avoid obvious comments
Commenting the code is a very good practice; however, it can be overdone or become redundant. When the text is obvious it is not required to be repeated within the comments. So, instead of repeating the same comment we can just combine it in a single line instead. - Code grouping
Certain tasks require few lines of code. It is always a good idea to keep these tasks within separate blocks of code, with some spaces between them. Adding a comment at the beginning of each block of code also emphasizes the visual separation. - Consistent naming scheme
Consistent naming scheme should be followed while coding. The variable names that will be used should have some relevance to the code that you are writing. This helps us in understanding the code better. Also, some language platforms tend to use a certain naming scheme. For instance, in Java, most codes use camelCase names, while in PHP, the majority use underscores. This should also be taken care of while coding. - DRY Principle
DRY stands for Don’t Repeat Yourself.The DRY principle should be maintained in every code. The same piece of code should not be repeated over and over again. Instead of each one writing the piece of code again and again, the code that is common to all can be kept in a separate file so that, everyone can make use of the same code and code redundancy can be avoided. Headers and footers are usually best candidates for this. It’s not a good idea to keep copy pasting these headers and footers into every page. Instead maintain separate header and footer file and then call them in each code file. - Avoid Deep Nesting
Many levels of nesting can make the code harder to read and follow. For the sake of readability, it is necessary to make changes in the code to reduce the level of nesting. - Code Refactoring
Refactoring means making changes to the code without changing any of its functionality. You can think of it like a “clean up” for improving readability and quality. It doesn’t include bug fixes or any new functionality. You might refactor code that you have written the day before, while it’s still fresh in your mind, so that it is more readable and reusable when you may potentially look at it two months from now.
Have I missed out any important ones? If so, you can share more guidelines from your list of guidelines.