Why Good Systems Separate What Varies from What Should Stay True

Kai Nguyen

Hatched by Kai Nguyen

May 12, 2026

10 min read

86%

0

The Hidden Rule Behind Better Databases and Better Code

What do a database query and an object in Python have in common? More than most people realize. Both are ways of answering the same deeper question: what belongs together, and what must remain separate? That question sits underneath everything from selecting rows in a table to designing a class hierarchy.

At first glance, SQL and object oriented programming seem to live in different worlds. One asks for the right rows, the other builds the right objects. But both are really about shaping information so that it can be understood, filtered, reused, and trusted. The surprising insight is that good data retrieval and good software design are not just technical skills. They are two expressions of the same discipline: learning how to carve reality into stable patterns without losing the details that make things useful.

The best systems do not store everything the same way. They preserve what is shared, isolate what varies, and make both easy to query.

That principle sounds abstract until you see how it shows up in practice. In a database, you use a WHERE clause to isolate only the rows that satisfy a condition. In Python, you use a class to define what every instance has in common, then let each object carry its own values. In both cases, the design challenge is not merely storing information. It is deciding which differences matter.


The First Mistake: Treating Everything as if It Already Has Order

One of the most important lessons in data work is also one of the easiest to miss: data is not naturally ordered. If you want a meaningful sequence, you must specify it. Otherwise, the table may return rows in any arrangement. That is not a bug. It is a warning.

This matters far beyond SQL. In programming, people often assume that the world will present itself in a tidy, stable order. But raw information rarely does. Books do not arrive sorted by publication year. Customers do not arrive sorted by value. Events do not arrive sorted by importance. Order is something you impose after deciding what question you are asking.

That is why ORDER BY is not decoration. It is a declaration of intent. If you sort by publication year descending, you are saying that recency matters more than chronology. If you sort by another column, you are revealing what you think should come first. In other words, ordering is a form of judgment.

The same idea appears in object oriented programming. A class is not the thing itself. It is a blueprint for what counts as the same kind of thing. An instance is the actual object with real data. The distinction seems simple, but it is profound. A class says, “These are the rules that make this thing intelligible.” An instance says, “Here is one concrete case.”

When developers confuse those two levels, systems get messy. They put values that should be shared into every object separately. Or they hide values that should vary inside one shared structure. The result is duplication, confusion, and brittle code. The same failure happens in database thinking when we treat every row as if it deserved the same shape of attention, regardless of whether it belongs in the result set.

So the first big insight is this: clarity begins by refusing to assume order, sameness, or relevance before the system has earned it.


The Real Power of WHERE: Filtering Is Thinking

The WHERE clause looks technical, but philosophically it is about something larger: attention. It is the mechanism by which a query says, “Only these rows matter for this question.” That sounds obvious, but it is actually a discipline many systems lack.

A table may contain thousands or millions of rows, yet most questions are narrow. Which books were published after 2010? Which customers live in a particular city? Which errors occurred after midnight? Without a filter, you are not querying. You are wandering.

The deeper lesson is that filtering is not merely reduction. It is definition. A question becomes precise only when you tell the system what to exclude. To ask for “books” is vague. To ask for “books where publication year is greater than 2010” is a question the machine can answer unambiguously. Constraints do not limit thinking. They sharpen it.

This has a direct analogy in object design. A class constructor, often built with __init__(), defines which attributes every instance must have. That is a kind of filter too. It says that some properties are essential and others are not. A Book object may require a title and author, but perhaps not a rating or a review count. The constructor acts like a gatekeeper of relevance, deciding what information is necessary for the object to exist in a valid state.

A useful mental model is to think of WHERE as a query-time constructor and __init__() as a create-time filter. One determines what belongs in the result. The other determines what belongs in the object. Both are acts of boundary setting.

A good system does not ask every question of every piece of data. It asks the smallest question that still deserves an answer.

That principle is especially valuable because it resists a common failure mode: overexposure. If you select everything, you carry around noise. If you build objects with too many unnecessary attributes, you create confusion and maintenance costs. Structure becomes bloated when relevance is not enforced.


Shared vs. Specific: The Deep Logic of Classes and DISTINCT

The most elegant connection between these domains is the relationship between what is common and what is unique. In SQL, DISTINCT removes duplicates and returns only unique rows. In OOP, class attributes represent properties shared by all instances, while instance attributes represent properties that vary from one instance to another.

That is not just a coincidence. It is the same architectural instinct in two different forms.

Imagine a library catalog. If every copy of every book stored the same genre, publisher format, and policy metadata separately, the system would be cluttered and fragile. Instead, some facts can be standardized. Others must remain specific to each copy, such as shelf location or checkout status. A smart system separates stable identity from variable state.

DISTINCT is an operation of compression through identity. It says, “These values may appear many times, but only the category matters here.” A class attribute works similarly. It says, “This property belongs to the type, not the instance.” In both cases, you are extracting the invariant from the repeated.

