-
-
Notifications
You must be signed in to change notification settings - Fork 1
Closed
Labels
Description
Summary
Deep nesting (nesting depth > 4) makes code hard to read, test, and maintain.
Current State
- 1,086 instances detected across the codebase
- Severity: High
- Detection type:
code_smell_deep_nesting
Impact
- Increased cognitive complexity
- Harder to understand control flow
- More difficult to test edge cases
- Higher bug probability
Resolution Strategy
- Early returns/guard clauses - Return early for edge cases
- Extract methods - Move nested logic to separate functions
- Use polymorphism - Replace conditional nesting with strategy pattern
- Flatten with continue/break - Reduce loop nesting
Example Fix
# ❌ Before: Deep nesting
def process(data):
if data:
if data.valid:
for item in data.items:
if item.active:
if item.type == 'A':
# 5 levels deep!
do_something(item)
# ✅ After: Early returns + extraction
def process(data):
if not data or not data.valid:
return
for item in data.items:
process_item(item)
def process_item(item):
if not item.active or item.type != 'A':
return
do_something(item)Acceptance Criteria
- Reduce deep nesting instances by 70%+ (target: <350)
- Max nesting depth of 4 in critical paths
- Code review confirms readability improvement
Related
- Part of codebase analytics cleanup (37,817 total problems)
Reactions are currently unavailable