CodeSOD: One’s Company
The more you learn about something, the less confident you often become in making statements about it, because you understand the complexities of the matter. If, for example, I asked you to help me refine my definition of how dates and times work, you know that many assumptions are wrong. Or if we tried to define what makes a string a person’s name, we’ll run into similar problems. This is even true for a value we’ve all probably seen implemented as a boolean value: gender. The more you learn about these subjects, the more complex and nuanced your understanding of them becomes. More and more, your answers start with, “It’s complicated…”.
Eugene was going through some code at a customer’s site, and he found that their business logic depended heavily on a flag
ISCOMPANY, but there was no
ISCOMPANY field anywhere in the database. There was, however, a
SEX field on the customer records, implemented as an integer.
Digging through the queries, Eugene found a new approach to defining a company:
SELECT …, CASE ISNULL(c.SEX, '') WHEN '6' THEN '-1' WHEN '9' THEN '-1' ELSE '0' END AS ISCOMAPNY, … FROM customers WHERE …
Like I said, it’s complicated.