In example #6, he gives this as the unreasonable approach:
var repo = new CustomerRepository();
var customer = repo.GetById(42);
Console.WriteLine(customer.Id);
with the issue being customer can be null, which is not being accounted for. The reasonable approach he says is to use a sum type:
var repo = new CustomerRepository();
var customerOrError = repo.GetById(42);
if (customerOrError.IsCustomer)
Console.WriteLine(customerOrError.Customer.Id);
if (customerOrError.IsError)
Console.WriteLine(customerOrError.ErrorMessage);
Do most (or any) languages in which people take this approach actually enforce handling of all cases? Or could a programmer write that this way:
var repo = new CustomerRepository();
var customerOrError = repo.GetById(42);
Console.WriteLine(customerOrError.Customer.Id);
and still have the same problem as the original?
It seems to me that the "reasonable" version is getting its reasonableness from naming the variable that gets the GetById return "customerOrError" which reminds the reader that there is an error case, not from the language having sum types. That's just a convention. Nothing stops you from naming it "customer" just like in the "unreasonable" language.
(I'd actually expect that from a lot of people, because you are probably going to have a lot more code in the case that you have gotten the Customer variant than in the Error variant case, and you probably don't want to be calling it customerOrError in the 99% of the code where you know that it is a Customer).