🧮 Code Readability / Complexity Estimator

Paste any code snippet to get a rough, heuristic read on its cyclomatic complexity, nesting depth, comment ratio, and overall maintainability — a quick gut-check, not a substitute for a real static analysis tool.

📄 Paste Code Snippet
📊 Complexity Estimate
Maintainability Rating
Lines of Code
Comment Ratio
Cyclomatic Complexity
Avg Line Length
Max Nesting Depth
Detected Indent Width
Key Metrics at a Glance
⚠️ This is a lightweight, regex/text-based heuristic — not a real AST-based static analysis tool. It cannot understand language semantics, string/comment context perfectly, or actual control flow. Use dedicated tools like ESLint, SonarQube, or radon for accurate, language-aware analysis. Nothing you paste here is transmitted, logged, or stored — all analysis runs locally in your browser.
🧩

Paste a code snippet to see its complexity estimate

Guide

About the Code Readability / Complexity Estimator

This tool gives you a rough, at-a-glance read on how complex and maintainable a code snippet is — without needing to install a linter, configure a static analysis tool, or even know what language you're looking at. Paste in any snippet and it immediately estimates cyclomatic complexity, maximum nesting depth, comment coverage, and average line length using simple text-pattern heuristics, then combines complexity and nesting into a single Simple / Moderate / Complex / Very Complex maintainability rating. It's built for quick sanity checks — skimming a pull request, deciding whether a function needs refactoring, or getting a fast second opinion before diving into a proper code review — not as a replacement for real static analysis tooling.

How It Works

Lines of code are counted by splitting the snippet on line breaks and discarding blank lines; comment lines are identified by checking whether a trimmed line starts with a common comment marker (//, #, /*, *, or --), and the comment ratio is comments ÷ non-blank lines. Cyclomatic complexity starts at 1 (representing a single straight-line path through the code) and adds 1 for every occurrence of a decision-point keyword or operator — if (which also naturally covers every else if, since that still contains the word "if"), for, while, case, catch, elif, &&, ||, and the ternary ?: operator — found via word-boundary regex matches across the whole snippet. Nesting depth is estimated by measuring each line's leading whitespace (tabs expanded to spaces), detecting the most common non-zero indentation step between distinct indent levels, and dividing the deepest indentation found by that step size.

Why It Matters

High cyclomatic complexity and deep nesting are strongly correlated with code that's harder to test, harder to reason about, and more likely to contain bugs — every additional decision point roughly doubles the number of distinct paths a reviewer or test suite needs to cover. A quick heuristic score like this one can't replace a real code review, but it's a fast, zero-setup way to flag a function that's grown too tangled and might be worth breaking into smaller pieces before it becomes a maintenance burden.

Tips for Accurate Results

  • Treat every number here as a rough estimate, not ground truth — this tool uses text patterns, not a real parser, so it can't perfectly distinguish code from strings or comments in every language.
  • For consistent nesting depth estimates, paste code that uses consistent indentation (all spaces or all tabs) — mixed indentation can throw off the detected indent width and skew the depth estimate.
  • Use this as a first-pass triage tool to flag functions worth a closer look, then confirm with a real static analysis tool appropriate to your language (ESLint/TypeScript for JS/TS, radon or pylint for Python, SonarQube for many languages).
  • A high comment ratio doesn't automatically mean good documentation — stale or redundant comments can inflate the ratio without improving actual readability.
  • Break down large snippets into individual functions before analyzing them here — a single giant snippet mixing many functions will report combined metrics that don't reflect any one function's real complexity.
About

Understanding the Metrics

🔀

Cyclomatic Complexity

Counts independent decision paths through code. Lower is simpler to test and reason about; functions above ~10 are commonly flagged as candidates for refactoring in real static analysis tools.

🪆

Nesting Depth

How many levels of indentation (if-inside-if-inside-loop, etc.) a snippet reaches. Deep nesting makes code harder to follow and is often a sign that logic should be extracted into separate functions.

💬

Comment Ratio

The share of lines that are comments versus code. Useful as a rough documentation signal, though quality matters more than quantity — a few clear comments beat many redundant ones.

FAQ

Frequently Asked Questions

Common questions about this complexity estimator

Is this a real static analysis tool?
No. This is a lightweight, regex-based heuristic estimator, not a real parser or abstract-syntax-tree (AST) based static analysis tool. For accurate, language-aware analysis, use dedicated tools like ESLint, SonarQube, radon (Python), or your language's official linter.
How is cyclomatic complexity estimated here?
The estimate starts at 1 (a single linear path) and adds 1 for each occurrence of a decision-point keyword or operator across the snippet: if (which also naturally covers every "else if"), for, while, case, catch, elif, &&, ||, and the ternary ?: operator. This mirrors the standard cyclomatic complexity formula but uses simple text pattern matching instead of a real control-flow graph.
How is nesting depth estimated without parsing the code?
The tool measures each line's leading whitespace (expanding tabs to spaces), finds the most common indentation step size across the snippet, and divides the maximum leading whitespace by that step size to approximate the deepest nesting level. It can be thrown off by inconsistent indentation or code that doesn't use indentation to signal nesting.
What does the maintainability rating mean?
It's a simple bucket — Simple, Moderate, Complex, or Very Complex — derived by combining the estimated cyclomatic complexity and nesting depth against fixed thresholds. It's meant as a quick gut-check, not a precise or industry-standard maintainability index.
Does this tool work for any programming language?
It works on any text, since it uses generic text patterns (keywords, indentation, comment markers) rather than a language-specific parser. Accuracy varies by language — languages with very different comment syntax or brace/indentation conventions may produce less precise estimates.

Related Calculators

Explore other developer & tech tools