Inline Variable - Refactoring skills(4)

Kerem Song·2021년 3월 23일
0

Refactoring - Study

목록 보기
6/22

4. Inline Variable(변수 인라인하기)

Remove variable which doesn't really communicate more than the expression itself.
변수 표현 자체가 원래 표현식과 다를 바가 없을 경우 혹은 변수가 주변 코드를 리팩터링하는데 방해될 경우 제거하고 인라인하기.

let basePrice = anOrder.basePrice
return (basePrice > 1000)

to

return anOrder.basePrice > 1000

Procedure

  1. Check that there are no side effects from the right side of assignment
    대입문의 우변(표현식)에서 부작용이 생기지 않는지 확인한다.

  2. If the variable is not declared immutable, test it after making it immutable.
    변수가 불변으로 선언되지 않았다면 불변으로 만든 후 테스트한다.

  3. Find the first code that used this variable and change it to the code on the right side of the assignment
    이 변수를 가장 처음 사용하는 코드를 찾아서 대입문 우변의 코드로 바꾼다.

  4. Test it.
    테스트한다.

  5. Repeat this process until you replace all the parts that use the variable.
    변수를 사용하는 부분을 모두 교체할 때까지 이 과정을 반복한다.

  6. Delete the variable declaration and the assignment.
    변수 선언문과 대입문을 지운다.

  7. Test it.
    테스트한다.

profile
Tea and Dessert

0개의 댓글