Be intentional about how AI changes your codebase
TL;DR Highlight
Splitting functions into semantic and pragmatic ones and tightening models keeps AI-written code from degrading
Who Should Read
A backend developer worried that code written by coding agents is getting messier over time
Core Mechanics
- A swarm of agents sloppifies faster
- The author says a swarm of coding agents sloppifies a codebase faster than a single one.
- So humans must be intentional about how AI-written code should look.
- Semantic functions are small and side-effect free
- They take all required inputs and return all necessary outputs directly.
- They need no comments and should be easy to unit test.
- Examples include quadratic_formula() and retry_with_exponential_backoff_and_run_y_in_between.
- Pragmatic functions hold the messy flows
- They wrap semantic functions and unique logic into real-world processes.
- Examples are provision_new_workspace_for_github_repo(repo, user) and handle_user_signup_webhook().
- If one is used in more than a few places, move its logic into semantic functions.
- They are covered by integration tests, and doc comments should note surprises like "fails early on balance less than 10", not restate the name.
- Models should make wrong states impossible
- Every optional field is a question the rest of the codebase must answer.
- Compose independent concepts, e.g. UserAndWorkspace.
- Brand types like DocumentId(UUID) turn swapped IDs into compile errors.
- Breakage starts when semantic turns pragmatic
- Adding work to a semantic function for convenience makes its other callers behave in unintended ways.
- So name functions by where they are used, not by what they do.
- Models decay the same way when "just one more" optional field piles up, and that is the signal to split them.
Community Reactions
- Optional args are the top annoyance
- One commenter said agents add optional arguments instead of designing well.
- Their first review step is hunting for those extra optional args.
- Code quality is now the prompt
- A commenter found agents perform better on cleaner codebases by following existing patterns.
- In messy repos they reportedly invent a new pattern every time.
- Code can't document the why
- One commenter argued self-documenting code is used as an excuse to skip docs and comments.
- This resembles FCIS
- A commenter noted semantic/pragmatic maps to Functional Core, Imperative Shell.
- They added that isolating complex logic in the core keeps tests fast.
How to Apply
- Scan agent PRs for optional fields first
- Today, find every newly added optional argument or field in recent AI-generated diffs.
- For each, decide whether it's needed or should become a separate model, then fix it.
- Put function and model rules in AGENTS.md
- Add a rule that semantic functions take inputs and return outputs with no side effects.
- Add a rule to create a new model instead of adding optional fields.
- Wrap ID types in brand types
- Give DocumentId, UserId and similar IDs their own types instead of bare string or UUID.
- Let the compiler catch swapped arguments.
- Install the author's skill in your agent
- Run npx skills add theswerd/aicode to add the guide to your agent.
- Check on one PR whether the generated code follows the rules.
Try It
# Paste into Claude Code or a Cursor chat (simplified version of the article's guide)
Review and fix the {{file or diff}} below using these criteria.
1. List every newly added optional field or argument and judge whether it can be removed or split into a separate model.
2. If IDs of different concepts share a type (string, UUID), suggest wrapping them in brand types.
3. Split functions that mix side effects into semantic functions (inputs in, outputs out) and pragmatic functions that compose them.
4. Do not comment semantic functions; let names explain them. For pragmatic functions, write doc comments only for surprising behavior, not the name.
Show me your change plan before editing any code.
{{file or diff}}Terminology
Related Papers
Frostbite: A new CPU architecture discovered, designed and verified by AI
AI agents designed a CPU from scratch, claiming 4.59x perf/W over a traditional core
Restricting AI agents in mobile operating systems platforms from capturing data
Signal now blocks OS-level AI agents from reading its screen on iOS 27 and Android
Actions Speak Louder than Words: Stateful Privacy Sniffing of LLM Agents via Behavioral Covert Channels in Web Interactions
Agents' link choices alone let attackers rebuild user queries at F1 0.89; SOR cuts it to 0.39.
Tracking and Limiting Unsupported Claim Propagation in Multi-Agent LLM Systems: A Provenance-Aware Framework
Passing claims with source, evidence and history kept equivalence at 5 agent stages at 96% versus 31%.
LLM assisted reverse engineering
Pointing an agent at binaries with skills and MD notes made years-long hacks feasible
Metrics-in-the-Loop: Complexity Feedback Reshapes Agent-Written Code
Injecting per-turn complexity reports into coding agents cut code erosion without changing correctness
Why is Gemini 4 Carbon taking so long?
Carbon took nearly an hour on bug fixes that Astra and Opus finished in minutes, mostly from extra unrequested work.
Weight-Space Programming builds neural networks like a 1990s researcher
LLM hand-wrote MNIST weights to 91.3%, using 1990s-style techniques