Part II — Intermediate Development · Chapter 9 · Lesson 4 of 5 · 7 min read
Lesson 4: Formatting, Checking, and Maintainability Conventions
Level: Intermediate
Purpose. A multi-module project stays healthy only if its style, structure, and quality checks are applied the same way by every contributor. This lesson shows how to use the formatter and the checker as automatic gates, how to agree on naming and comment conventions, and how to review a project for maintainability.
Learning objectives
After this lesson you will be able to:
- format a whole project consistently and verify formatting without changing files;
- run the checker as a quality gate and interpret its findings;
- apply naming, comment, and documentation conventions across modules;
- design a non-mutating CI routine that fails clearly;
- review a project for dependency direction, contract drift, and dead code;
- use a maintainability checklist before accepting a change.
Release note: command names, flags, and output shown here are illustrative. Verify them against the installed v0.63 release with the built-in help before relying on them.
4.1 Why conventions matter
Conventions remove low-value decisions. When layout, naming, and structure are predictable, reviewers spend their attention on behavior, contracts, and risk instead of whitespace. Conventions also make diffs small: a change to one rule should touch that rule, not reflow the whole file.
4.2 The formatter
The formatter rewrites source into one canonical layout. Two modes matter in practice: a mutating mode used by developers, and a check mode used by automation that reports differences and exits with a failure status without touching files.
pea fmt src/
pea fmt --check src/
Run the mutating mode before committing. Run the check mode in CI. Never let CI rewrite files, because a pipeline that silently fixes style hides the fact that a contributor skipped the step.
4.3 The checker
The checker performs static analysis without running the program: syntax errors, unresolved names, import problems, and, where annotations exist, type and flow findings. It answers the question: can this project be understood by the tooling before it is ever executed?
pea check src/
pea check src/main.pea
Treat every finding as a defect to fix or an explicit, documented exception. A checker whose warnings are routinely ignored soon stops being read.
4.4 Formatting versus checking versus testing
| Gate | Question answered | Changes files? | Typical frequency |
|---|---|---|---|
| Format check | Is the layout canonical? | No (check mode) | Every commit and CI run |
| Check | Is the code statically sound? | No | Every commit and CI run |
| Tests | Does behavior meet the contract? | No | Every CI run |
| Review | Is the design maintainable? | No | Every change |
The gates are complementary. Passing one never substitutes for another.
4.5 Naming conventions
Names carry meaning across module boundaries, so agree on them early and apply them everywhere.
- Use lowercase words separated by underscores for values, functions, and module names, such as discount_rules and apply_discount.
- Name constants for what they mean, not what they hold: high_impact_threshold, not eight.
- Prefix intentionally internal helpers with an underscore and do not export them.
- Name modules after one responsibility. A module called utils usually hides several unrelated ones.
- Never rely on capitalization alone to distinguish names; identifiers are case-sensitive and such pairs invite defects.
- Avoid the reserved words, including import, export, and as, even where a synonym seems natural.
4.6 Comment conventions
Comments explain intent, constraints, and reasons. They should not restate syntax. PeaLang supports line comments introduced by # or //; choose one style for the project and keep to it.
# Policy: security cases always outrank impact and user-count rules.
const high_impact_threshold = 8
Give every exported function a short comment stating its inputs, its result, and its failure behavior. This is the text that generated documentation and reviewers will rely on.
4.7 A project-wide quality routine
Combine the gates into one routine that developers run locally and CI runs without modification, except that CI uses non-mutating modes.
| Step | Local command | CI command |
|---|---|---|
| 1. Format | pea fmt src/ tests/ | pea fmt --check src/ tests/ |
| 2. Check | pea check src/ tests/ | pea check src/ tests/ |
| 3. Test | pea test (see Chapter 10) | pea test (see Chapter 10) |
| 4. Docs | Regenerate when exports change | Verify generated docs are current |
Commands are illustrative; confirm the exact test and documentation commands in the installed release. Keep each step separate so a failure names its stage.
4.8 Reviewing for dependency direction
Formatting and checking cannot see architectural drift. Reviewers must also confirm that dependencies still point downward, as established in Lesson 2.
- Does any low-level module import a higher-level one?
- Did a new import create a cycle between two modules?
- Does a rules module now import an adapter that performs file, network, or process work?
- Is each new cross-module call going through an exported contract rather than an internal helper?
4.9 Reviewing for contract drift
Contract drift occurs when an exported function changes behavior while its name and signature stay the same. Treat any change to exported inputs, outputs, reason codes, or error behavior as a contract change: update the comment, update callers, add or adjust tests, and note it in the project changelog.
4.10 Maintainability checklist
- Every module has one stated responsibility.
- Exports are small, named, and commented.
- No cycles; dependencies point downward.
- Configuration is validated at the boundary and holds no secrets.
- Policy values are named constants, not unexplained literals.
- Each rule has tests for below, at, and above its boundary.
- Output and reason codes are stable and labeled.
- Formatter, checker, and tests pass in non-mutating CI mode.
4.11 Common mistakes
| Mistake | Consequence | Correction |
|---|---|---|
| Running the formatter in CI without check mode | Pipeline silently rewrites files or hides skipped local steps | Use check mode in CI and fail on drift |
| Ignoring checker warnings | Real defects are lost in noise | Fix each finding or document the exception |
| Reformatting and changing behavior in one commit | Reviewers cannot separate style from logic | Commit formatting changes separately |
| A catch-all utils module | Hidden coupling and cycles | Split by responsibility |
| Comments that restate code | Comments drift out of date | Explain intent and constraints only |
| Changing an export without updating its comment and tests | Contract drift | Treat as a contract change |
4.12 Diagnostic workflow
- Identify which gate failed: format, check, test, or review.
- For a format failure, run the formatter locally, review the diff, and recommit.
- For a check failure, read the first reported error and fix it before later ones.
- For a test failure, reproduce with the smallest input and use the debugger if needed.
- For a review finding, decide whether it is a defect or a documented decision.
- Rerun the whole routine to confirm nothing else changed.
4.13 Guided practice
- Explain why pea fmt --check is appropriate in CI but pea fmt is not.
- Rename three vague names in a sample module to meaning-based names.
- Rewrite a comment that restates its code so that it explains the reason.
- Draw the dependency direction for a three-module project and mark any violation.
- Decide whether a changed reason code is a contract change and list what must be updated.
4.14 Hands-on lab: Add quality gates to a multi-module project
Goal: Apply the full routine to the project built in Lesson 3.
- Deliberately introduce uneven spacing in two modules. Run the format check and record the failure.
- Run the formatter, review the diff, and rerun the check until it passes.
- Introduce a misspelled name. Run the checker and record the diagnostic location and message. Correct it.
- Rename two vague identifiers and update every caller.
- Add intent comments to each exported function.
- Create a script or checklist that runs format check, check, and tests in order and stops on the first failure.
- Perform a review against the maintainability checklist and record findings.
Deliverable: The command log with outcomes, the diagnostic notes, the renamed identifiers, and the completed checklist. Use synthetic data only and include no secrets.
4.15 Review questions
- What is the difference between the formatter's normal mode and its check mode?
- Why should each quality gate remain a separate step?
- What does the checker find that the formatter cannot?
- Name three naming conventions used in this lesson.
- What should a comment on an exported function state?
- What is contract drift, and how do you prevent it?
- Which review questions detect dependency-direction violations?
- Why should formatting changes be committed separately from behavior changes?
4.16 Applied challenge
Choose a small multi-module project of your own. Write a one-page conventions guide covering formatting, naming, comments, export rules, the quality routine for local and CI use, and the review checklist. Then apply it to the project and record every change it caused.
4.17 Lesson summary
Consistent conventions make multi-module PeaLang projects easier to review and change. The formatter normalizes layout and the checker finds static defects; both should run in non-mutating mode in CI. Naming, comments, and small commented exports document intent, while reviews for dependency direction and contract drift catch what tools cannot. A short maintainability checklist turns these practices into a repeatable acceptance step.
4.18 Transition to the Chapter 9 checkpoint
The next item is the Chapter 9 Checkpoint: Multi-Module Business-Rules Project, which brings together module boundaries, contracts, layout, configuration, and the quality routine in one complete project.
Lesson status: Ready for review.