Re:Is your programming language unreasonable? (2015)
by learc83 on Saturday October 10, 2020 @08:15AM
(#24738417)
> Admittedly, this prevents you from accessing name until you provide an address, but I don't think there are many valid use cases where you want to access data before the Customer value is corrrectly initialized. I'd consider this a code smell to be refactored.
If you really needed to do that you could just define a partial customer with no address field and pass are that around.
ie, The argument is that (in pseudocode):
is not really a customer if address is a necessary piece of information, so we should distinguish at the type level by passing around a function that takes the address and returns the correctly initialized Customer like so Admittedly, this prevents you from accessing name until you provide an address, but I don't think there are many valid use cases where you want to access data before the Customer value is corrrectly initialized. I'd consider this a code smell to be refactored.