News for hackers. Stuff that matters.
Re:Anti-If: The missing patterns (2016) by d--b on Wednesday June 27, 2018 @06:32AM (#17407090)
Pattern 1 is impracticable: most reasons why you would add a Boolean parameter to a function is to avoid code duplication:

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...

Re:Anti-If: The missing patterns (2016) by hitsthings on Wednesday June 27, 2018 @06:40AM (#17407125)
Pattern 1 you can pass in a logger there or a noop logger and not have any duplication.
Re:Anti-If: The missing patterns (2016) by pavel_lishin on Wednesday June 27, 2018 @09:58AM (#17408130)
It's not my job to pass a logger to some given class method. Should I pass in a database handle and a DNS resolver, too?
Re:Anti-If: The missing patterns (2016) by d--b on Wednesday June 27, 2018 @07:07AM (#17407234)
Well, I could do operations for logging that are otherwise not required...

   if(log) { logger.write(computestuff()); }
Re:Anti-If: The missing patterns (2016) by meheleventyone on Wednesday June 27, 2018 @07:24AM (#17407300)
Depending on language if you have first class functions you could also do:

  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.
Re:Anti-If: The missing patterns (2016) by rini17 on Wednesday June 27, 2018 @06:51AM (#17407166)
This means to interrupt whatever you're doing and implement the logger and do the associated refactoring.