Build a Clean, Coherent Change
Part 2 of 3 · Pre-Flight Checks
- Respect Your Pre-Flight Checks
- Build a Clean, Coherent Change
- Run Your Checklist Before the PR (coming soon)

In Part 1 we mercilessly dissected code's purpose and scope and allowed it to exist. We are cleared for take off.
You have a clean, elegant design in front of you. It's exciting and you expect the implementation to be minimal.
Fast forward a couple of hours and you are looking at a disjointed pile of code the size of Mount Everest.
Now let's figure out how we got there and what we could have done better.
Sadly, I won't teach you how to code, there are plenty of resources for that out there. This post is about applying the engineering process to turn a concept into a working piece of software reliably.
Don't fight against the project
If you feel excessive resistance that comes from the way the project is set up - pause and reconsider.
This might materialise as language not having the constructs that you would like to use, leaking abstractions between the architectural layers or editing dozens of files for a simple change. AI is notorious for ignoring this kind of pushback and making changes anyway.
Don't be like that, stop and think of a better way, do a little research into the topic or ask a mate. This can happen because of the lack of experience, but more often than not you are doing something conceptually wrong.
What might this look like?
- Manually pushing the dependency down as an argument in a project with a defined Dependency Injection pipeline
- Using manual SQL operations in a project that has an ORM
- Inverting the dependency order in a Clean/Onion Architecture project
- Using exceptions and try/catches instead of responses for logic flow for languages that support it
- Using patterns common in other languages e.g. manually parsing JSON objects instead of using idiomatic serialisers
Before I get covered in food scraps, the opposite is also true from time to time. The friction can come from the project structure itself and it ought to change when that happens. This case is more prominent in open source projects that tend to evolve more naturally and outgrow their current scope. Having a feel for when that happens is equally important, but that deserves its own write up and I won't elaborate on that here.
Don't fight the scaffolding, let it guide you. It is commendable to push through a hard problem. Circumventing your tooling to get there is not.
Keep the scope tight
Once you start coding it's easy to get carried away. Changes in one layer might have a flow-on effect on the other or you get a good idea for a refactor.
From time to time you need to pause and have a good hard look at what you've got so far and compare it with what you committed to.
Sometimes, having written something in a crude way, you get an idea for a more elegant solution. Every line of code you've added is a permanent maintenance burden going forward. If you see a cleaner path forward - refactor your change towards it.
Some of the more common offenders:
- Finding an optimisation to a common method, then having to re-test all of the unrelated code that uses said method
- Coming up with a neat testing harness that is only applicable to a handful of tests
- UI unification changes e.g. standardising the components or behaviours across various pages unrelated to the scope of work
- Adding generic integration points for something that will realistically only have one source or consumer
- Many simpler changes to complicated logic instead of a few more complicated targeted changes (AI favourite). E.g. adding yet another override for a method instead of generalising the problem to save on lines of code
Follow existing patterns
If you have to write new code because you can't reuse what's there - make it look identical and follow the same patterns. Don't be that guy.
It's tempting to bring the latest and greatest to an established codebase. We crave novelty, love new toys and chase the dopamine hit of being on the bleeding edge of technology.
Overindulging in that urge comes at a cost of increasing the cognitive load for anyone reading the code and extended dependency surface. It confuses the agents as they no longer have a single point of contact when it comes to picking practices to follow. For humans it increases the onboarding cost for the project and makes it less maintainable in the long run.
In the worst case, when only the contributor understands the new pattern, it adds friction to the follow up work as well.
In saying that, modernisation of the codebase is a necessary evil and should not be forgotten nor forbidden. If the benefit outweighs those costs greatly, it's worth migrating everything to the new pattern as a separate piece of work systematically. There is nothing inherently wrong with that as long as everyone is on the same page that the purpose of the exercise is a tech debt repayment.
We must also acknowledge that routing the upgrade as part of an unrelated piece of work muddies the water, brings chaos to the git history and makes the change generally harder to review. This also distracts the reviewer from the core change and should be avoided where practical.
What does that actually look like in practice?
- Adding yet another UI library to the project because it's 1% faster and all of your mates are using it
- Renaming exceptions or reformatting error messages to something that makes more sense to you
- Rewriting tests using a new framework just because you think it's more readable
- Using a cool new language feature that is, in essence, syntactic sugar
Sometimes the best code is the code that everyone on the team can understand and support and not the latest shiny thing.
Update tests and docs as you go
One of the most expensive things in development is context. Not unlike an agent's context window, our brains have a context window of their own. The more time passes since the code is written the more of that context is lost to time and other important things in life. I wish I could remember why that one endpoint uses a different JSON parser from the rest but that spot is now permanently taken by my grandma's lasagna recipe. The code tells the story of "what", git history tells the story of "when" but only the documentation and tests tell the story of "why".
Yes, it's so much more convenient not to document the code and yes, you've just proven that it works. No, I don't think you should skip doing that. Writing up a short doco directly after the code is finished is incredibly cheap. Even more so now that AI provides effortless drafting and editing tools. Unload the context into the doco or a code comment and go fill it with whatever else floats your boat.
Similar logic applies to testing. While we all test our code to some extent, having a dedicated suite of tests provides you with two very tangible benefits.
First, you document the exact part of the behaviour that matters. This might be an edge case that you found during the development and had to write up some obscure code to fix. Or it might be sequencing of events that matters in practice but can be easily lost during a refactoring. It might even be a confirmation that something is broken in a specific way and the test should fail when it gets fixed. All up it's a very easy way to convey the "why" of the development in a binary reproducible format.
Second, the test should fail when something important changes. It is a signal for the next person to slow down and think about it. Was that expected? Was my intention to change the behaviour of the system? If yes, here is a golden opportunity to update the test and solidify the new behaviour. If no, well, it clearly doesn't do what you think it does and it's time to get back to the drawing board.
Tests and docs are the easiest way to snapshot the state of the universe. Seize the opportunity.
The points above are by no means an exhaustive list of approaches. There are many ways to skin a cat.
However, I hope that you've noticed that the common thread between them is caring. Giving a shit about the work you put out there is vital to software engineering.
Really stop and think about what you are doing, don't be a robot. You've got an agent for that.
Speaking of mechanical things, let's have a look at practical ways to prevent your pipeline from exploding.