Computing Foundations › Systems Foundations: Storage, Observability, and Tooling › Day 37

Day 37: Debuggers, Linters, and Formatters

Day 37 of 365 — Debuggers, Linters, and Formatters

After this lesson you will be able to explain what debuggers, linters, and formatters each do, choose the right one for a given problem, and run a real quality pipeline — syntax check, lint, and format check — over a broken script.

Course
Computing Foundations
Category
Systems Foundations: Storage, Observability, and Tooling
Reading time
≈ 40 min
Practical time
≈ 30 min
Lesson duration
1h 10m
Last verified
2026-07-12

Hands-on lab for this lesson

Lab files on GitHub: https://github.com/ai-roadmap-365/ai-roadmap-365.github.io/tree/main/labs/sections/computing-foundations/day-037-debuggers-linters-and-formatters

  1. Get the hands-on files. Clone the labs repository once (you can reuse this clone for every lesson). This works on macOS, Linux, and Windows (PowerShell or WSL):
    git clone https://github.com/ai-roadmap-365/ai-roadmap-365.github.io.git
    cd ai-roadmap-365.github.io
  2. Open this lesson's lab. Move into the directory for this specific day. Every lab lives at the same predictable path — section / subsection / week / day:
    cd labs/sections/computing-foundations/day-037-debuggers-linters-and-formatters
  3. Read the lab guide. Open `README.md` in that directory. It lists the exact commands, what each does, the expected output, and how to check your work — read it before running anything.
  4. Run it and check your work. Follow the README's "How to run" section: run the example first to see the finished result, then complete the numbered exercises in `starter/`, then run the tests. The tests pass (exit 0) only when your work is correct.
    bash tests/run_tests.sh   # or the test command named in the lab README

You can also open the lab as a local page (works offline, shows the file tree and expected output).

Learning objectives

By the end of this lesson you will be able to:

Prerequisites

Why this matters


The idea in plain language

Diagram: the cost of finding a defect at each stage


Historical background

Diagram: a configurable formatter compared with an opinionated one


What it is — and what it is not

These tools are:

They are not:


Why it was created and what problems it solves


How it works

How a linter and a formatter read your code

Diagram: how source code becomes a syntax tree for analysis

The pipeline

Flow diagram: the code-quality pipeline from writing to committing, catching issues earlier where they are cheaper to fix

How a debugger controls a running program

Diagram: print debugging compared with a debugger

Architecture diagram: the anatomy of a debugger session, showing the paused program, breakpoint, call stack, variables panel, and step controls

Where they live

Diagram: quality checks in the editor compared with in continuous integration


An everyday analogy

Diagram: introducing a type checker to an existing codebase gradually

Producing a manuscript.

PublishingThe tools
The house typesetting standardA formatter
A copy-editor marking suspicious phrasingA linter
Checking that names and dates are consistentA type checker
Reading aloud to find where it stops making senseA debugger
The proof stage before printingCI

Examples in practice

Diagram: using a conditional breakpoint to stop on a specific case

Diagram: what a formatter, a linter and a debugger each do


Implications: security, privacy, performance, scalability, and cost

Diagram: what static analysis catches compared with what tests catch


Alternatives: free, open source, and commercial

ToolTypeWhat it does
Black, Prettier, gofmtFree, open sourceFormatters with few or no options, by design
Ruff, ESLint, PylintFree, open sourceLinters; Ruff is fast enough to run on every keystroke
mypy, Pyright, TypeScriptFree, open sourceType checkers, which catch a different class again
pdb, debugpy, editor debuggersFree, built inBreakpoints and stepping
pre-commitFree, open sourceRuns all of them before a commit lands
Bandit, SemgrepFree, open sourceSecurity-focused linting

TermWhat it actually is
FormatterRewrites layout; never changes behaviour
LinterFlags suspicious patterns without running the code
Type checkerVerifies the kinds of values line up
DebuggerPauses a running program so you can inspect it
BreakpointA line where execution stops
Call stackThe chain of calls that reached this line
CIThe same checks, run as a gate on every push

