Alt Title: Communication is Hard
I’ve been thinking a lot about the best way to write maintainable code for the past few months, after reading this debate1 between John Ousterhout and Robert “Uncle Bob” Martin regarding their differing philosophies on software design.
My introduction to clean coding was this video series2, which I’ve watched several times. It has greatly influenced my opinions on the importance of writing maintainable code, but there were always a couple parts of it that didn’t sit well with me. The debate between Ousterhout and Uncle Bob really dug into them3.
I don’t have anywhere close to the experience that those two have, but I would like to get my thoughts down in text. I’m relatively new to formal software development, but I’ve dabbled in coding as a hobbyist since the 90s, so I still have a lot of experience in seeing incomprehensible code. Also, I think there’s a perspective on “what code is easy to understand” that only a new person can bring.
Perhaps I’m way off base, and perhaps I have the insight of an outsider. Either way, this will be interesting to look back at in a few years.
Why is Just An Abstraction of What
I think one of the most pointed examples of the difference in their philosophies is an early example of a contrived method called makeStatement. These are the two versions presented, each strongly preferred by one of Ousterhout and Uncle Bob:
public String makeStatement() {
amountOwed=0;
totalPoints=0;
return makeHeader() + makeRentalDetails() + makeFooter();
}
public String makeStatement() {
clearTotals();
return makeHeader() + makeRentalDetails() + makeFooter();
}
I spent a lot of time thinking about the difference between those two methods, and why someone might prefer one over the other. My conclusion is that the first example provides a clearer description of what is happening, while the second provides a clearer description of why it’s happening.
That observation is not particularly new. The need to explain the “why” is a well trodden need in maintainable coding, and so is the need to understand “what”. If I’m going to try to figure out when and where each might be most important, I’ll need to come up with some kind of definition… and then came the rabbit hole.
I quickly came to understand that neither why nor what is concrete. They are completely relative to each other. This can be taken to an extreme in either direction.
It’s the classic case of the toddler that keeps asking why. If we start with a = b + c, the why might be “calculate the total”, and then we keep going…
calculate the total -> figure out how much the customer owes -> bill the correct amount -> get money without blowback -> get repeat business -> get lots of business -> get lots of money -> live a certain lifestyle -> be happy…4
And it breaks down in the other direction as well…
programming language math abstractions <- add instruction in assembly <- hardware add instructions <- ALU <- adder <- logic gate <- transistor…
Why is just an abstraction of what. It’s impossible to look at a piece of code and say “that represents the ‘why’ “, because “why” is always relative.
Along the way, I decided to add “how” into the mix as well. Just as “why” is an abstraction of “what”, it’s also just as true that “what” is an abstraction of “how”.
Although this doesn’t let me define exactly what counts as “why”, it does allow a different kind of standardization:
“What” is your current frame of reference. “Why” is one level of abstraction up. “How” is one level of abstraction down.
This maps well to thinking about whether code could be easily understood. It’s kinda like the rungs on a ladder. You move up and down the rungs as you move through abstractions5. This also roughly maps onto some forms of code tree analysis.
OK, so we need to make sure the important context is readily available, and the rest is what should be abstracted away. What is the “important context” that needs to be understood? As is almost always the case, it depends… understood by who?
The Many Code Reviewers
I’ve come up with the (non-exhaustive) list of code reviewers below. I’ve made my best attempt to succinctly capture how much each reviewer needs to understand what is up the ladder and what is down the ladder (relative to whatever their current context).
- PR Reviewer
- Their What: What does this change do? What is the impact on the bigger structure?
- Up or Down: Up first (what is the intent of this PR?), then down as necessary (e.g. explore new called methods), then back up to assess impact on the surrounding system
- New to the Codebase
- Their What: What are the major architectural parts of this codebase? What are the interactions? What are the conventions?
- Up or Down: Ideally, starts at the top and moves down, but often starts at a random point and expands in all directions
- Debugging an Existing Issue
- Their What: What is this code doing? What affects this piece of state?
- Up or Down: Typically involves drilling down into the how, but the fix action will need a good understanding of why
- Unknown Bug Hunting
- Their What: What is this code doing versus what should the code be doing?
- Up or Down: Understanding up is critical before moving down to look deeper
- Vulnerability Hunting
- Their What: What can be misused?
- Up or Down: Up helps frame what should be expected, but the biggest value is likely to come from digging down to find the gaps in implementation vs intent
- Performance Optimization
- Their What: What is wasteful or unnecessary?
- Up or Down: Up is foundational to even knowing what counts as waste. The process involves digging down a lot, but the analysis is relative to the expectations of “why”
- Clearing Tech Debt
- Their What: What can be simplified? What is outdated?
- Up or Down: Up is critical to knowing what would count as outdated and what can be cut/changed for simplification
- New Feature Planner
- Their What: What are the connection points for the new feature?
- Up or Down: The bigger picture is important, while the details of how often only matter at the seams
- Auditor
- Their What: What doesn’t meet standards?
- Up or Down: This is a wild card and could match any of the above, depending on what standards need to be met
A few observations I made while putting together that list:
- The PR reviewer holds two whys at the same time: the why of the code and the why of the PR itself. A lot of their effort is about making sure those two match. This applies to others to varying degrees, but it is most notable for the PR reviewer.
- Evaluating the code typically focuses on looking up the abstraction ladder. Working on the code is the main driver of looking down. This makes sense, but it was interesting to see it laid out.
- Shared state sidesteps all of this. I’ll touch on this a bit more later, but it’s mostly outside the scope of this post.
The Right Answer
Spoiler! There isn’t one! Or at least there isn’t only one. There are many right answers depending on the reader and the situation.

