‘Make invalid states unrepresentable’ considered harmful
One of the most controversial things I believe about good software design is that your code should be more flexible than your domain model. This is in direct opposition to a lot of popular design advice, which is all about binding your code to your domain model as tightly as possible. For instance, a popular principle for good software design is to make invalid states unrepresentable. This usually means doing two things: Enforcing a single source of truth in your database schema. If users and profiles are associated with a user_id on the profiles table, don’t also put a profile_id on the users table, because then you could have a mismatch. Enforcing stricter types. If you use an “published/pending” enum to track comment status instead of a string field, you don’t have to worry…