When to use it — and when not to

Diagram: the question each of the three tools answers


The AI connection


Knowledge check

quiz:
  question: "A codebase passes its linter and its formatter cleanly, yet a function returns the wrong result for valid input. Why did neither tool catch it?"
  options:
    - "Both analyse the code's structure without running it, so neither can evaluate what a function actually computes"
    - "The linter's rules for that language do not cover return values"
    - "The formatter reformatted the function and obscured the defect from the linter"
    - "Static analysis runs before the code compiles, so runtime paths are not visible"
  answer_index: 0
  explanation: "Linters and formatters work on a parsed representation of the source and never execute it. They can tell you a variable is unused or a branch is unreachable; they cannot tell you the arithmetic inside is wrong, which is what tests and a debugger are for."

Hands-on exercise

Run all three on real code, and find a bug with the debugger rather than with prints. Worked through fully in the Day 37 lab directory.

What you are doingCommand
Format a messy fileblack messy.py or prettier --write messy.js
Confirm it is deterministicRun it twice; the second run changes nothing
Lint itruff check . or eslint .
Fix what it findsAnd note which finding was a real bug
Type checkmypy . or pyright
Debug with a breakpointpython3 -m pdb script.py, or your editor’s debugger
Set a conditional breakpointStop only when the failing input arrives

Expected output

reformatted messy.py
All done! 1 file reformatted.
messy.py:14:5: F841 local variable 'reuslt' is assigned to but never used
messy.py:22: error: Argument 1 has incompatible type "str"; expected "int"
> /project/script.py(31)process()
-> total = total + row['amount']
(Pdb) p row
{'amount': None, 'id': 4732}

Validate your work

Troubleshooting

Common mistakes


Practice assignment


Extension challenge


Quiz

Q1. Which tool rewrites your code's layout — indentation, spacing, quote style — without changing what the code does?

  1. A debugger
  2. A formatter
  3. A linter
  4. A type checker
Show answer

Answer: B. A formatter

A formatter regenerates the layout from the code's meaning, producing one consistent style while leaving behavior untouched. It does not judge correctness — a broken program is formatted just as happily as a correct one.

Q2. What does it mean that a linter performs "static analysis"?

  1. It analyzes the program only after it has finished running
  2. It measures how fast the program runs
  3. It inspects the source without running it, against rules
  4. It formats the code so it never changes again
Show answer

Answer: C. It inspects the source without running it, against rules

"Static" means the program sits still on disk rather than executing. A linter parses the source and checks it against rules — unused variables, unquoted values, unreachable branches — catching likely bugs before the code ever runs.

Q3. In a debugger, what is the difference between "step over" and "step into" at a line that calls a function?

  1. "Step over" skips the line entirely; "step into" runs it twice
  2. "Step over" restarts the program; "step into" ends it
  3. They are two names for the same command
  4. Step over runs the call as one step; step into descends into it
Show answer

Answer: D. Step over runs the call as one step; step into descends into it

Step over treats a function call as one step, running it and stopping at the next line in the current function. Step into descends into the called function so you can debug its inner lines. Step out then finishes a function and returns to its caller.

Q4. A shell script passes `bash -n` (the syntax check) but ShellCheck still reports an unquoted variable. How can both be true?

  1. Valid syntax only means it parses; a linter flags bad behavior
  2. The syntax check is broken and should be ignored
  3. ShellCheck is wrong because valid syntax means correct behavior
  4. The script must be run first for either check to apply
Show answer

Answer: A. Valid syntax only means it parses; a linter flags bad behavior

`bash -n` only confirms the shell can parse the script. An unquoted variable is perfectly valid syntax but a real bug — it word-splits or breaks on empty or spaced values. The linter catches this class of behavioral problem that a syntax check cannot.

Q5. What does the call stack show you when a debugger pauses deep inside a helper function?

  1. The list of every variable in the program
  2. The ordered chain of calls that led to the current line
  3. A history of every keystroke you have typed
  4. The formatted version of the source file
