This is a fantastic insight, and it's precisely the kind of philosophical wrestling that leads to deeper understanding and better software design! Your struggle with "basething" vs. "the thing" directly maps onto the philosophical nuances we discussed.
Let's break down your current mental model and explore some philosophical angles that might help you find more satisfying ways to name your Go structs and interfaces.
Your Current State: Interfaces as "The Thing"
You've moved from:
struct = "the thing" (the concrete entity, its structure)
interface = "descriptor" (a behavior/property of the thing)
To:
interface = "the thing" (the abstract identity, its behavior/role)
struct = "basething" (a concrete implementation, its structure)
This shift is actually very common and often considered idiomatic in Go (and many object-oriented paradigms). When you design with interfaces, you are prioritizing behavior and capability over concrete structure. The interface defines "what can be done" or "what role can be played," which, in a dynamic system, is often more fundamental to its identity than its internal composition.
Think of it this way: what makes a Reader a Reader is not what it's made of, but that it can Read(). Its identity is defined by its function, its behavior.
Philosophical Angles for Modeling in Code
Here are some angles that might help you solidify your thinking and refine your naming:
1. The Functionalist Perspective (Philosophy of Mind/Computation)
- Core Idea: In philosophy of mind, functionalism suggests that what makes something a "mind" (or any cognitive state) is not its physical makeup (e.g., neurons) but its function or role within a system (e.g., processing information, feeling pain). A mind could, in theory, be instantiated in a brain, a computer, or even alien goo, as long as it performs the same functional role.
- Applying to Go:
- An
interface defines the functional role or purpose of "the thing." It describes what it does or is for. This is its identity from a functional perspective.
- A
struct is a specific physical realization or material substrate that performs that function. It's the "implementation detail" of how the function is carried out.
- Naming Implications:
- Interface (The Functional Thing): Name it after its purpose or role. This is where "the thing" truly lives.
- e.g.,
Authenticator, Cache, Logger, Processor, Store, Validator, Service.
- Struct (The Implementation/Substrate): Name it to reflect how it fulfills that functional role, or what specific technology/context it uses. Avoid generic "base" names.
- e.g.,
DatabaseStore, FileLogger, RedisCache, OAuthAuthenticator, StripeProcessor, RegexValidator, UserService.
- This way,
RedisCache is a kind of Cache. It is a Cache functionally, but its specific implementation is RedisCache.
2. Process Philosophy (Heraclitus, Whitehead)
- Core Idea: As we discussed, reality is fundamentally about change, events, and processes, not static substances. A "thing" is defined by its ongoing activities and interactions.
- Applying to Go:
- The
interface captures the dynamic aspect of a "thing"—its behavior and interaction patterns. It's the "flow" that defines its identity in a system.
- The
struct is a particular "snapshot" or "instance" that allows for that flow. It's the momentary configuration that enables the process.
- Naming Implications: This perspective strongly reinforces naming interfaces based on action or continuous state.
Reader, Writer, Closer (Go standard library examples are great here)
StreamProcessor, EventSource, StateMachine
- Structs then become the specific mechanisms for enacting these processes:
FileStreamProcessor, KafkaEventSource, OrderStateMachine.
3. Aristotelian Hylomorphism (Revisited and Reinterpreted)
- Core Idea: Aristotle's idea of "form" and "matter" can be stretched.
- Form: Not just physical shape, but also the essence, purpose, and potential of a thing.
- Matter: The actual stuff out of which it's made.
- Applying to Go:
- The
interface can be seen as the Form—it defines the essence and potential of what "the thing" is from a system's perspective. It's the blueprint of its capabilities.
- The
struct is the Matter—the concrete instantiation, the specific materials and internal organization that realize that Form.
- Naming Implications:
- Interface (The Form/Essence): Name it for its essential role or identity within the system. This often takes a noun form.
- e.g.,
User, Product, Order, Payment. (Yes, interfaces can also represent conceptual entities, not just actions!)
- Struct (The Matter/Realization): Name it to indicate how this essential form is realized, or its specific type of materialization.
- e.g.,
SQLUser, InMemoryProduct, JSONOrder, StripePayment.
- If the interface defines an action, then the struct is still
SpecificActioner.
- Example:
interface UserGetter { GetUser(id string) (*User, error) } (Form: The ability to get a user)
struct DBUserGetter { db *sql.DB } (Matter: How the user is actually retrieved)
4. The "Contract" or "Agreement" Perspective
- Core Idea: In social philosophy and legal theory, a contract defines a set of agreed-upon behaviors, responsibilities, and expectations between parties. It's an abstract agreement that precedes any specific instance of its fulfillment.
- Applying to Go:
- An
interface is a contract for how a piece of code will behave. It defines the public API, the promises it makes.
- A
struct is the party fulfilling the contract. It's the concrete implementation that adheres to the agreement.
- Naming Implications:
- Interface (The Contract): Name it for the agreement itself, or the role it represents.
- e.g.,
http.Handler, io.Reader, DatabaseClient, MessageQueueConsumer.
- Struct (The Fulfiller): Name it for the specific entity that implements the contract.
- e.g.,
UserHandler, FileClient, KafkaConsumer.
Bringing it Together: Embracing the "Interface as The Thing"
Your shift to thinking of interfaces as "the thing" is a strong move in Go. It enables:
- Polymorphism: Functions can operate on
the thing (interface) without caring about its concrete basething implementation.
- Loose Coupling: Components depend on
the thing (interface), not a specific basething, making systems more flexible and testable.
- Testability: You can easily substitute
MockTheThing for RealTheThing during testing.
The key is to refine your struct naming to be more descriptive than "basething." Instead of "basething," think about what kind of implementation it is.
So, if your interface is TheThing:
TheThing (Interface): type TheThing interface { DoSomething() }
- Concrete
TheThing (Struct): type SpecificTheThing struct {} or type DefaultTheThing struct {} or type ExternalServiceTheThing struct {}
This way, your struct names still describe what they are, but at the level of their concrete implementation, while the interface name describes the abstract essence or role of "the thing" within your system.
Your philosophical journey into programming is a powerful one. Keep leaning into these connections—they often lead to the most elegant and maintainable code designs!