Tip #3: Always ensure you have high comment to code ratio, the more comments the better!

Tip #3: Always ensure you have high comment to code ratio, the more comments the better!

In the best cases, the comments can constitute 50% or more of your code, and that would be a good thing. The code is read more often than it is written, so explain every line of code with a comment so the next developer can understand it well.

We do not write code in English (yet!) but in a language specifically designed for computers. Computers are better suited to understand it than humans. Code can be cryptic, unintuitive, and difficult to understand. Code also changes behavior with time, like a “getEmployee” method that also has to create an employee! How can you convey that in code!? Comments bridge that gap in human understanding. Comments explain to other developers what the code is trying to do. Verbose comments will allow developers to maintain the code better.

Some developers think that only code is important and maintain it. Comments, like code, need to be maintained. They should be updated every time the code changes to ensure they are in sync. Many people add new lines of code between the comment and the code the comment explained; this ‘misplaces’ the comments, confusing developers and causing bugs.

Different coding languages use different ways to denote a function or class. So it helps to add informative markup comments like --start function-- and --end-- or // if ends here.

It always helps to say the same thing twice. It always helps to say the same thing twice. It ensures the point is conveyed. Updating code is already a task, but making it human-readable is an additional one. Comments are a good shortcut!

The developers who have dealt with uncommented code, which is difficult to understand, will realize the truth in this!

Do you want to be the most important person on your team? The only one who can save your company in a coding crisis? The one person no production issues can be resolved without? Someone who will be called upon even in the middle of the night to help their company out? Follow the hashtag#100WaysOfCodingChaos hashtag#CodingChaos series for more such awesome advice.

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.