Developer and Text Tools

How to Understand Unfamiliar Code: Complexity, Line Notes and Local AI

Read unfamiliar code faster: a function outline, cyclomatic complexity, line-by-line notes and refactor hints, plus optional on-device AI explanations.

Saizul Amin
Saizul Amin2 Nov 2026 · 4 min read
How to Understand Unfamiliar Code: Complexity, Line Notes and Local AI

How to Understand Unfamiliar Code: Complexity, Line Notes and Local AI

Developers spend much of their time reading code they did not write. Reading well is a skill, and it gets easier when you have a map of the code before diving into the details. This guide explains the measures that make such a map useful, especially cyclomatic complexity, and shows how to get them in seconds without sending your code anywhere.

Start with structure, not lines

When you open an unfamiliar file, resist reading from the top. First answer three questions: what does it import, what types or classes does it define, and which functions exist and how big are they? The function list, with line ranges and lengths, tells you where the real work happens.

What cyclomatic complexity measures

In 1976 Thomas McCabe proposed counting the number of independent paths through a piece of code. The practical formula is simple: start at 1 and add one for every decision point, such as an if, an else if, a loop, a case label, a catch block, a ternary, or a short-circuit && or ||.

Why does this matter? Each independent path is a scenario that a test should cover. A function with complexity 3 needs only a handful of tests; one with complexity 18 has so many branches that nobody can hold them all in mind. A common rule of thumb is:

ScoreReading
1 to 5simple
6 to 10needs care
above 10hard to test fully, consider splitting

Complexity is a signal, not a verdict. Nesting depth is often a better clue to confusion: three or four levels of indentation inside loops and conditions are hard for anyone to follow.

Using the explainer

Open Code Explainer with Local AI and paste your code. The language is detected automatically for JavaScript, TypeScript, Python, Java, C#, Go, PHP, Ruby, Rust, C, C++, Kotlin, Swift, SQL and shell scripts, and you can override it if detection is wrong.

  • Structure lists imports, classes and a table of functions with their line range, length, maximum nesting and cyclomatic complexity. Strings and comments are blanked before counting, so the word "if" inside a message is not mistaken for a branch.
  • Line by line places a short plain-English note next to every line: an import, a loop over each item, a condition, a return, an error handler, a closing brace. These notes describe what the syntax does, not why the author wrote it.
  • Refactor hints points to specific lines that deserve attention: complexity above 10, functions over 50 lines, deep nesting, too many parameters, very long lines, loose equality and var in JavaScript, any in TypeScript, bare or silent except clauses, empty catch blocks, magic numbers, leftover TODO comments, eval and repeated lines.
  • AI lets you load a small coding model that runs in your browser. After you accept the download notice and press Load the AI model, you can pick Line by line, Summary, Refactor ideas or Big-O and press Explain.

A worked example

Take a short Python function, load_orders, that reads a JSON file, skips cancelled orders and sums quantity times price for each customer, then returns the totals sorted from largest to smallest.

The structure view shows two imports, json and pathlib, and one function spanning about a dozen lines. Its complexity is 5: the base value of 1, plus two for loops and two if statements. Maximum nesting is 2. That already tells you the function is manageable and that about five tests would exercise its paths.

The line notes then explain details that trip up beginners, for example that continue jumps to the next round of the loop, and that the final sorted call returns the totals ordered by value. If you want to know why cancelled orders are skipped or whether the algorithm scales, the AI tab's Summary or Big-O mode is the right place to ask.

Tips for reading code well

  • Treat hints as questions. A magic number may be a well-known constant; an empty catch may be intentional. Check before changing.
  • Use the AI for intent, the exact views for facts. Counts, line ranges and nesting are computed from the text and are reliable within the parser's limits. The model's explanation is a guess that you should check against the code and the library documentation.
  • Explain one function at a time. The model only looks at the first 6,000 characters of code.

About the local model

The optional model, Qwen2.5-Coder-0.5B-Instruct (about 555 MB), is downloaded once and cached, then runs in your browser, so your code stays on your device. It is small and can misread rare libraries or state wrong complexity classes, so review what it writes.

Limits

The structure, line and hint views rely on language-specific patterns rather than a full parser for every language, so unusual formatting or newer syntax can hide a function or skew a count. Line notes explain syntax, not business intent. The tool never executes your code, so it cannot detect runtime bugs or performance issues. The local AI model is small and can be confidently wrong, especially on long files or uncommon frameworks; treat its output as a starting point and verify it against the code and official documentation.

Completely freeNo cost, no sign-up
Files stay privateEverything runs in your browser
Easy in your languageAvailable in many languages