긴 함수
코드 악취 중 하나. 긴 함수는 이해하기 어렵고, 재사용 가능성이 낮고, 불필요한 주석을 필요로 한다.
함수를 작게 나누면 생기는 문제들에 대해
실행 성능:
Older languages carried an overhead in subroutine calls, which deterred people from small functions. Modern languages have pretty much eliminated that overhead for in-process calls. —Chapter 3, Refactoring: Improving the design of existing code
파편화:
There is still overhead for the reader of the code because you have to switch context to see what the function does. Development environments that allow you to quickly jump between a function call and its declaration, or to see both functions at once, help eliminate this step, but the real key to making it easy to understand small functions is good naming. If you have a good name for a function, you mostly don’t need to look at its body. —Chapter 3, Refactoring: Improving the design of existing code
관련 리팩토링
- Extract function
- Replace temp with query
- Introduce parameter object
- Preserve whole object
- Replace function with command
- Decompose conditional
- Conditionals to polymorphism