The Hidden Discipline of Making Machines Read Fast and Humans Read Once

Kai Nguyen

Hatched by Kai Nguyen

Apr 27, 2026

9 min read

74%

0

The Same Problem Hides in Two Different Places

What if the fastest code and the clearest prose are built on the same principle: help the reader find the answer without searching?

That question sounds too broad at first, until you notice a strange symmetry. In one world, a database engine tries to satisfy a query. In another, a human tries to understand a function, a module, or a line of code. In both cases, the cost of confusion is real. The machine pays in scans, sorts, and wasted computation. The human pays in rereads, wrong assumptions, and avoidable bugs.

The deeper issue is not speed alone. It is friction. Every unnecessary operation, whether in SQL or in a docstring, creates friction between intention and understanding. The craft is not simply to make something work. It is to structure it so the next step is obvious.

The best systems, human or machine, do not reward cleverness. They reward legibility.

That is the hidden connection between query optimization and documentation conventions. Both are about designing for a reader who arrives with a question and deserves a direct path to the answer.


Efficiency Is Not a Trick, It Is a Shape

A database is not slow because it is lazy. It is slow when its shape forces it to do more work than necessary. If you wrap an indexed column in arithmetic, negate it in the wrong place, or hide it behind a leading wildcard, you have changed the shape of the question. The engine can no longer take the shortest route, so it falls back on brute force.

This is why SARGable queries matter. A SARGable condition is one the engine can search efficiently, often by using an index rather than scanning everything. The point is not to memorize the acronym. The point is to understand the design ethic behind it: express your intent in a form the system can act on directly.

That ethic shows up in writing too. A docstring that starts with a precise summary line does not merely provide information. It gives the reader a route. One line says, in effect, “Here is the answer to your first question.” A blank line then creates a pause, and the longer explanation deepens the answer without burying it.

This is not a cosmetic rule. It is a cognitive one. People, like query engines, benefit when the high value information appears early and in a predictable shape. A clean summary line is the human equivalent of an indexed lookup: a quick way to orient before diving deeper.

Think about the difference between these two explanations:

def normalize_scores(scores):
    """Normalize scores.

    Scale a list of numeric scores so the largest value becomes 1.0 and all
    others are proportional to it. Returns an empty list if scores is empty.
    """

versus:

def normalize_scores(scores):
    """Process scores in a standard way.

    This function performs a normalization transformation across an iterable
    of numerical inputs using an internally defined scaling procedure.
    """

The second may be technically accurate, but it forces the reader to hunt for the point. The first behaves like a good query plan. It surfaces the likely answer immediately.


The Real Opponent Is Unnecessary Work

SQL optimization advice often sounds tactical: use indexes, avoid leading wildcards, filter early, limit result size, avoid unnecessary sorting and grouping. But the principles behind those tactics are structural. They all reduce the amount of work done before usefulness appears.

That is exactly what well written docstrings do. A one line summary is useful because it reduces the work required to classify the function. The longer paragraph is useful because it reduces the work required to use it correctly. Even the recommendation to use triple double quotes consistently is not just style trivia. Consistency lowers parsing effort for both tools and people. It makes documentation easier to discover, extract, and trust.

Here is the surprising link: both databases and readers punish hidden work. If the system has to infer too much, it becomes slower or more error prone. If you force it through detours, it gets less reliable.

Consider three patterns that appear in both domains:

  1. Filter early. In SQL, reduce rows as soon as possible. In writing, state the function’s purpose before discussing edge cases or implementation details.

  2. Avoid transformations on the thing you want to search. In SQL, wrapping an indexed column in a function can block index usage. In documentation, burying the core purpose inside vague language blocks comprehension.

  3. Keep the common path obvious. In SQL, optimize for the frequent query. In code comments, optimize for the question a maintainer is most likely to ask.

This is why the best docstrings often look deceptively plain. They are not trying to impress you. They are trying to save you effort.


Why a Summary Line Works Like an Index

An index is not the data itself. It is a compressed route to the data. That is a powerful mental model for documentation.

A good docstring summary line is an index entry for a function’s purpose. It answers the most important question at the top level: what is this thing for? The blank line that follows acts like a boundary between the fast path and the deep path. The detailed paragraph then explains the constraints, assumptions, and special cases that matter once the reader has oriented themselves.

