Chapter Eleven · Unfamiliar and Legacy Code

Unfamiliar and Legacy Code

Code nobody on the team wrote: Cragmoor's pricing module, three years old, untested, its authors gone. A map from the agent checked against the code, characterization tests that record what it does before anyone changes it, refactoring in named steps that each stay green, changes too large to read site by site, and the documentation the agent writes about all of it.

5 topics

Most code an engineer works on was written by someone else, and an agent changes the economics of that work in both directions. It reads unfamiliar code in seconds and answers questions about it with total fluency, which is a gift. It also fills every gap in its reading with what such code usually does, and on old code the usual thing is precisely what is not there. A newcomer with an agent can learn a codebase in an afternoon, or misunderstand it in an afternoon, and the two feel the same while they are happening.

This chapter takes the agent into Cragmoor's pricing module and keeps the work honest at every step. It starts with a map of the booking service that the agent draws in a minute and you check against files, searches and history. It pins what pricing does today with characterization tests, before a line changes, and finds two surprises on the way: the 10% member discount is rounded for each class, so a 10-class pack at $17.95 costs $161.60 instead of $161.55, and the 16:00 off-peak cut-off is read on the server's clock, so the gyms in the other time zone charge the peak rate for the last off-peak hour of each afternoon. Both stay exactly as they are until someone decides otherwise.

Then the module is restructured in nine named steps, each green and each committed, with one step discarded when it tried to fix the rounding on the way past. The chapter widens to a change too large to read site by site, a library upgrade across 47 call sites, where a script and a count replace reading every edit. And it ends on the documentation the agent writes, which tends to describe the code it expected rather than the code that is there.

From unknown code to code you can change, in four moves
Mapchecked, not trusted
→
Pinrecord, don't judge
→
Refactorone step, one commit
→
Documentwhat is surprising

Topics in This Chapter