Is Maybe an Option? How to Model Nothing
- Speakers
Marco Heimeshoff
- Description
Null is used to model a variety of states within an application. Be it to model the absence of a field in a database table, the return value when parsing something unparsable, an unsuccessful API call or to initialize some fields empty because the “ORM expects it that way”. The problem with null is that it is never completely clear to the developer whether something can or should be null at some point of the application and what null means in a specific case. Most statically typed functional programming languages avoid the problem completely by not allowing null at all. They introduce a new data type called Option or Maybe which allows us to lean on the compiler to check whether we forgot to handle the unexpected absence of a value. This leads to a greater trust in our applications and reduces runtime errors tremendously. Options can also be used to help modelling our domain but often they lack clear semantics of why a value is absent in a specific situation. Luckily options are just a small subset of the beautiful concept of sum types. Those sum types allow us to model different states of our application with ease and great expressiveness. Furthermore they allow us to get rid of many errors that are usually modelled with exceptions by taking care of them in our domain model. This talk will give you the ability to get rid of nulls with options and abstract over this concept with the help of sum types to make your code more expressive and your domain model easier to comprehend for your team and for the business.
- About Marco Heimeshoff
Chief of storytellingTwitterLinkedInCompany Website
Marco Heimeshoff is a trainer, speaker and software developer from Germany. He organizes KanDDDinsky, a conference about Domain-driven Design and the art of business software and co-founded the german DDD community in 2013 and VirtualDDD.com in 2019. Between consulting companies around the globe and his day job in building health care software, you'll find him speaking at conferences about DDD, socio-technical systems and first principles. With over a decade of experience, he is helping teams to change and learn in all things from code to culture and to master Domain-Driven Design, agile software development, functional programming and CQRS with event sourcing.