Robustpython Preview
Robustpython Preview
author’s intent and calling code. The author intended to solve a problem, but I am
unsure of why they wrote the code the way they did. Why are they popping elements?
Why is <servings= a tuple inside the list? Why is a list used? Presumably, the original
author knew why, and communicated it locally to their peers. Their peers wrote call‐
ing code based on those assumptions, but as time wore on, that intent became lost.
Without communication to the future, I am left with two options of maintaining this
code:
• Look at all calling code and confirm that this behavior is not relied upon before
implementing. Good luck if this is a public API for a library with external callers.
I would spend a lot of time doing this, which would frustrate me.
• Make the change and wait to see what the fallout is (customer complaints, broken
tests, etc.). If I’m lucky, nothing bad will happen. If I’m not, I would spend a lot of
time fixing use cases, which would frustrate me.
I’ve replaced variables with types, such as a recipe type and an ingredient type. I’ve
also defined operations (clear_ingredients, adjust_proportion) to communicate
my intent. By making these changes, I’ve made the code’s behavior crystal clear to
future readers. They no longer have to come talk to me to understand the code.
Instead, they comprehend what I’m doing without ever talking to me. This is asyn‐
chronous communication at its finest.
Asynchronous Communication
It’s weird writing about asynchronous communication in a Python book without
mentioning async and await. But I’m afraid I have to discuss asynchronous commu‐
nication in a much more complex place: the real world.
Asynchronous communication means that producing information and consuming
that information are independent of each other. There is a time gap between the pro‐
duction and consumption. It might be a few hours, as is the case of collaborators in
different time zones. Or it might be years, as future maintainers try to do a deep dive
into the inner workings of code. You can’t predict when somebody will need to
understand your logic. You might not even be working on that codebase (or for that
company) by the time they consume the information you produced.
Discussion Topic
This plot in Figure 1-1 was created based on generalized use cases.
Think about the communication paths you and your organization
use. Where would you plot them on the graph? How easy is it to
consume accurate information? How costly is it to produce infor‐
mation? Your answers to these questions may result in a slightly
different graph, but the single source of truth will be in the exe‐
cutable software you deliver.
Low cost, low proximity communication methods are the best tools for communicat‐
ing to the future. You should strive to minimize the cost of production and of con‐
sumption of communication. You have to write software to deliver value anyway, so
the lowest cost option is making your code your primary communication tool. Your
codebase becomes the best possible option for expressing your decisions, opinions,
and workarounds clearly.
However, for this assertion to hold true, the code has to be cheap to consume as well.
Your intent has to come across clearly in your code. Your goal is to minimize the time
needed for a reader of your code to understand it. Ideally, a reader does not need to
read your implementation, but just your function signature. Through the use of good
types, comments and variable names, it should be crystal clear what your code does.