๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ

๋นˆ ๊ตฌ๋ฉ ์ฑ„์šฐ๊ธฐ

[ํ”„๋กœ๊ทธ๋ž˜๋ฐ] ์ฃผ์„ ์“ฐ๊ธฐ ํŒ

https://stackoverflow.blog/2021/07/05/best-practices-for-writing-code-comments/

 

Best practices for writing code comments - Stack Overflow Blog

While there are many resources to help programmers write better code—such as books and static analyzers—there are few for writing better comments. While it's easy to measure the quantity of comments in a program, it's hard to measure the quality, and t

stackoverflow.blog

 

 

Rule 1: Comments should not duplicate the code.

์ฝ”๋“œ์„ ๋ณต์‚ฌํ•ด ์ฃผ์„์— ์จ์„œ ์ค‘๋ณต๋˜๊ฒŒ ํ•˜๋ฉด ์•ˆ๋œ๋‹ค.

 

Rule 2: Good comments do not excuse unclear code.

์ข‹์€ ์ฃผ์„์€ ๋ถˆ๋ถ„๋ช…ํ•œ ์ฝ”๋“œ๋ฅผ ๋ณ€๋ช…ํ•˜์ง€ ์•Š๋Š”๋‹ค.

 

Rule 3: If you can’t write a clear comment, there may be a problem with the code.

์ฃผ์„์„ ๋ช…ํ™•ํ•˜๊ฒŒ ์“ธ ์ˆ˜ ์—†๋‹ค๋ฉด ์ฝ”๋“œ์— ๋ฌธ์ œ๊ฐ€ ์žˆ์„ ์ˆ˜ ์žˆ๋‹ค.

 

Rule 4: Comments should dispel confusion, not cause it.

์ฃผ์„์€ ํ˜ผ๋ž€์„ ์—†์• ์•ผ์ง€ ์•ผ๊ธฐํ•ด์„œ๋Š” ์•ˆ๋œ๋‹ค.

 

Rule 5: Explain unidiomatic code in comments.

๋น„๊ด€์šฉ์  ์ฝ”๋“œ(ํ†ต์ƒ์ ์œผ๋กœ ์ž˜ ์“ฐ์ง€ ์•Š๋Š” ์ฝ”๋“œ)๋Š” ์ฃผ์„์œผ๋กœ ์„ค๋ช…ํ•˜๋ผ

 

Rule 6: Provide links to the original source of copied code.

๋ณต์‚ฌํ•œ ์ฝ”๋“œ์˜ ์›๋ณด ๋งํฌ ํฌํ•จํ•˜๊ธฐ

 

Rule 7: Include links to external references where they will be most helpful.

๋„์›€์ด ๋ ๋งŒํ•œ ์™ธ๋ถ€ ์ฐธ์กฐ ๋งํฌ ์ฒจ๋ถ€ํ•˜๊ธฐ

 

Rule 8: Add comments when fixing bugs.

๋ฒ„๊ทธ ์ˆ˜์ • ํ›„ ์ฃผ์„ ๋‹ฌ๊ธฐ

 

Rule 9: Use comments to mark incomplete implementations.

๋ถˆ์™„์ „ํ•œ ๊ตฌํ˜„ ํ‘œ์‹œ๋ฅผ ์ฃผ์„์œผ๋กœ ํ•˜๊ธฐ