Sub topic 11
Maintainability and fit with your codebase
This chapter assumes you can read a Git diff, write basic unit tests, and have used an AI coding assistant. Earlier chapters covered correctness, security, and tests. Here the question is different: will the next person who opens this code be able to work with it?
Why working code can still be rejected
An AI assistant sees the prompt and a slice of your files. It does not know your team's conventions unless you show them. The result often runs and passes tests but reads like it came from a different project. A change like that adds cost every time someone touches it later.
Review for fit after you have confirmed the change is correct and safe. Fit problems are cheaper to fix than bugs, but they pile up.
What to look for
- Naming. Does the code use your names for the same concepts? If your project says
customer, a newclientvariable is a small inconsistency that spreads. - Duplicated helpers. Assistants often write a new date parser or retry loop instead of using the one already in your repo. Search before you accept.
- Layering. Does the change put database calls in a request handler when your code keeps them in a repository module?
- Error handling style. Does your codebase raise exceptions, return result objects, or log and continue? New code should match.
- Unneeded abstraction. Extra classes, config options, or "flexible" parameters that no requirement asked for are code you must now maintain.
- Comments. Remove comments that restate the code. Keep ones that explain why.
- Dead code. Look for unused imports, leftover helper functions, and commented-out blocks.
Example: a change that works but does not fit
Suppose your project already has app/utils/retry.py with a retry decorator. The assistant adds this to a new file:
import time
def fetch_with_retry(fetch, attempts=3, delay=1.0):
for i in range(attempts):
try:
return fetch()
except Exception:
if i == attempts - 1:
raise
time.sleep(delay)It works. It also duplicates your existing decorator, catches every Exception instead of the network errors your decorator targets, and uses a fixed delay where your project uses exponential backoff. Reviewing it against the codebase shows three problems that tests would not catch.
A better change reuses what exists:
from app.utils.retry import retry
@retry(exceptions=(ConnectionError, TimeoutError))
def fetch_report(client, report_id):
return client.get(f"/reports/{report_id}")The retry decorator and its exceptions argument are assumed to exist in this example project. Always open the real helper to confirm its signature before you tell the assistant to use it.
A fit-review workflow
Useful commands for the search step:
git grep -n "retry"
git grep -n "def parse_date"
git diff --statA large --stat for a small feature often means the assistant rewrote or reformatted code you did not ask it to touch.
Giving feedback that works
When a change does not fit, name the exact convention and point to an example. "Use the retry decorator from app/utils/retry.py and remove fetch_with_retry" gets better results than "make it fit the codebase." You can also add a short conventions file to the repository so the assistant sees your rules every time.
Review summary
| Check | Question to ask |
|---|---|
| Naming | Does it use the project's terms? |
| Reuse | Does an existing helper already do this? |
| Layering | Is code in the right module? |
| Scope | Did it change files unrelated to the task? |
| Simplicity | Is every abstraction required? |
Exercise
An assistant adds a 40-line format_currency function to a new file. The tests pass. What do you check before accepting it, and why?
Show answer
Search the repository (for example with git grep -n "currency") for an existing formatting helper. If one exists, ask the assistant to use it and delete the new function, since duplicate helpers drift apart and double the maintenance. Also check that naming, error handling, and file location match project conventions.
Exercise
A small bug fix produces a diff with 300 changed lines across 12 files. Which command gives you a quick overview, and what does the result suggest?
Show answer
git diff --stat shows changed files and line counts. A large footprint for a small fix suggests unrelated edits such as reformatting or refactoring. Ask the assistant to limit the change to the lines needed for the fix.