▲ | cma 9 days ago | |||||||
Often you can check validity one time before everything else. 5 bools might only actually be valid in 7 possible combinations instead of 32. Convert in one place to a 7 element enum and handle with exhaustive switch statements everywhere else can sometimes be a lot cleaner. Making invalid data unrepresentable simplifies so much code. It's not always possible but it is way underused. You can do some of it with object encapsulation too, but simple enums with exhaustive switch statements enforced by the compiler (so if it changes you have to go handle the new case everywhere) is often the better option. | ||||||||
▲ | ajuc 9 days ago | parent [-] | |||||||
> Making invalid data unrepresentable simplifies so much code That's the dream. Error handling is what crushes it :) | ||||||||
|