shtukbasehub

Code: the pragmatic programmer

The school of Hunt and Thomas ("The Pragmatic Programmer", 1999; ed. 2019): DRY as one piece of knowledge in one place, orthogonality, no broken windows, tracer bullets, crash early; three heuristics and judges.

Packagecode-pragmaticv0.1.015 files

Code: the pragmatic programmer

The school. Craft is habits. Every piece of knowledge in the system is written once. The parts of the system are independent, and a change to one does not touch the others. Small decay is fixed at once, otherwise it invites more. New things are built as a thin end-to-end path and then grown.

The authors. Andrew Hunt and David Thomas. Source: Andrew Hunt, David Thomas, "The Pragmatic Programmer", Addison-Wesley, 1999; the 20th anniversary edition is 2019. The norms below retell the ideas in our own words; they are not quotes.

When to take it. Any project where the code lives longer than a week and is changed by several people or agents.

When not to take it. Learning and throwaway sketches, where the code will be discarded.

Norms

NormWhat holdsLevelEnforcer
PRG-R01One piece of knowledge, one placeSHOULDcheck repeated-literals and judge judges/dry-knowledge.md
PRG-R02Modules are independent: no import cyclesSHOULDcheck import-cycles
PRG-R03No broken windowsSHOULDcheck broken-windows
PRG-R04New things as a thin end-to-end pathMAYjudge judges/tracer-bullets.md
PRG-R05The program checks its preconditions and crashes earlySHOULDjudge judges/crash-early.md

All norms are in observe mode: the checks print findings and pass, the judges are a procedure for the reviewer. A check you trust on your code is moved by the owner to mode: enforce in the norm's page, and then a finding fails shtuk check.

How to connect

shtuk install <path>/apps/standard/packages/code-pragmatic --dir <project>
shtuk check --dir <project>
shtuk run code-pragmatic review                 # a prompt for the reviewer over the uncommitted change
shtuk run code-pragmatic review --diff main..HEAD
shtuk run code-pragmatic review src/a.ts src/b.py

The package requires norms-core and code-lib (the shared code-parsing library and shared settings). It is installed on top of Basic.

Settings

Which code to read is the shared page /norms/code.md of the code-lib package: roots (roots), exclusions (exclude), languages, whether to read tests. This package's thresholds are the page /norms/code/code-pragmatic.md:

KeyDefaultWhat it means
minLength16length of a string literal whose repetition is counted (PRG-R01)
minFiles3in how many files a repetition is already a finding (PRG-R01)
commentedLines3lines of commented-out code in a row (PRG-R03)

The same page has its own exclude list (path masks from the project root). One place is released by the comment code-allow: <check name> on its line or the line above.

Honestly about the checks

The checks are rough heuristics: regular expressions and bracket parsing for TypeScript/JavaScript, Python and Rust, with no parsers and no dependencies. They err both ways, which is why they stand in observe. The meaning of a norm is held by the judge; the heuristic only shows where to look. 3 checks, 3 judges.