주석

코드 악취 중 하나.

방향제 또는 데오데란트

The reason we mention comments here is that comments are often used as a deodorant. It’s surprising how often you look at thickly commented code and notice that the comments are there because the code is bad. —Chapter 3, Refactoring: Improving the design of existing code

리팩토링을 해서 코드가 충분히 개선되면 주석이 상당 부분 필요 없어진다.

주석이 필요한 상황

A good time to use a comment is when you don’t know what to do. In addition to describing what is going on, comments can indicate areas in which you aren’t sure. A comment can also explain why you did something. This kind of information helps future modifiers, especially forgetful ones. —Chapter 3, Refactoring: Improving the design of existing code

관련 리팩토링

  • Extract function
  • Change function declaration
  • Introduce assertion

2024 © ak