logoalt Hacker News

reillyse04/23/20254 repliesview on HN

One thing I do quite frequently which is related to this (and possibly is a pattern in rails) is to use times in place of Booleans.

So is_deleted would contain a timestamp to represent the deleted_at time for example. This means you can store more information for a small marginal cost. It helps that rails will automatically let you use it as a Boolean and will interpret a timestamp as true.


Replies

jfengel04/24/2025

I consider booleans a code smell. It's not a bug, but it's a suggestion that I'm considering something wrong. I will probably want to replace it with something more meaningful in the future. It might be an enum, a subclass, a timestamp, refactoring, or millions of other things, but the Boolean was probably the wrong thing to do even if I don't know it yet.

show 4 replies
noman-land04/24/2025

This is all well and good until you need to represent something that happened on Jan 1 1970 00:00 UTC.

show 2 replies
hadriendavid04/24/2025

« Anytime you store Boolean, a kitten dies » Nobody has ever said that but nobody wants any kitten to die so nobody has ever challenged me anytime I use that statement.

acedTrex04/23/2025

This one little change alone can bring such huge benefits later.