The Art of Commenting in Programming

Two Viewpoints
1. We don't need Comments! The Code itself should be Self-Documenting

2. Comments are helpful! We should write them as mush as we can!

Two Reactions
1. Most of the Time code can  Describe How, but it cannot Explain Why!

2. You can Remove Comments by Rewriting the Code to be more Legible

Correct Approach
Write Code to be more Readable and Legible as you can. And also, use comments to give readers valuable information which they can find in the Code.

Readable Code: Best Practices
▪Meaningful Identifier Name
▪ Consistent Naming Scheme
▪ Consistent Indentation
▪ Limitation of Line Length
▪ Proper Use of Whitespace

The Good
/*
We had to write this function because the browser interprets that everything is a box
*/
    function manipulateElement(){
...
}
    "That Comment reveals the Reason"

The Bad
// Fetches the data and stores it in a Variable

"let a = b();"

"It can easily be removed by proper identifier names"

The Ugly
//Calculate annual Expenses

   let amount = annualIncome();

"Inconsistency, Probably a Wrong and Obsolete Comment"

Comments

Popular posts from this blog

FrontEnd Courses

ActiveX

How to Type Faster