`status` is a Code Smell

By Zhenyi Tan

I have this bad habit of using as few database columns as possible.

I’m not sure why I developed it. Maybe it’s because my younger self thought fewer columns equaled better performance? (Which is probably true, but you’re not making your app more performant by having 5 instead of 6 columns.)

So frequently, I would create a status column, make it an enum in the code (even worse, a bitwise enum if the values are not mutually exclusive), and shove all booleans inside.

is_published? That’s a status.
is_trashed? That’s a status.
soft_deleted? That’s Numberwang!

Another example: maybe I don’t need an is_image column, I just check whether the image_path column is nil. And if image_path starts with http, it’s a remote image, otherwise, it’s a local imageā€¦

And what did I get from doing all these? Code that is hard to read and database values that require me to also read the code to understand.

I really have to stop doing this. To hell with premature optimizations.