← Home ← Codex ← DEBT ← Engine
Browse by Category
+ added · updated 7d
← Back to glossary

Lines of Code (LOC) as a Metric

Code Quality Beginner
debt(d5/e3/b3/t7)
d5 Detectability Operational debt — how invisible misuse is to your safety net

Closest to 'specialist tool catches it' (d5). Tools listed — phploc, phpmetrics, sonarqube, cloc — are specialist static analysis and metrics tools, not default linters. They can flag files >500 lines or methods >50 lines automatically, but a developer must deliberately run or configure them; misuse of LOC as a sole metric won't be caught by a compiler or standard linter.

e3 Effort Remediation debt — work required to fix once spotted

Closest to 'simple parameterised fix' (e3). The quick_fix states LOC should be used as a starting indicator alongside cyclomatic complexity, cohesion, and test coverage. Correcting the misuse means adjusting metric dashboards and team practices — a small but non-trivial change — rather than a single-line code patch. It touches team conventions and tooling config rather than a broad codebase refactor.

b3 Burden Structural debt — long-term weight of choosing wrong

Closest to 'localised tax' (b3). LOC as a metric applies across web, cli, and queue-worker contexts, but its burden is primarily on the team's measurement and review practices rather than the production codebase itself. Misusing it as a productivity proxy distorts incentives but doesn't structurally infect architecture the way a shared abstraction would; the damage is contained to process and review workflows.

t7 Trap Cognitive debt — how counter-intuitive correct behaviour is

Closest to 'serious trap' (t7). The misconception field explicitly states 'fewer lines of code always means better code' — a belief that contradicts how experienced developers know compact code can be less maintainable. The common_mistakes reinforce this: LOC is routinely misused as a productivity metric, as the only size metric, and triggers gaming behaviour (compressing statements, bloating lines). This contradicts reasonable developer intuition and mirrors how similar-sounding 'quality metrics' behave in other domains, making it a serious cognitive trap.

About DEBT scoring →

Also Known As

LOC SLOC source lines of code

TL;DR

The simplest size metric — useful for normalising other metrics and tracking growth, but a poor quality indicator when used in isolation.

Explanation

Lines of Code has three variants: physical LOC (all lines), source LOC (non-blank, non-comment), and logical LOC (statements). LOC is useful for normalising defect density (defects per KLOC) and tracking codebase growth trends. As a standalone quality metric it is misleading — a 500-line function and ten 50-line functions share the same LOC but differ enormously in maintainability. LOC is best used alongside complexity metrics (cyclomatic, cognitive) rather than as a target. Setting LOC limits per file in CI is a lightweight smell detector that flags candidates for refactoring review.

Common Misconception

Fewer lines of code always means better code. Extremely compact code can be harder to read and maintain than slightly more verbose but explicit code. LOC is a weak proxy for complexity — use it alongside other metrics, never alone.

Why It Matters

Lines of code is the simplest size metric — while not a quality metric by itself, abnormal counts (very high or very low) reliably indicate areas worth examining for complexity or laziness.

Common Mistakes

  • Treating LoC as a productivity metric — incentivising more lines produces bloated, verbose code.
  • Using LoC as the only size metric — a 50-line function with 15 branches is more problematic than a 200-line class with simple sequential logic.
  • Reducing LoC by compressing multiple statements onto one line — not an improvement.
  • Not normalising LoC by language — PHP and Java will naturally produce different counts for equivalent logic.

Code Examples

✗ Vulnerable
// 'Reducing' LoC by unreadable compression — worse, not better:
function p($u){return$u->a&&$u->v&&!$u->b?'active':($u->b?'banned':'inactive');}
// Low line count, zero readability — meaningful LoC reduction requires refactoring, not compression
✓ Fixed
// Lines of Code (LOC) is a simple but blunt metric
// Logical LOC (non-blank, non-comment) is more meaningful

// Tools to measure PHP LOC:
$ phploc src/
// Reports: LOC, LLOC (logical), CLOC (comment), NCLOC, methods, classes

// Rough guidelines (not strict rules):
// Method: < 20 LLOC
// Class:  < 200 LLOC
// File:   < 400 LLOC

// LOC alone doesn't indicate quality — pair with:
// - Cyclomatic complexity
// - Test coverage
// - Maintainability Index

// SonarQube and PHPMetrics produce LOC dashboards:
$ phpmetrics --report-html=report/ src/

Added 15 Mar 2026
Edited 22 Mar 2026
Views 80
Rate this term
No ratings yet
🤖 AI Guestbook educational data only
| |
Last 30 days
0 pings F 0 pings S 0 pings S 1 ping M 1 ping T 0 pings W 0 pings T 0 pings F 0 pings S 0 pings S 2 pings M 1 ping T 0 pings W 0 pings T 0 pings F 0 pings S 2 pings S 0 pings M 0 pings T 0 pings W 0 pings T 0 pings F 0 pings S 1 ping S 0 pings M 0 pings T 0 pings W 0 pings T 0 pings F 1 ping S
Amazonbot 1
No pings yesterday
Amazonbot 8 Ahrefs 6 PetalBot 6 SEMrush 5 Scrapy 5 ChatGPT 4 Bing 4 Majestic 2 Perplexity 2 Google 2 Claude 2 Twitter/X 2 Applebot 2 Unknown AI 1 Meta AI 1 Brave Search 1
crawler 49 crawler_json 4
DEV INTEL Tools & Severity
🔵 Info ⚙ Fix effort: Low
⚡ Quick Fix
Use LOC as a starting indicator only — high LOC signals classes worth examining, but quality is better measured by cyclomatic complexity, cohesion, and test coverage
📦 Applies To
any web cli queue-worker
🔗 Prerequisites
🔍 Detection Hints
File >500 lines; method >50 lines; class >300 lines; no LOC baseline to track growth over time
Auto-detectable: ✓ Yes phploc phpmetrics sonarqube cloc
⚠ Related Problems
🤖 AI Agent
Confidence: Medium False Positives: Medium ✗ Manual fix Fix: Medium Context: File Tests: Update


✓ schema.org compliant