Learn how to write deterministic, high-quality code that AI assistants can understand and maintain effectively.
This repository demonstrates common code quality issues that PMAT (Pragmatic AI Labs MCP Agent Toolkit) can detect, and how to fix them. Each example is designed to be:
- Simple: ELI5-level complexity
- Focused: One issue per example
- Practical: Real problems you'll encounter
- Educational: Learn by doing
-
Install PMAT:
cargo install pmat
-
Clone this repo:
git clone https://github.com/paiml/deterministic-llm-coding cd deterministic-llm-coding
-
Check bad examples:
make check
-
See the fixes:
make fix
-
Learn interactively:
make learn
- Why nested if-statements hurt AI understanding
- How to refactor for clarity
- Target: Complexity ≤ 10
- Why TODOs and FIXMEs accumulate
- How to eliminate technical debt
- Target: 0 SATD comments
- Spotting copy-paste patterns
- Applying DRY principles
- Target: Entropy score < 30
- Eliminating panic potential
- Safe error handling
- Target: 100% provable code
PMAT analyzes your code using:
- AST (Abstract Syntax Tree) parsing
- Complexity metrics (McCabe cyclomatic)
- Pattern detection (entropy analysis)
- Comment parsing (SATD detection)
- Provability analysis (panic detection)
deterministic-llm-coding/
├── examples/
│ ├── 01-complexity/ # Nested code → Simple functions
│ ├── 02-satd/ # TODO comments → Clean implementation
│ ├── 03-entropy/ # Copy-paste → DRY principles
│ └── 05-provability/ # Panic-prone → Safe error handling
├── scripts/ # Automation and learning tools
├── Makefile # Build and analysis commands
└── pmat.toml # PMAT configuration
Run the guided tutorial:
make learn
This will:
- Show you a bad example
- Run PMAT to identify issues
- Explain what's wrong
- Show you how to fix it
- Verify the fix works
Track your improvements:
pmat tdg . --format dashboard
make check
- Analyze all bad examplesmake fix
- Show all good examplesmake learn
- Interactive tutorialmake compare
- Before/after comparisonmake build
- Build all examplesmake install-pmat
- Install PMAT tool
Add your own examples! Each example needs:
- A "bad" version with issues
- A "good" version with fixes
- A README explaining the problem
- Cargo.toml for compilation
MIT - Use these examples to improve your code quality!