3 ms·
Well, multiply the ifs and the elses I would consider that doing so makes it a different problem, and so what becomes the better solution changes. If you need
by userbinator 11y ago
Well, multiply the ifs and the elses
I would consider that doing so makes it a different problem, and so what becomes the better solution changes. If you need very many different combinations, you should probably use a table-based approach instead (produce an integer from each of the booleans, index into a table of function pointers or similar; you can often reduce its size if you put "don't cares" into the more significant bits.) I think the second option is more difficult to understand since you now have to consider together all 4 different combinations of a and b to determine what code gets executed for each one. For the first option, it is immediately obvious that none of those functions execute if a is false, whereas in the second you have to inspect each if-condition.