Code for a lightning talk on making illegal states unrepresentable in C# and F#.
The code follows Scott Wlashin's excellent Designing with types blog series.
There are tests for each language, but these don't assert that the code is correct, they just show the shape of the data in the console:
Start at the main branch, then follow the branches by number.
This is the starting point. It shows a naive implementation of a contact type and how that's not safe.
publicrecordContact{publicstringFirstName{get;init;}="";publicstringMiddleInitial{get;init;}="";publicstringLastName{get;init;}="";publicstringEmailAddress{get;init;}="";publicboolIsEmailVerified{get;init;}publicstringAddress1{get;init;}="";publicstringAddress2{get;init;}="";publicstringCity{get;init;}="";publicstringState{get;init;}="";publicstringZip{get;init;}="";publicboolIsAddressValid{get;init;}}- Designing with types
- Yaron Minsky from Jane Street (who coined the phrase 'making illegal states unrepresentable')
- Sudhir Mangla's article on Developers Voice which take it further using C#
- Railway oriented programming in F# (follows up from the last section of Sudhir's blog above)
- Vogen
- Kahlid Amuhakmeh's blog about Vogen
- Briain Chavez's wonderful Bogus library which generates the data for us
Scott Wlashin's series is really about domain modelling. The last section of the series presents a more meaningful challenge:
“A contact must have at least one of the following: an email, a postal address, a home phone, or a work phone”_
https://fsharpforfunandprofit.com/posts/designing-with-types-discovering-the-domain/
His book is excellent too!


