Joined January 2013
·
981494 10151466984546915 1613396205 o

Emmanuel Turlay

Full stack web developer at StreamNation.com
Full stack web developer
StreamNation.com
·
San Francisco
·
·
·

Posted to Using bitmasks to store settings over 1 year ago

@sheerun I have a table dedicated to users settings with dozens of booleans columns and as many rows as users. That freaks me out. I much rather like a single integer field on the users table.
I never need to query on them, I only need to check a given record's settings.

Now to be clear, I never said people should use this technique blindly. Everyone should be sensible to how it fits there requirements. Just like everything else.
Also, I used ruby here to illustrate the point but the post was mostly intended to showcase the technique rather than the language used to apply it.

Posted to Using bitmasks to store settings over 1 year ago

@sheerun Why?

Posted to Using bitmasks to store settings over 1 year ago

@encodes Indeed.
I actually learned this technique while coding for the ATLAS experiment at CERN which contains thousands of electronic chips where both physical and logical space are limited resources.

* sudo rm -rf /*

- don't forget to run

Posted to Using bitmasks to store settings over 1 year ago

Indeed, using bitmasks requires some serious testing.
And you sure can't use it for everything. In my case, I use it for a stupid collection of checkboxes.

Posted to Using bitmasks to store settings over 1 year ago

That's a fair point.
If I'm not mistaken, all flavours of SQL support bitwise operations don't they? Hence one could query with SELECT * FROM users WHERE settings & (1 << 3) > 0.
Isn't that right?

Posted to Custom Rails error pages over 1 year ago

@jeroenr Thank you for that tip, I was looking for that exactly ;)

Achievements
375 Karma
44,667 Total ProTip Views