The Hidden Query Inside Every Good Docstring
Hatched by Kai Nguyen
Aug 17, 2026
10 min read
1 views
88%
What if the most important skill in programming is not writing instructions, but deciding what deserves to be visible first?
A database query and a Python docstring appear to belong to different worlds. One retrieves rows. The other explains code. Yet both solve the same deeper problem: a complex system contains more information than a human can process at once.
The database designer asks: Which records should appear, in what order, and with which repetitions removed? The programmer asks: What should a reader understand immediately, and what deserves further explanation? In both cases, quality depends on controlling attention.
This suggests a powerful principle for technical work and perhaps for thinking itself:
Good systems do not merely contain information. They shape the sequence in which information becomes useful.
Once we see documentation and data retrieval as two versions of the same design problem, familiar conventions become much more significant. A summary line is not just a style preference. A WHERE clause is not just syntax. Both are mechanisms for turning an undifferentiated mass into an intelligible experience.
The hidden problem is not storage, but attention
Imagine opening a table containing ten thousand books. The records may include titles, authors, genres, publication years, publishers, and identifiers. Nothing prevents the table from containing everything. The challenge is that a person rarely wants everything.
They may want books published after 2010. They may want only the genres represented in the collection. They may want the newest books first. They may want to know whether a particular category exists at all. Each question requires a different transformation of the same underlying material.
SQL gives us a vocabulary for these transformations. WHERE filters rows according to a condition. ORDER BY controls sequence. DESC reverses the natural direction of comparison. DISTINCT removes repetition when repeated values are not meaningful to the question.
Documentation has analogous operations. A one line docstring gives the fastest useful orientation. A blank line separates the immediate summary from the fuller explanation. An additional docstring can preserve context near an attribute or a block of code. The conventions do not merely tell writers where to put text. They establish a retrieval system for readers.
A reader encountering a function is performing a query, even if no database is involved. Their implicit request might be:
SELECT purpose FROM function WHERE comprehension_is_blocked = true;
The best documentation returns the answer quickly, then offers more detail when the reader asks for it. Poor documentation forces the reader to scan every available fact before discovering the one fact that matters.
This is why information architecture is a form of compassion. It recognizes that readers arrive with limited time, incomplete context, and a specific question that may not yet be perfectly articulated.
Summary first, detail second
A useful docstring convention asks for a summary line followed by a blank line and then a more elaborate description. This structure encodes a theory of reading: people need a compact orientation before they can interpret detail.
Consider a function that calculates a shipping estimate. A weak explanation might begin with a history of postal zones, edge cases, and internal assumptions. A stronger opening says, in effect, “Calculate the estimated delivery date for an order.” That sentence answers the first question in the reader's mind: What does this thing do?
Only after that orientation should the documentation explain inputs, rules, exceptions, and implementation details. The sequence matters because detail without a frame increases cognitive load. A reader cannot easily decide which facts are important when the purpose is still unclear.
The same principle applies to query results. Suppose a user asks for the genres in a library. Returning every book row is technically informative but practically noisy. The question concerns categories, so a query using DISTINCT produces a more faithful answer. It removes repetition not because duplicate rows are always bad, but because repetition is irrelevant to this particular question.
This gives us a general model:
- Orient the user with the smallest useful statement.
- Filter information according to the user's actual question.
- Order the result so the most relevant material appears first.
- Expand only when more context is needed.
A docstring's summary line performs orientation. Its detailed description performs expansion. A WHERE clause performs filtering. ORDER BY performs prioritization. DISTINCT performs conceptual compression.
The connection is more than metaphorical. Both practices force the creator to distinguish between available information and necessary information. That distinction is the foundation of usable systems.
The danger of confusing completeness with usefulness
Technical people often reward completeness. A function description that mentions every parameter, exception, assumption, and internal step can look rigorous. A query that returns every column and every matching row can look transparent. Yet completeness can become a form of negligence when it leaves the reader to perform the work of selection.
The familiar habit of using SELECT * illustrates the problem. It asks the system to return every column, whether or not those columns serve the current purpose. For exploration, this can be convenient. For a stable interface, it can be fragile and noisy. The result may include fields that obscure the important ones, increase transfer costs, or change unexpectedly when the table evolves.
Documentation has its own version of SELECT *. It is the paragraph that attempts to explain everything at once. It may include implementation history, internal terminology, caveats, and incidental details before stating the central purpose. Such writing is not necessarily false. It is simply poorly queried.
The remedy is not minimalism at all costs. A one line docstring is appropriate only when the case is genuinely obvious. If a function has surprising behavior, important constraints, or consequences that are not apparent from its name, a summary alone is insufficient. The issue is not length. The issue is layering.
Layered information lets different readers stop at different depths. A hurried developer may need only the summary. Someone integrating the function may need parameter behavior. Someone debugging a failure may need assumptions and edge cases. The same documentation can serve all three if it presents information in descending order of general usefulness.
The principle also clarifies when DISTINCT helps and when it hides something. If the question is “Which genres occur?” repeated genres are noise. If the question is “How many books belong to each genre?” removing duplicates would destroy the evidence needed for the answer. Compression is useful only relative to purpose.
The right amount of information is not the least information possible. It is the least information that preserves the decision the reader needs to make.
This is a more demanding standard than brevity. It asks whether every included detail earns its place by improving understanding, preventing misuse, or enabling action.
Order is not decoration
People often treat order as a cosmetic choice. A list is considered correct if it contains the right items, regardless of sequence. But the sequence of information changes what readers notice, remember, and trust.
Rows in a table are not necessarily ordered in any meaningful fashion. Without an explicit ordering instruction, the database makes no promise about which result appears first. This is a useful reminder that accidental order is not reliable order.
The same is true of prose and code interfaces. If the most important explanation appears after five paragraphs of setup, it may as well be missing for a reader under pressure. If exceptions are buried after normal behavior, users may build the wrong mental model. If a function's summary describes an edge case before its primary purpose, the interface feels harder than it is.
ORDER BY publication_year DESC expresses a clear priority: show the newest publications first. In documentation, an equivalent choice might be to present the normal use case before rare exceptions, or to state the output before describing the internal mechanism. In both situations, ordering converts a collection of facts into a path.
This leads to a practical distinction between truthful information and truthfully arranged information. Every sentence can be accurate while the overall explanation remains misleading because of emphasis and sequence. A query can return the correct rows while still failing the user because the relevant result is difficult to find.
Good interfaces therefore answer three separate questions:
- What belongs in the result?
- What should appear first?
- What should be omitted unless requested?
These questions are often collapsed into one vague goal called clarity. Separating them makes clarity actionable. Filtering controls membership. Ordering controls attention. Layering controls depth.
We can call this the FOD model: Filter, Order, and Depth.
Filter removes information unrelated to the current task. Order places high value information where it will be encountered early. Depth allows the reader to move from orientation into explanation without being forced into either extreme.
The model applies to a query, a docstring, an error message, a dashboard, a design document, or an entire application. It is a compact way to inspect whether an interface respects the reader's cognitive bandwidth.
Write interfaces as if someone will query them under pressure
The strongest test of documentation is not whether it sounds polished when read from beginning to end. The test is whether a person can retrieve the needed answer while distracted, unfamiliar with the code, or trying to repair a failure.
That perspective changes how we write. We begin with a summary that can stand alone. We use consistent triple double quotes for Python docstrings because conventions reduce friction for both people and tools. We keep a one line form for genuinely obvious cases, rather than compressing complicated behavior into a misleading sentence. We add detail when the reader's likely questions justify it.
It also changes how we construct queries. We do not assume that a table's physical arrangement expresses meaning. We state filters explicitly with WHERE. We state priorities explicitly with ORDER BY. We request unique values when the question concerns categories rather than individual records. We select the shape of the result to match the decision it will support.
A small example makes the relationship concrete. Suppose a team maintains a function that returns books published within a year range. Its documentation might begin with the purpose, then explain that the bounds are inclusive, then note what happens when no books match. The corresponding query might filter by the year range, order the results from newest to oldest, and select only the fields needed by the display.
The function and the query are both answering a user shaped by constraints. The reader does not need the entire database schema. The caller does not need every internal calculation. They need a reliable, well ordered answer with enough context to use it safely.
This is also why conventions matter even when tools do not enforce them. A convention is a shared expectation about where meaning will be found. Consistent structure lowers the cost of every future interaction. It allows a reader to scan rather than investigate.
Key Takeaways
- Separate orientation from explanation. Start with the smallest accurate summary, then provide the detail needed for safe and effective use.
- Treat every interface as a query. Ask what the user is actually trying to retrieve, and remove information that does not serve that question.
- Make order explicit. Do not rely on accidental sequence in database results, documentation, or user interfaces. Put the most useful information first.
- Use compression purposefully.
DISTINCTand concise summaries are valuable when repetition is irrelevant, but harmful when they erase distinctions the user needs. - Review for Filter, Order, and Depth. Before publishing a query or docstring, check what is included, what leads, and what remains available for deeper investigation.
The deeper lesson is that documentation and data retrieval are not separate disciplines. Both are acts of interpretation. They take a system that contains more possible meaning than any one person can absorb and construct a route through it.
That route can be careless, making the reader sort, rank, and deduplicate the material alone. Or it can be designed, giving them the right summary, the relevant records, the meaningful order, and the option to go deeper.
The next time you write a docstring or a query, do not ask only whether it is correct. Ask a harder question: What will the reader encounter first, and will that first encounter help them form the right question?
A well designed system does not merely answer questions. It teaches people how to ask better ones.
Sources
Hatch New Ideas with Glasp AI 🐣
Glasp AI allows you to hatch new ideas based on your curated content. Let's curate and create with Glasp AI :)
Start Hatching 🐣