3 ms·
I definitely like this approach in my own code. I think the main advantage of a different approach such as enums is enforcing the explicitness at the call site
by ColinDabritz 11y ago
I definitely like this approach in my own code. I think the main advantage of a different approach such as enums is enforcing the explicitness at the call site for all users, especially in library functions.
Another thing to consider: In some cases, it may make more sense to split the function into two versions, one for 'true' and one for 'false'. Then you gain the enforced explicitness. The function could call a private method to share code and pass the Boolean. Clearly that isn't ideal for all situations, but it might help in some situations today.
- JadeNB 11y ago> Another thing to consider: In some cases, it may make more sense to split the function into two versions, one for 'true' and one for 'false'. Then you gain the enforced explicitness. The function could call a private method to share code and pass the Boolean. The author describes exactly this approach and implementation, under the heading "Distinct functions".