"매 code 의 surface 의 sign 의 deeper problem". Martin Fowler 의 catalog. 매 syntax 의 OK 가, 매 design 의 ill. 매 refactoring 의 trigger. 매 modern: 매 SonarQube / Semgrep / AI review 의 자동 detect.
📖 핵심
매 Fowler 의 6 category
1. Bloater
Long Method: 매 single function 의 거대.
Large Class: 매 god class.
Primitive Obsession: 매 string / int 의 abuse.
Long Parameter List: 매 4+ parameter.
Data Clump: 매 같이 쓰이는 data 의 group X.
2. OO Abuser
Switch Statement: 매 polymorphism 의 missed.
Temporary Field: 매 일부 case 만 의 사용 field.
Refused Bequest: 매 inherit 가, 매 일부 의 X.
Alternative Classes with Different Interface: 매 same job, 매 다른 method name.
3. Change Preventer
Divergent Change: 매 1 class 의 매 다른 reason 의 수정.
Shotgun Surgery: 매 1 변경 의 매 N class 의 수정.
Parallel Inheritance Hierarchies: 매 두 hierarchy 의 동시 의 grow.
4. Dispensable
Duplicate Code (DRY violation).
Lazy Class: 매 도움 X.
Data Class: 매 anaemic (case-by-case).
Dead Code: 매 unused.
Speculative Generality: 매 hypothetical 의 design.
Comments: 매 reason 의 explain 의 X 의 case.
5. Coupler
Feature Envy: 매 method 의 다른 class 의 더 사용.
Inappropriate Intimacy: 매 internal 의 over-share.
Message Chain: a.b().c().d() 의 chain.
Middle Man: 매 delegation 만.
6. Other
Mysterious Name: 매 unclear identifier.
Magic Number: 매 unnamed constant.
Insider Trading: 매 inappropriate field access.
Incomplete Library Class.
매 modern addition (Fowler 2nd ed)
Mutable Data.
Global Data.
Loops (Stream / functional 의 lieu).
Repeated Switches.
매 detection
Manual review.
Linter: ESLint, RuboCop, Pylint.
SAST: SonarQube, CodeClimate.
Semgrep: 매 custom rule.
AI review: CodeRabbit, Greptile.
매 refactoring (corresponding)
Extract Method: Long Method.
Extract Class: Large Class.
Replace Conditional with Polymorphism: Switch.
Move Method: Feature Envy.
Hide Delegate: Message Chain.
Introduce Parameter Object: Long Parameter / Data Clump.
// ❌
classOrder{total(customer: Customer){// 매 모든 logic 의 customer 의 사용
returncustomer.discount*customer.tax*...;}}// ✅ Move to Customer
classCustomer{applyDiscount(amount: number){returnamount*this.discountRate;}}
# 매 long parameter list detectionrules:- id:long-parameter-listpattern-either:- pattern:function $F($A, $B, $C, $D, $E, ...) { ... }message:"Function has 5+ parameters — consider Parameter Object"severity:WARNINGlanguages:[typescript, javascript]
SonarQube quality gate
# 매 cognitive complexitysonar.javascript.cognitive-complexity-threshold=15# 매 duplicate thresholdsonar.cpd.minimumLines=20sonar.duplicatedLines.maximum=3.0
AI review (CodeRabbit)
# .coderabbit.yamllanguage:enreviews:profile:chillhigh_level_summary:truepoem:falseauto_review:enabled:truedrafts:false# 매 auto-detect: long methods, missing tests, complexity, etc.
Refactor metric (cyclomatic complexity)
# 매 radon (Python)
radon cc src/ -a -nb
# 매 ESLint complexity ruleecho'{ "rules": { "complexity": ["error", 10] } }' > .eslintrc.json
Bobby tables (refactor cadence)
# 매 boy scout ruledefvisit(file):ifneeds_change(file):# 매 main changedo_main_change()# 매 small refactor (touching area)ifhas_smell(file):small_refactor()
🤔 결정 기준
Smell
Refactor
Long Method
Extract Method
Large Class
Extract Class
Primitive Obsession
Value Object
Long Parameter
Parameter Object
Duplicate
DRY (Extract)
Switch
Polymorphism
Feature Envy
Move Method
Data Clump
Class
Comments (bad)
Rename / Restructure
Magic Number
Named Constant
기본값: 매 fix-as-you-touch + 매 priority queue (changing area).