by d--b · 8y ago · 0 comments
void blah(int x, bool logInfo) {
...
if (logInfo) ...
...
}Pattern 2 can be horrible when applied to the wrong problem. As in: you can use polymorphism to implement fact(int x) without if statements, but it’s not going to be pretty...
Pattern 3 is not a pattern, it just says “if the if is useless remove it”...
Pattern 4 is particularly confusing, especially when you start to have nots in there:
var x = !(a || !b) // ugh
Pattern 5: doesn’t remove the if...
if(log) { logger.write(computestuff()); } logger.write(computestuff);
Or for parameterized functions: logger.write(() => computestuff(a, b, c));
Then all that logging policy stuff can live with the logging and doesn't need to be checked explicitly throughout the codebase.