Re:Applying “make invalid states unrepresentable”
by srtjstjsj on Monday October 05, 2020 @01:16PM
(#24689738)
"required" is an example of making an invalid state representable and having it ruin your program.
[ Parent
| on HN ]
Re:Applying “make invalid states unrepresentable”
by dodobirdlord on Monday October 05, 2020 @02:50PM
(#24690721)
Yea, a better example of making invalid state unrepresentable in Google’s protocol buffers is to use the “oneof” feature to mark that a set of fields are mutually exclusive. If A, B, and C are mutually exclusive you can put them in a oneof, which also saves space in the binary representation. If in future you discover that A and B but not C needs to be a valid state, you can add a 4th AB option inside of the oneof.