Hacker News new | ask | show | jobs
by andreyvit 946 days ago
Default gender male not how this works in practice. Instead, you define an extra “invalid” value for almost every scalar type, so invalid would be 0, male 1 and female 2. Effectively this makes (almost) every scalar type nullable. It is surprisingly useful, though, and I definitely appreciate this tradeoff most of the time.

(Sometimes your domain type really does have a suitable natural default value, and you just make that the zero value.)

1 comments

Great, now you’ve brought the pain of checking for nil to any consumer of this type too!