Show answer

Answer: B. The ordered chain of calls that led to the current line

The call stack is the sequence of active function calls, with the current function on top and its caller beneath, all the way down. It tells you how execution reached this point, and you can move up and down it to inspect each caller's variables.

Q6. When is logging (a print statement) usually a better choice than an interactive debugger?

  1. When you can reproduce a bug on demand and want to explore it
  2. Never — a debugger is always better
  3. For rare events, production, or a durable record
  4. Only when the code has no functions
Show answer

Answer: C. For rare events, production, or a durable record

A debugger shines for reproducible bugs you can trigger and explore live. Logging wins for rare or hard-to-reproduce events, production systems where attaching a debugger is impractical, and cases where you want a permanent trace to consult later.

Q7. Which statement about formatters and linters is correct?

  1. A formatter judges whether your code is correct; a linter only changes spacing
  2. They are interchangeable and do exactly the same thing
  3. Both tools run the program to see what it does
  4. A formatter changes layout; a linter flags likely bugs
Show answer

Answer: D. A formatter changes layout; a linter flags likely bugs

The division of labor is the key idea: a formatter owns appearance (layout only), while a linter judges patterns and likely bugs. A linter can occasionally flag something you did on purpose — a false positive — which a formatter, being purely mechanical about layout, cannot.

Q8. Why do teams run the same linter and formatter in CI that developers already run locally?

  1. The local run helps you; the CI run guarantees it for everyone
  2. CI runs are faster than local runs, so local runs are pointless
  3. CI uses entirely different rules to catch different bugs
  4. It is required only for projects written in C
Show answer

Answer: A. The local run helps you; the CI run guarantees it for everyone

The editor loop gives you fast private feedback, but only an automated CI gate guarantees that every change — across many contributors and thousands of commits — meets the standard. Running identical tools in both places means what you see locally is exactly what the gate enforces.

Glossary

debugger
A tool that controls the execution of another program — starting it, pausing it at chosen points, and letting you inspect its live state — so you can watch exactly what the code does rather than guess.
breakpoint
A marker on a line that tells the debugger to pause the program when execution reaches it; a conditional breakpoint pauses only when a condition you specify is true.
step over
A debugger command that runs the next line and stops again, treating any function call on that line as a single step rather than descending into it.
step into
A debugger command that descends into a function being called so you can watch its inner lines execute one at a time; its counterpart, step out, finishes the current function and returns to its caller.
call stack
The ordered chain of function calls that led to the currently executing line — who called whom, with the current function on top — which you can navigate to inspect each caller's variables.
watch expression
A value or expression you ask the debugger to re-evaluate and display continuously as you step, so you can watch a single quantity change over the course of execution.
linter
A static-analysis tool that reads source code without running it and reports likely bugs and bad patterns, such as unused variables or unquoted values, each with a file, line, and message.
static analysis
Examining a program by reading its source code while it sits still on disk — without executing it — to find problems; the opposite of dynamic analysis, which observes a running program.
formatter
A tool that rewrites code's layout — indentation, spacing, line breaks, quote style — into one consistent style while leaving behavior unchanged; running it twice changes nothing the second time.
type checker
A static tool that verifies the kinds of values fit together — that text is not passed where a number is required, or a possibly-missing value read as if present — without running the code.
ShellCheck
A free, open-source linter for shell and Bash scripts that flags quoting, test-command, and portability bugs, each tagged with a rule code (such as SC2086) linking to an explanation.
Debug Adapter Protocol (DAP)
A shared, open standard that lets a single editor debugging interface drive debuggers for many different languages through language-specific adapters.
continuous integration (CI)
An automated system that runs checks — such as formatting and linting — on a shared server every time code is pushed, refusing changes that fail, so standards are enforced on every commit.

Sources and further reading


Kept in this browser, no account needed. Your progress page turns the whole record into one link you can bookmark or open on another device.