▲ | crazygringo 5 days ago | |||||||||||||
No. All of this is breaking the primary rule of programming: KISS (keep it simple, stupid). Don't add unnecessary complexity. Avoid premature optimization. Tons of things are correctly booleans and should stay that way. Turning boolean database values into timestamps is a weird hack that wastes space. Why do you want to record when an email was verified, but not when any other fields that happen to be strings or numbers or blobs were changed? Either implement proper event logging or not, but don't do some weird hack where only booleans get fake-logged but nothing else does. Should booleans turn into enums when a third mutually-exclusive state gets added? Yes, of course, so go refactor, easy. But don't start with an enum before you need it. The same way we don't start with floats rather than ints "just in case" we need fractional values later on. Booleans are a cornerstone of programming and logic. They're great. I don't know where this "booleans are bad" idea came from, but it's the opposite of communicating intention clearly in code. That boolean should probably stay a boolean unless there's an actual reason to change it. | ||||||||||||||
▲ | operator-name 4 days ago | parent | next [-] | |||||||||||||
I strongly disagree. Making invalid state unrepresentable is important. > wastes space > premature optimisation A timestamp is a witness of when the email was verified. Since if they’ve verified can be calculated from it, having both is not only redundant but allow invalid states to be represented. Cases like email verified are often followed by the need to know when. Say an expiry system. Going from bools, you are faced with the hard choice of how to migrate existing state. Databases also warrant more care as a source of persistent state - accessed by multiple versions of your software. If you don’t have this persistency, then it matters less. > any other fields that happen to be strings or numbers or blobs were changed > implement proper event logging Event logging is orthogonal to your database state. If your business logic needs dirty flags or timestamps they should be stored in the database, not queried. And if you do need it for other fields, adding the bool is the perfect time to ask yourself if what you need is a timestamp. > way we don't start with floats rather than ints "just in case" we need fractional values later on Floats are a subset of int, and a natural migration. A bool can be calculated from a timestamp, but not the other way. | ||||||||||||||
| ||||||||||||||
▲ | lock1 5 days ago | parent | prev | next [-] | |||||||||||||
Disagree. Given the current popularity of dynamic languages and the fact that many people don't understand the value of ADT, newtype pattern, C-like enum even in static languages, I'd argue booleans & primitives are way overused. I think a lot of people misunderstand KISS, believing everything should be primitives or surface-level simplicity. Instead, I interpret "simple" not something like golang's surface-level readability, but infosec's "principle of least privilege". Pick the option that minimizes possible state and capture the requirement logic, rather than primitives just because they're "simple" or "familiar". Even then, sometimes it's fine to violate it. In this case, (nullable) date time might be more preferable than boolean for future-proofing purposes. It's trivial to optimize space by mapping date time to boolean, while it's a total pain to migrate from boolean to date time. Also, doesn't "... a weird hack that wastes space" contradict "Avoid premature optimization"? | ||||||||||||||
| ||||||||||||||
▲ | breadwinner 5 days ago | parent | prev | next [-] | |||||||||||||
Disagree. KISS is for bigger things like architecture. Exposing an enum instead of a simple bool is a good idea that will save you time later. The only time to not do this is if you're exposing internal info, i.e., breaking encapsulation. | ||||||||||||||
| ||||||||||||||
▲ | glxxyz 5 days ago | parent | prev | next [-] | |||||||||||||
Yes the advice in TFA was brought to you by the sort of people who never finish anything because they're always wasting time thinking about potential future use cases that will never happen. Make it simple and extensible and make it satisfy today's requirements. | ||||||||||||||
▲ | scuderiaseb 4 days ago | parent | prev [-] | |||||||||||||
Depends, if you're absolutely sure whatever you have has just two states. Then by all means, use a boolean. But booleans are harder to read than enum values and you're skipping that because of saving a few bytes on the DB? This is not premature optimization, sometimes booleans can be extremely hard to change so it's not as easy as "just refactor". |