Code comments are arguably more important than the code itself. Here are some ways to ensure that the comments you write in your code are friendly: Comments that clearly explain what the code does are of no help to us.
To annotate reasoning and history If the business logic in your code might need to be updated or changed later, that's where comments should be left :)
Do not write long comments on the same line Nothing annoys developers more than having to drag the horizontal scroll bar to read comments. In fact, most developers simply ignore these comments because they are so inconvenient to read.
Put long comments above the logic and short comments after it. Comments can be placed next to the code if they are less than 120 characters. Otherwise, the comment should be placed directly above the statement.
Don't add unnecessary comments just for the sake of comments Superfluous comments create confusion. Maybe in school you were taught to add comments to all statements, which will help developers understand better. But this is wrong. If anyone says this, you should give him a slap in the face immediately. Code should be kept clean and concise, there is no doubt about it. If your code needs to be explained line by line, then what you need to do most is refactoring.
Notes should be spelled correctly Don't make excuses for spelling mistakes in code comments. Your IDE can check spelling for you. If it doesn't have this feature, download a plugin and do it yourself! Practice makes perfect. Try writing helpful comments and ask other developers if your comments are useful. Over time, you will learn what makes a friendly comment. We often overlook comments during code reviews. Don't be afraid to ask for more comments, you should question them. If everyone made it a habit to write good comments, the world would be a better place. Comments are a very important part of the development process, but we shouldn't comment for the sake of commenting. Comments should be useful, concise, and should complement the code. Comments should not be used to explain the code line by line, instead, they should be used to explain business logic, reasoning, and implications for the future. |
<<: Google's Android M secret weapon: built-in theme engine
>>: Learn more! A collection of iOS trivia
one iQiyi currently ranks first in the industry i...
This article reviews the 618 group buying event t...
Spinach, once left deep childhood memories for ma...
Image source: Qiantu.com If air enters the blood ...
How much does it cost to join a pregnancy and chi...
Mixed Knowledge Specially designed to cure confus...
Since the broadcast of "Kuang Bi", &quo...
Once upon a time, I was superstitious about conve...
The governor of the central bank, Zhou Xiaochuan, ...
[[417879]] Preface Design patterns are sometimes ...
Many people found that after buying a computer, t...
[[127033]] We recently released a new Swift-based...
Jiuzhaigou was hit by an earthquake. Just when th...
TCL Group, which has just released its semi-annua...
Data shows that summer traffic generally shows an...