Skip to content
Sarj Code Standards

no-magic-arithmetic

Name nontrivial numeric factors and operational limits.

Why

Unnamed conversion factors, frame sizes and timing limits hide units and can drift across related operations.

Fix

Extract a meaningfully named constant or use validated configuration. Reuse an existing constant when it represents the same unit or limit.

Examples

Before — flagged The contract is implicit
app/service.py
def normalize(sample):
return sample / 32768
After — preferred The contract is explicit
app/service.py
PCM16_SCALE = 32_768
def normalize(sample):
return sample / PCM16_SCALE