5 Modeling the possible absence of data

This chapter covers

  • Using Option to represent the possible absence of data
  • Understanding why null is a terrible idea
  • Whether you should use C# 8 nullable reference types

In chapter 4, I introduced you to the idea that types should precisely represent the data they encapsulate in order to write expressive function signatures. One particularly thorny issue is that of representing data that may not be available. For instance, when you register on a website, you typically have to provide your email address, but other details like your age and gender are optional. The website owner may want to process and analyze this data if it’s available.

“Wait a minute,” you’re probably thinking, “don’t we use null for ...

Get Functional Programming in C#, Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.