Remember just joining the work , The manager sent a project code to the group , Faced with such a big project at that time , For a few days , Everyone in the group complained that the code was uncommented , Hard to read . This is what the manager said , I remember now ：
“ You always complain that other people's code is uncommented , But have you commented on your code ?”
in truth , We want to see other people's comments , And I don't want to comment on my code . For those large open source projects , Generally, there will be good comments , The team itself is very good , Management specification , The project has a large number of users , In general, there is no lack of comments for such projects , It doesn't have to be voluntary .
I think everyone who has read the code has realized , Within its own level , Implement a function and understand others' implementation code , The latter is often more difficult than the former . Although many people say good code doesn't need comments , In itself “ Self comment ”. But you will find , People who say that , Or Daniel , Or rookie . Just the observation around us , When reading someone else's code , It is hoped that necessary comments will be made .
In most companies , Take over someone else's code , There is no necessary comment .github The person on Repositories There is a general lack of comment . Why don't they write notes ?
Because it's altruistic to write notes .
Especially company projects , It's the same person who took over the code , Compete with each other . therefore , Even if company specifications require comments , You know that , Someone will take over your project in the future , But you seldom write notes for posterity . I took over 10 Items , There is only one item with a few comments .
Annotated code has become a luxury . If you are the project leader , Rather than forcing colleagues to write notes , It's better to advocate Coding Without
Comments. When annotation is not advocated , They will write variable names more carefully , Function name . Have to admit , Good as notes , It's hard to write well . Such as difficult maintenance , When the implementation is modified , Comments often forget to sync . Some notes are vague , redundant . After a long time , No one can understand what this note means . so , Even if you want to write notes , Try to be concise .
Writing comments is the same as writing code , It's Art . (2016/4/1)