This matters because much of poor design comes from confusing repetition with meaning. Just because a value appears in many rows does not mean it should live redundantly in every row forever. Just because a property is common to many objects does not mean it should be duplicated as instance data. Repetition is sometimes a symptom of a missing abstraction.

But there is a caution here. DISTINCT is useful only when uniqueness is the right lens. If you use it carelessly, you can erase important differences. Similarly, class attributes are powerful only when the shared value is truly shared. If one instance needs a different value, forcing everything into the class layer creates hidden coupling.

The real skill is not simplification for its own sake. It is knowing where sameness stops and variation begins.


Inheritance Is Not Just Reuse, It Is Controlled Variation

Inheritance often gets described as code reuse, but that undersells what is really happening. Inheritance is a design method for saying, “This thing is mostly like that thing, but not exactly.” It gives you a structured way to preserve shared behavior while allowing meaningful difference.

That idea mirrors how good data queries work. You start with a broad dataset, then narrow it using filters and ordering. You might retrieve all books, then all books in one genre, then all books in that genre sorted by publication year descending. Each step preserves the underlying structure while refining the view.

In that sense, inheritance and querying both participate in a larger pattern: layering constraints without rebuilding from scratch. A child class inherits methods and attributes from a parent, then overrides or extends them where necessary. A query inherits the table’s entire contents, then applies conditions and order to produce a more useful answer.

This is why good inheritance feels elegant when used well. It avoids duplication without flattening the world into one undifferentiated mass. It says, “We do not need to restate the obvious, but we do need an explicit place for the exceptions.”

Still, inheritance is also where systems become overconfident. If the parent class is too broad, the children become awkward. If the shared abstraction is too weak, every subclass becomes a special case. The same problem appears in data retrieval when a query is too broad or too narrow. A query can be technically correct and still practically useless.

A helpful test is this: does your structure reduce surprise? If a subclass surprises you, the inheritance tree may be wrong. If a query surprises you, the filtering logic may be wrong. In both cases, the system is telling you that the boundary between shared and specific has been drawn poorly.


A Framework for Better Design: Relevance, Identity, and Variation

Once you see the parallel, a practical framework emerges. Any system that handles information has to answer three questions:

  1. What is relevant right now?
  2. What is identity, or shared structure?
  3. What is variation, or instance-specific detail?

SQL gives you tools for the first and third questions through WHERE, ORDER BY, and DISTINCT. OOP gives you tools for the second and third through classes, instance attributes, class attributes, and inheritance. Together, they teach the same design discipline: separate the shape of the world from the state of the world.

Think about a bookstore application. The Book class might define shared features like category or format. Each instance might hold title, author, and publication year. A query might retrieve only fantasy books published after 2020, then sort them descending by year. If you later need to display only unique genres, DISTINCT helps collapse repetition into a cleaner view.

The architecture is coherent because each layer does one job.

  • The class defines what a book is.
  • The instance stores one book’s actual data.
  • The query decides which books matter for the current task.
  • The sort decides what should appear first.
  • The distinct selection reveals categories rather than copies.

When these layers are confused, the system becomes harder to reason about. When they are separated cleanly, the system becomes more maintainable and easier to extend. That is why good design often feels less like invention and more like finding the grain of the problem.

Great structure is not about adding more detail. It is about placing detail at the right level.

This is the common wisdom hidden inside both database querying and object design. Use the table when you need a collection. Use the class when you need a blueprint. Use the instance when you need reality. Use the filter when you need relevance. Use the sort when you need a meaningful sequence. Use DISTINCT when you need the category, not the copy.


Key Takeaways

  • Do not assume order exists by default. If sequence matters, state it explicitly with a sorting rule.
  • Use filters to define questions precisely. A WHERE clause is not just syntax, it is a way of making relevance explicit.
  • Separate shared structure from individual state. Class attributes belong to the type, instance attributes belong to the object.
  • Treat duplication as a design signal. If the same value appears everywhere, ask whether it should become a shared attribute or a distinct category.
  • Use inheritance for controlled variation, not convenience alone. Extend or override only when the shared abstraction genuinely holds.

The Deeper Lesson: Systems Become Clear When They Respect Difference

The temptation in both databases and programming is to make everything uniform. Store everything the same way. Access everything the same way. Design every object to look similar. But the best systems do the opposite. They create clarity by respecting the boundaries between what is common, what is unique, and what is currently relevant.

That is why WHERE, DISTINCT, classes, instance attributes, and inheritance are not just tools. They are expressions of a deeper intellectual habit: the willingness to distinguish instead of blur. The more skillfully you distinguish, the less noise your system carries. The less noise it carries, the easier it becomes to trust.

And perhaps that is the most useful way to think about design in general. Whether you are querying a table or building an object, you are not just moving data around. You are deciding what reality should look like when someone asks a question of it. The best answer is not the biggest answer. It is the one that preserves meaning while eliminating confusion.

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 🐣