This structure matters because people rarely read code the way they read an essay. They scan first, then zoom in. If the summary is weak, the scan fails. If the summary is strong but the explanation is absent, the zoom fails. The best docstrings support both modes.

A useful way to think about this is the lookup ladder:

  • First rung: What does it do?
  • Second rung: When should I use it?
  • Third rung: What should I watch out for?
  • Fourth rung: How does it behave in edge cases?

Good SQL honors the same ladder. The execution plan should quickly answer: what rows are needed, how can they be located, what can be skipped, and what would force a full pass? If you make the first rung expensive, everything below it becomes more costly.

This is why leading wildcards are so damaging to index use. A search like '%abc' asks the engine to find matches without knowing where to start. It is the database equivalent of a docstring that opens with abstractions, caveats, and implementation minutiae before saying what the function actually does.

Clarity is not an ornament added after the work. Clarity is what makes the work searchable.

That sentence applies equally to query design and to code documentation.


A Practical Framework: Design for the First Read and the Cheapest Path

There is a deeper synthesis here that goes beyond either topic alone: every artifact has an execution order.

SQL has one. The database may write the query in one sequence, but it logically resolves filters, joins, projections, sorting, and limits in an order that determines cost. Documentation has one too. A reader encounters the title, then the summary, then the supporting detail, then the implementation specifics. If you ignore that sequence, you create unnecessary cognitive load.

This suggests a practical framework for both code and prose:

1. Put the answer where the search begins

For SQL, make your predicates searchable. Use conditions that allow the engine to narrow efficiently. For docstrings, put the one line summary first. Do not force the reader to decode the details before they know the point.

2. Preserve the native shape of the thing being searched

If a column is indexed, let the query speak in terms that preserve that index. If a function is meant to be obvious, let the docstring speak in direct language. Avoid syntactic transformations that obscure the underlying intent.

3. Separate orientation from elaboration

A summary line or an early filter or a tight index condition serves orientation. The follow up explanation, join, or detailed paragraph serves elaboration. When those roles are mixed, both suffer.

4. Reduce the number of decisions required at the top

In SQL, unnecessary calculations, sorts, and groupings delay results. In writing, too many qualifiers or vague abstractions delay understanding. The first task is not to be exhaustive. It is to be usable.

5. Optimize for the common question, not the rare clever one

Most users of a function want to know what it does, when it fails, and what it returns. Most queries need the simplest effective path. Design for that path first. Optimize special cases later.

This framework can change how you read your own code. When a query is slow, ask not only, “How do I make it faster?” but also, “What am I forcing the engine to discover late?” When a docstring feels weak, ask, “What am I making the reader infer instead of telling them directly?”

The same diagnostic question applies in both cases: where is the first moment of certainty?


Key Takeaways

  • Make the first read cheap. In SQL, that means structuring conditions so indexes can help. In docstrings, that means leading with a precise summary line.
  • Do not hide intent behind transformations. Wrapping indexed columns in functions, or burying a function’s purpose in vague language, both create avoidable friction.
  • Separate orientation from detail. Give the reader or engine a fast way to understand the shape of the problem before adding nuance.
  • Optimize for the common path. Most performance gains and comprehension gains come from helping the typical case, not the edge case.
  • Treat clarity as infrastructure. Good structure is not decoration. It is what makes both systems fast, maintainable, and trustworthy.

The Best Optimization Is to Be Easy to Use

We usually talk about performance and clarity as if they belong to different disciplines. One is technical, the other literary. One serves machines, the other serves humans. But the deeper lesson is that both are about respecting the reader’s path.

A database engine is a literal reader of your query. A maintainer is a human reader of your code. Both do best when you do not make them search harder than necessary. The most elegant systems, whether lines of SQL or lines of prose, do not merely contain the answer. They lead to it efficiently.

That is the real lesson hiding inside both query optimization and docstring conventions. The goal is not to be clever, exhaustive, or ornate. The goal is to create a form that makes truth easy to find. Once you see that, you start to recognize the same discipline everywhere: in indexes, in summaries, in filters, in the first sentence, in the first clue.

And maybe that is the highest form of craftsmanship: not writing for admiration, but designing so that understanding arrives quickly, cleanly, and with almost no wasted motion.

Sources

← Back to Library

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 🐣