"매 function 의 linearly independent path 수". Thomas McCabe (1976) 가 정의. 매 control-flow graph 매 M = E − N + 2P (edges − nodes + 2×components). 2026 현재 ruff, eslint, SonarQube 매 default 로 측정; high CC ↔ test difficulty + bug rate correlation 매 empirical.
매 핵심
매 계산
각 decision point (if, for, while, case, &&, ||, ternary, catch) 마다 +1.
Base 1 (single path) + decisions.
Function 1 → straight-line.
Function 10+ → moderate.
Function 20+ → complex, refactor 권장.
Function 50+ → 매 unmaintainable.
매 의미
Test path 수 lower bound.
Reading difficulty proxy.
Bug density correlation — 매 empirical study.
NOT measure of correctness, performance, design quality.
매 응용
CI gate — max-complexity: 10 lint rule.
Code review — high-CC function 매 split 요청.
Refactoring target prioritization.
Legacy modernization metric.
💻 패턴
CC 계산 example (Python)
defclassify(score):# base 1ifscore>=90:# +1return'A'elifscore>=80:# +1return'B'elifscore>=70:# +1return'C'else:return'F'# CC = 4
// before — CC 5
functionarea(shape: Shape):number{if(shape.kind==='circle')returnMath.PI*shape.r**2;if(shape.kind==='square')returnshape.s**2;if(shape.kind==='rect')returnshape.w*shape.h;if(shape.kind==='triangle')return0.5*shape.b*shape.h;thrownewError('unknown');}// after — CC 1 per class
abstractclassShape{abstractarea():number;}classCircleextendsShape{area() {returnMath.PI*this.r**2;}}classSquareextendsShape{area() {returnthis.s**2;}}
Refactor: guard clauses (early return)
# before — CC 4defprocess(user):ifuserisnotNone:ifuser.active:ifuser.has_permission:do_work(user)# after — CC 4 still, but readability ↑defprocess(user):ifuserisNone:returnifnotuser.active:returnifnotuser.has_permission:returndo_work(user)
Refactor: table dispatch
# before — CC 6defhandle(event_type,payload):ifevent_type=='created':returnon_created(payload)elifevent_type=='updated':returnon_updated(payload)elifevent_type=='deleted':returnon_deleted(payload)# ...# after — CC 2HANDLERS={'created':on_created,'updated':on_updated,'deleted':on_deleted}defhandle(event_type,payload):handler=HANDLERS.get(event_type)ifnothandler:raiseValueError(event_type)returnhandler(payload)
radon (Python CLI)
$ radon cc -s -a app/
app/service.py
F 42:0 process_order - C (12)
F 88:0 validate - A (3)
Average complexity: B (6.2)