| « Make Sure That You | The Raybinator, Copy & Paste Error, and Yes I Do » |
Consider the tautology: an unnecessary construct that adds no meaning, context, or understanding and may as not exist. In linguistics, it can come in the form of superfluous modifiers such as adequate enough and true fact. In procedural code, it’s simply wrapping code in an “if (true) {…}” block. But in a database table, representing the tautology can be especially tricky.
Fortunately, John’s has solved this problem by inventing a new SQL data type that can be used when a BIT column would allow too much variation in the data. Simply add a BIT column to your table along with a CHECK constraint enforcing that column to be zero.
CREATE TABLE [CustomerOrder] (
[Id] INT IDENTITY(1,1) NOT NULL,
... snip ...
[IsFulfilled] BIT NOT NULL
CONSTRAINT [CK_CustomerOrder_IsFulfilled]
CHECK ( [IsFulfilled] = 0 )
)
Just think of the possibilities! With the tautology type, you can add columns like [DoesThisRowExist] and [IsValidOrInvalid], thereby effectively encoding zero bits of information.
Re: The Tautology Type
2010-05-10 10:16
•
by
Kef Schecter
(unregistered)
|
A tautology. |
|
This isn't a WTF, it's just a standard sanity check. They're just encoding the business rule that customers' orders should never be fulfilled. Now, thanks to that forward-thinking, should a bug in the code ever accidentally fulfil a customer's order, it'll raise an error condition.
That's just robust coding. |
| « Make Sure That You | The Raybinator, Copy & Paste Error, and Yes I Do » |