4 ms·
Meh, I'm not so sure. "Why do we validate data? Typically, to make sure that invalid state doesn’t leak into our systems." Surprisingly, no! We validate data
by DanielBMarkham 11y ago
Meh, I'm not so sure.
"Why do we validate data? Typically, to make sure that invalid state doesn’t leak into our systems."
Surprisingly, no! We validate data to put all the business validation logic into one place, regardless of whether that data is being persisted or not. In fact, a good argument can be made that the most important purpose of centralized object validation is to allow storing objects that are out of whack -- and that our code should degrade gracefully on load when the object is invalid -- whether that load occurs from the UI, a feed, or a persistent datastore.
Perfectly fine to argue the other way. In that case, nope, it doesn't make sense.
- solnic 11y agoIt's not feasible to have validations centralized. You don't validate objects, you validate data that your system received from somewhere. How it's done depends on the type of this external system, the format and sometimes the context in which you validate, that is specific to your system. This is one of the reasons why AR validations don't scale so well. Having said that, there are many systems where AR and centralized validation works just fine.
- DanielBMarkham 11y agoI hate these discussions because you're right, but in a limited way. Yes, it is impossible. I should have said something like "locally centralized to the compilation unit" As gandalf pointed out, "IsValid" really asks a bunch of questions at the same time, and talking about it in the abstract is always going to miss the full depth. As a for-instance, there's clean data in terms of my datastore and then there's clean data in terms of whatever app I'm looking at. In a system of any size, these are most likely not the same thing. (And yes, that drives us crazy, but such is the way of large datastores)