The answer is that communication is hard6, and there’s no getting around that. It’s messy and circumstance dependent. It depends on subconscious context that people bring into the situation that they may not even know exists.
Still, it’s not like we can have different versions of the code to suit different reviewers7. Instead of looking for the right answer, I’d like to think about what, or who, to prioritize. I think there are two main candidates:
- PR Reviewer: For this section, this includes anyone reviewing a change (including reviewing an AI change). This probably has the biggest impact on production in the short to medium term, especially in the AI-coding era.
- New to the Codebase: This includes people who are new to this part of the codebase or just haven’t seen it in a while and are effectively new to it. This has significant implications for long-term productivity.
Most of the other use cases are limited. Also, in today’s AI-assisted environments, those two personas rely the most on gaining an understanding of the codebase that exists outside of AI. The Feature Planner persona may be an exception, depending on how hands-on they want to be with the planning, but it is still likely to collapse into a review at some point. The Auditor’s requirements may be more important than anything else in specific situations, but it’s not a good basis for generalized conventions.
Also, speaking of AI, it’s worth noting that the conventions that help humans understand code are important for AI too. AI is even less equipped to understand the why when it’s not expressed in the code somewhere.
Of the two, I lean towards the PR Reviewer as the top priority. Onboarding can be assisted by documentation, and once they dig into the code, their needs look fairly similar to the PR Reviewer anyway.
OK, cool. We’re prioritizing the PR Reviewer. Now what?
The Plan
The challenge is to figure out when an abstraction is valuable. When does hiding the implementation make understanding the current “what” easier? Both switching rungs on the abstraction ladder and not switching come with a cost (the cost of switching context and “the current context is heavier” respectively).
A rough guideline as I continue: keep visible what the reviewer needs to verify and extract what the reviewer can understand by name.
Function calls (in all the forms they take) will be considered the main tool for abstraction, although structures can also contribute (e.g. custom Money type vs a bare int). Also, code (meaning the words that appear in the source code) is shaped by function calls. To put it another way, function calls will decide the order a reader is introduced to the code.
Structures can’t be ignored though. The elephant in the room is that, as noted above, shared state can sidestep everything else. All of the reviewer personas are aided by understanding the reach of each variable (e.g. “What else modifies or relies on this value?”), and reach often extends beyond its formal scope (e.g. a private field might still be reached via getter/setter methods).
Programming languages can also add features that assist with managing state (Rust’s borrow checker comes to mind). It’s also possible to minimize reach to limit the risk(functional programmers rejoice!). However, both of those are very high-level structural decisions that are pretty much set by the time the reviewer is trying to figure out what they’re looking at.
Within the scope of this blog post, variable naming conventions and custom types are the main way to guard against shared state issues (e.g. _var for private fields).
The Proposal
Here are my proposed guidelines for determining when something should be abstracted:
- An abstraction must be succinctly summarized in a name
- One of the following must almost always be true:
- The name is easier to understand than the code
- The abstraction is necessary to follow established conventions or local patterns (e.g. in a switch statement where most options pass to complex functions, it may be worth extracting single line functions for consistency)
- Decisions that determine the caller’s control flow must almost always stay local to the caller
- Abstractions can retrieve the information necessary to make the decision (e.g. a
hasPermission()method), but the callee reports and the caller decides - Fatal exceptions don’t break this rule because they aren’t intended behavior
- Abstractions can retrieve the information necessary to make the decision (e.g. a
- Abstractions generally should operate on a subset of the current state
- Passing a lot of arguments to a small piece of code is a good indicator that this principle is being violated
- Counter-example: a function that calls several other functions that each complete a single phase of the overall process using most or all of the state
- Abstractions generally should not change state that is used or modified by the caller (including in other function calls)
- This is very often unavoidable, but it should be biased against
- When unavoidable, the name generally should express that changes can/will happen (i.e. command/query pattern)
The following proposed guidelines would also apply:
- Shared functions to reduce duplicated code should only be done to prevent situations where future changes would need to reliably be updated in all locations
- This explicitly does not cover abstracting repeated code for the sake of making the code shorter or just because it’s repeated
- Comments in lieu of abstractions should be used in the following cases:
- To explain the “what” of a clearly distinct8 code block (e.g. the code inside an
ifstatement) where a function call removes potentially important context or would otherwise violate the rules above - The comment explains “what”, not “how” or even “why” (i.e. if it were a function, what would it be named?)9
- To explain the “what” of a clearly distinct8 code block (e.g. the code inside an
Names as Comments
This is really just another part of my proposed guidelines, but I’d like to dive into it a bit deeper.
In the discussion that I linked at the beginning of this post, Uncle Bob advocates for using function names as comments. I don’t think it’s covered specifically in that document, but I’ve seen him advocate for close to the same with variable names10. Ousterhout pushes back on this idea, or at least on the degree that Uncle Bob advocates.
Both agree that descriptive function names are important, but I don’t think either quite gets to a full answer. Even Uncle Bob acknowledges that there is an extreme where it can be overdone, but what is the point of excess? What’s the Goldilocks zone?
I’ll start by noting that, when I first read the PrimeGenerator example from Uncle Bob’s book, I felt much the same way that he feels about comments. Uncle Bob mentions that he doesn’t fully trust comments and typically feels the need to verify them. When reading his descriptive method names, I found myself doing the same with the methods. I’d read the descriptive name of a method and then immediately dig into the method to see if that’s really what it does. Sometimes it wasn’t even a trust issue. I just needed to know the “how” as I analyzed the code, and that naturally required digging into the method, and I would be comparing that to the method name as I went along.
This helped me realize an issue with that practice. It overloads the method name. Method names are identifiers first, and comments second. If the comment-nature of the name interferes with the identifier-nature of the name, that is a bad tradeoff.
With that, I’ll add one more proposed guideline:
- Abstraction names should be simple to understand
- If a name needs to be “parsed” instead of just read, it’s likely too complicated
The above rule may lose some information at the call site, but the name should only carry the “what”. Definition comments can carry the contract details and caveats. The code itself carries the how. In situations where extra context is needed at the call site, the function should be accompanied by a comment.
Also, while on the topic of PrimeGenerator example from the referenced text, I think both of them get bogged down in something that causes them to somewhat miss the meat of their discussion.
Sometimes the algorithm is just hard to understand and code conventions can’t fix that.
This is the case for the prime number algorithm they were working with. They both get lost in whether their preferred coding standards make the algorithm clear, but I would argue that the particular algorithm being used would be difficult to understand regardless of how it’s presented. Poor coding standards can make the situation worse, but there’s a complexity floor of the algorithm itself that can’t be fixed by the code.
The Result
Given the guidelines above, what is the result? Let’s look at the two proposed variants of makeStatement again:
public String makeStatement() {
amountOwed=0;
totalPoints=0;
return makeHeader() + makeRentalDetails() + makeFooter();
}
public String makeStatement() {
clearTotals();
return makeHeader() + makeRentalDetails() + makeFooter();
}
Running through the guidelines:
The proposed abstraction…
- can be summarized in a name โ
- doesn’t determine local control flow โ
- works on a subset of local state โ
- doesn’t need a lot of arguments โ
- affects local state โ
- has a name that indicates state will be changed โ
- is possibly easier to understand than the code (they debate this)๐คทโโ๏ธ
My verdict: don’t abstract.
Regardless of whether the name is easier to understand than the code, it hides the details of the modified state. That isn’t a hard rule, but it should be biased against, and the abstraction doesn’t otherwise provide significant value. The cost in “heavier local context” from not abstracting is low compared to the potential cost of the context switch of a function call. In this case, inlining is cheap and abstraction is expensive in the cases where the details matter.
If we consider the PR Reviewer target persona, it’s somewhat of a wash. Whether or not the reviewer wants to know the details of clearTotals depends on how well they know the code and what other changes exist. However, the New to the Codebase persona likely will want to know what’s happening inside that method. Given the low cost, not abstracting still seems like the better option.
I believe the first version is probably fine as it is. However, if there is concern over it being unclear what those variable resets are for, the context can be added with a comment, over a clearly distinct block of code:
public String makeStatement() {
// clear totals
amountOwed=0;
totalPoints=0;
return makeHeader() + makeRentalDetails() + makeFooter();
}
Closing
If you’ve made it this far, you probably either really like or really dislike my recommendation. I’d love to hear any counterpoints or disagreements. Coding conventions are an art without a perfect solution, and I know it’s something I can always get better at.
- Link rot guard: the John OusterhoutโRobert “Uncle Bob” Martin discussion on GitHub discussing their different philosophies on method length, comments, and test-driven development. โฉ๏ธ
- Link rot guard: the “Coding Better World Together” clean code video series from UnityCoin on YouTube. โฉ๏ธ
- The biggest one for me was method length. โฉ๏ธ
- No comment on whether these are actually sound methods to achieve the why. โฉ๏ธ
- While doing some sanity checking on my outline for this post, I found that this isn’t really new either. Hayakawa beat me by 87 years! โฉ๏ธ
- Thank you Col Ritchie for adding that to my lexicon. โฉ๏ธ
- Startup idea! โฉ๏ธ
- “Clearly distinct” means easy to skip. If it’s a 50-line loop where you need the IDE to verify you found the right closing bracket, that doesn’t count. Most likely, something inside the loop should be abstracted. โฉ๏ธ
- This doesn’t apply to all comments. Explaining “why” is often a great reason for a comment. This is just a guideline for a “comment in lieu of an abstraction”. โฉ๏ธ
- He has a set of guidelines for both that I won’t cover here, but I want to acknowledge that his advice has more depth than I’m stating. โฉ๏ธ

