My gripe isn't that AI code is wrong, it's that it is unmaintainable: 80-line functions, clever one-liners, no seams for testing, magic numbers everywhere. It passes review by looking confident.
I stopped saying "write clean code" (meaningless) and started giving it a hard output contract with named, checkable constraints: cyclomatic limits, no boolean-flag params, dependency injection over globals, and a self-audit at the end where it grades its own output against the contract and rewrites anything failing before showing me.
The self-audit is the part that made it stick. I'd love a sharper set of constraints, especially anything that discourages premature abstraction, which is the other failure mode.
Write the requested code to this MAINTAINABILITY CONTRACT. These are hard constraints, not suggestions.
Structure:
- No function longer than 30 lines or with cyclomatic complexity > 8. Split with intention-revealing names.
- No boolean 'flag' parameters that fork behavior; make two functions instead.
- No magic numbers/strings; name them as constants with a comment on the unit or meaning.
- Dependencies (clock, IO, random, network) are injected, not reached for globally, so it is testable.
- Prefer duplication over the wrong abstraction. Do NOT introduce a base class/generic/helper until there are 3 real call sites. Comment any place you deliberately left duplicated.
Errors and edges:
- Validate inputs at the boundary; fail fast with a specific message. No silent catch-all excepts.
SELF-AUDIT (required, before you show me code):
List every constraint above and mark PASS/FAIL for your draft. For each FAIL, rewrite until it passes. Only then output the final code plus a 3-line summary of the seams you left for testing.
Task: {DESCRIBE_WHAT_TO_BUILD}
Language/conventions: {STACK}