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.
[ Parent
| on HN ]
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?
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.