|
|
|
|
|
by turboponyy
295 days ago
|
|
I actually completely agree with both the article and your point that your code should directly communicate your intent. The angle I'd approach it from is this: recording whether an email is verified as a boolean is actually misguided - that is, the intent is wrong. The actual things of interest are the email entity and the verification event. If you record both, 'is_verified' is trivial to derive. However, consider if you now must implement the rule that "emails are verified only if a verification took place within the last 6 months." Recording verifications as events handles this trivially, whilst this doesn't work with booleans. Some other examples - what is the rate of verifications per unit of time? How many verification emails do we have to send out? Flipping a boolean when the first of these events occurs without storing the event itself works in special cases, but not in general. Storing a boolean is overly rigid, throws away the underlying information of interest, and overloads the model with unrelated fields (imagine storing say 7 or 8 different kinds of events linked to some model). |
|
Or, your assumption about the intent is wrong. Many (most?) times, the intent is precisely whether an email is verified. That's all. And that's OK if that's all the project needs.
> Storing a boolean is overly rigid, throws away the underlying information of interest, and overloads the model with unrelated fields
Also, storing a boolean can most accurately reflect intent, avoid hoarding unnecessary and unneeded information, and maximize the model's conceptual clarity.