"매 control flow 가 noodle 처럼 entangled 되어 trace 불가". 매 unstructured GOTO · deeply nested conditions · global state mutation · circular dependency 가 만든 maintenance nightmare. 매 SOLID 위반 의 most visible symptom.
매 핵심
매 증상
Tangled control flow: 함수 한 개가 500+ lines, nested if 5+.
Global state: any 함수 가 any 변수 mutate.
Circular dep: A→B→C→A.
Magic numbers/strings: meaning unclear.
Copy-paste: same logic in 7 places.
매 원인
Time pressure → "just make it work".
No code review → drift 누적.
Premature optimization → unnecessary complexity.
Lack of architecture → ad-hoc additions.
매 응용 (refactor 전략)
Extract method · extract class.
Replace conditional with polymorphism.
Introduce parameter object.
Strangler fig migration.
💻 패턴
Before (spaghetti)
functionprocessOrder(o: any){if(o.type=="A"){if(o.user.isVip){o.discount=0.2;if(o.country=="KR")o.tax=0.1;elseif(o.country=="US")o.tax=0.07;// ... 200 more lines
}}}
// before: 1 huge function
// after: 5 small functions, each <20 lines, single responsibility
functioncheckout(cart: Cart){validateCart(cart);consttotal=calculateTotal(cart);consttax=applyTax(total,cart.country);returnsubmitPayment(cart.user,total+tax);}