Are you running out of space in your database? It just seemed like a way to needlessly complicate your database, make it difficult to query (what was email_enabled again? the third bit?), difficult for other developers to use (now it needs a comment to understand) and difficult to constrain for data integrity.
I think that unless you're having space issues, you're better off using boolean columns.
Re:Binary in JavaScript
by whalesalad on Wednesday July 29, 2015 @10:40AM
(#9968917)
This was somewhat of a contrived example.
A solution that seems good right up until a bug starts flipping the wrong bit or someone decides that a flag needs 3 states instead of two.
Bitmasking is a useful technique in some places, but storing user preferences isn't one of them. It's 'cleverness' for the sake of being clever - the code is harder to read, new developers can't immediately understand it, experienced developers have to look up what flags mean, you can't just dump the database row to see what a user's preference are, and if your documentation ever gets out of sync you're screwed.
For the sake of saving DB space it's a really bad idea.
Clever databases can do this themselves.
Re:Binary in JavaScript
by BinaryIdiot on Wednesday July 29, 2015 @03:50AM
(#9966921)
Gah, booleans use so little space do you really need that added complexity?
These can be queried using bitwise operations and you can abstract all of it with synthetic instance properties.
User.email_enabled = true would translate to 0010 or something in, for example, a properties column.
Really handy stuff!!!