4 ms·
Granted the F# approach is somewhat nicer, but I don't think the C# approach with contracts is too bad (no recent experience with .Net - 6yrs ago contracts were
by nowprovision 11y ago
Granted the F# approach is somewhat nicer, but I don't think the C# approach with contracts is too bad (no recent experience with .Net - 6yrs ago contracts were painful to use), but you also could go the immutable route and via a method call easily return a new instance of User and enforce the invariant prior to creating a new instance etc.. It's a minor issue in the end, the bigger issue is that your client/stakeholder knows what they actually want and you actually capture those in-variants exhaustively and correctly (implementation is minor, F#/ocaml/haskell can't save you here)...
- romaniv 11y agoAFAIK, code contracts in .NET still have all the issues they had several years ago. The absolute worst one being that you need to install something for them to actually work. This means different computers will have different code behavior.