4 ms·
And now you've baked your understanding of reality into your type system or your invariant contracts, you come to write some code that actually works with this
by jameshart 11y ago
And now you've baked your understanding of reality into your type system or your invariant contracts, you come to write some code that actually works with this API and realize you've made a terrible mistake, because when you delete a user, you need to know which subscriptions to cancel, but you've already thrown that information away as soon as you called 'Delete()'. Maybe we should restrict you from deleting a user while they have active subscriptions? Well, that's easily accomplished with a C# invariant, a little harder to bake into the F# Type union.
In general, though, it turns out you often need to be able to have objects in an 'illegal' state some of the time. "Zip code is a mandatory field" - but that doesn't mean you can't save your order form for later if you need to go and look up the zip code. It's generally best to validate objects as being 'eligible' for a particular operation, not to prevent them from being ineligible altogether - An object with no zipcode can be saved, but it can't be submitted. Structuring that sort of thing into a type system - while doable - is probably not idiomatic in either F# or C#.
- ionforce 11y agoIf you're experiencing some sort of mismatch with your model, it means that your model is incorrect.
- jameshart 11y agoBut if your model is churning every time your understanding of the business rules changes, then you have a different problem.
- noblethrasher 11y agoYour model will usually be incorrect because in all but the most trivial applications the model will be the result of experimentation. Even if you “accurately”[1] model the business rules, those rules themselves are subject to change as the business revives it’s model of the market, or customer relationship, or regulatory environment, or whatever. The main selling point of extreme late-binding (e.g. ad-hoc polymorphism, dependency injections, message passing, etc) is that lets you quickly revise your model. [1] Whatever that means.
- deleted 11y ago[deleted]