Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

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.)



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




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: