← Back to context

Comment by jen20

6 years ago

I’d recommend Scott Wlaschin’s excellent book “Domain Modelling made Functional”. The examples are in F# but the concepts apply much more broadly.

Came here to post this. I second this book heartily. If you design your types to be DD with raw, valid, invalid data then by the time you actually get to the database or API, you are sure that your code has passed through however many compile-time enforced validity checks (if you use F# or similar static strong type PL) before it got to this point.

That way, you don't need nearly as much defensive coding re: null checks etc. because the data has gone from 'some client typed some value in an input box, hope its valid' to 'this is an Address line that has been confirmed to be valid structure to pass to downstream systems'.

Pit of success is so much better than peak of success, and much easier to get in a static typed functional language vs. an OO language in my experience.

+1 for that book. It totally changed how I thought about types and their role in programming.

Agreed. This is a great book. It's changed the way I use statically-typed functional languages.

This article is very much in the same vein.

The best thing is that he writes F# in a way that is perfectly understandable by the domain experts so he can use the code as the ubiquitous language. In this way an intermediate representation to communicate with the users is not needed and there is nothing that needs to be kept in sync with the code.