PeaBox Lab › PeaLang › Learn › Chapter 9 › Lesson 4

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:

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

GateQuestion answeredChanges files?Typical frequency
Format checkIs the layout canonical?No (check mode)Every commit and CI run
CheckIs the code statically sound?NoEvery commit and CI run
TestsDoes behavior meet the contract?NoEvery CI run
ReviewIs the design maintainable?NoEvery 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.

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.

StepLocal commandCI command
1. Formatpea fmt src/ tests/pea fmt --check src/ tests/
2. Checkpea check src/ tests/pea check src/ tests/
3. Testpea test (see Chapter 10)pea test (see Chapter 10)
4. DocsRegenerate when exports changeVerify 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.

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

4.11 Common mistakes

MistakeConsequenceCorrection
Running the formatter in CI without check modePipeline silently rewrites files or hides skipped local stepsUse check mode in CI and fail on drift
Ignoring checker warningsReal defects are lost in noiseFix each finding or document the exception
Reformatting and changing behavior in one commitReviewers cannot separate style from logicCommit formatting changes separately
A catch-all utils moduleHidden coupling and cyclesSplit by responsibility
Comments that restate codeComments drift out of dateExplain intent and constraints only
Changing an export without updating its comment and testsContract driftTreat as a contract change

4.12 Diagnostic workflow

4.13 Guided practice

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.

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

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.

← Previous Next →