4 ms·
Yet another article prematurely optimizing. It’s like these people have nothing better to do. I’ll wait for my code to get into stupid edge cases first and then
by iwontberude 2y ago
Yet another article prematurely optimizing. It’s like these people have nothing better to do. I’ll wait for my code to get into stupid edge cases first and then fix it. Even if you spend your time avoiding booleans you will still find yourself with some new contradictory state and have to fix it differently anyways.
- amluto 2y agoHuh? This isn’t premature optimization unless you consider trying to write correct code “optimizing”.
- lmm 2y agoComing up with proper representation for your state is almost always worth it. If anything it's the opposite of premature optimisation - normalise first, only denormalise after you've proven that it's needed.
- liontwist 2y agoThe issue isn’t booleans the issue is that the code doesn’t handle all the states described by the two booleans, when all are possible.
- cma 2y agoMake the impossible states unrepresentable using an enum of only the possible boolean combinations.
- dpig_ 2y agoIsn't that exactly what the article prescribes?
- liontwist 2y agoDid you read the context?
- cma 2y agoNo I read wrong and missed it. If all four states are actually possible an enum can still be a win if you have a compiler that can check for exhaustive switch case statements. Or especially if updating a system where it used to be only three were valid and now something changed so that all four are.