There seem to be a common misconception about the meaning of the term “relational” (in the context of “relational databases”).
There are a few commonly-used phrases:
- “Relational data”
- “Relational database”
- “Relation”
- “Relationship”
One of these things is not like the others.
A classic demonstration of the misunderstanding:
Collectively, multiple tables of data are called relational data because it is the relations, not just the individual datasets, that are important. Relations are always defined between a pair of tables.
https://r4ds.had.co.nz/relational-data.html
The Drizzle ORM also gets this annoyingly wrong, although fortunately they didn’t bake the word relation
into the library’s API.
A relation, properly defined, is closely analogous to a table.
Relational data is just data stored in tables.
If somebody asks you “if your data is relational”, they may be suffering from this misunderstanding.
Filed under:coding
I will be re-reading the following quotes from Sandi Metz’s Practical Object-Oriented Design every morning before I start coding:
Object-oriented design is about managing dependencies. It is a set of coding techniques that arrange dependencies such that objects can tolerate change. In the absence of design, unmanaged dependencies wreak havoc because objects know too much about one another. Changing one object forces change upon its collaborators, which in turn forces change upon its collaborators, ad infinitum. A seemingly insignificant enhancement can cause damage that radiates outward in overlapping concentric circles, ultimately leaving no code untouched.
This makes sense of why dependency injection containers exist, the principle of inversion of control, and how to split up classes into the right responsibilities.
Asserting that code should be easy to change is akin to stating that children should be polite; the statement is impossible to disagree with, yet it in no way helps a parent raise an agreeable child. The idea of easy is too broad; you need concrete definitions of easiness and specific criteria by which to judge code. If you define easy to change as
- changes have no unexpected side effects,
- small changes in requirements require correspondingly small changes in code,
- existing code is easy to reuse, and
- the easiest way to make a change is to add code that in itself is easy to change,
then the code you write should have the following qualities. Code should be
- Transparent
The consequences of change should be obvious in the code that is changing and in distant code that relies upon it.
- Reasonable
The cost of any change should be proportional to the benefits the change achieves.
- Usable
Existing code should be usable in new and unexpected contexts.
- Exemplary
The code itself should encourage those who change it to perpetuate these qualities.
Code that is Transparent, Reasonable, Usable, and Exemplary (TRUE) not only meets today’s needs but can also be changed to meet the needs of the future. The first step in creating code that is TRUE is to ensure that each class has a single, well-defined responsibility.
Optimising for unknown future requirements seems like a great way to go about writing code that’s usable today as well.
Filed under:coding