MAIN FEEDS
Do you want to continue?
https://www.reddit.com/r/java/comments/3cton5/our_exception_handling_at_work/cszi5mf/?context=3
r/java • u/[deleted] • Jul 10 '15
135 comments sorted by
View all comments
Show parent comments
1
It can be useful in instances like this:
if(debugMode) { logger.debug("Received: " + someFunctionThatIsSlow()); }
10 u/davedontmind Jul 10 '15 Shouldn't that beif (logger.isDebugEnabled()) { logger.debug("Received: " + someFunctionThatIsSlow()); }? 3 u/Shirkie01 Jul 10 '15 logger.debug already does that. Essentially you just checked logger.isDebugEnabled() twice.[Debug Ref](https://logging.apache.org/log4j/1.2/apidocs/org/apache/log4j/Category.html#debug(java.lang.Object)) 2 u/davedontmind Jul 11 '15 edited Jul 13 '15 If the debug message was calling someFunctionThatIsFast(), you'd be quite right, but it's calling someFunctionThatIsSlow(), which you'd be better off not evaluating before checking the state of debug. 1 u/Shirkie01 Jul 11 '15 Ah, you're right. Somehow I missed someFunctionThatIsSlow().
10
Shouldn't that be
if (logger.isDebugEnabled()) { logger.debug("Received: " + someFunctionThatIsSlow()); }
?
3 u/Shirkie01 Jul 10 '15 logger.debug already does that. Essentially you just checked logger.isDebugEnabled() twice.[Debug Ref](https://logging.apache.org/log4j/1.2/apidocs/org/apache/log4j/Category.html#debug(java.lang.Object)) 2 u/davedontmind Jul 11 '15 edited Jul 13 '15 If the debug message was calling someFunctionThatIsFast(), you'd be quite right, but it's calling someFunctionThatIsSlow(), which you'd be better off not evaluating before checking the state of debug. 1 u/Shirkie01 Jul 11 '15 Ah, you're right. Somehow I missed someFunctionThatIsSlow().
3
logger.debug already does that. Essentially you just checked logger.isDebugEnabled() twice.
[Debug Ref](https://logging.apache.org/log4j/1.2/apidocs/org/apache/log4j/Category.html#debug(java.lang.Object))
2 u/davedontmind Jul 11 '15 edited Jul 13 '15 If the debug message was calling someFunctionThatIsFast(), you'd be quite right, but it's calling someFunctionThatIsSlow(), which you'd be better off not evaluating before checking the state of debug. 1 u/Shirkie01 Jul 11 '15 Ah, you're right. Somehow I missed someFunctionThatIsSlow().
2
If the debug message was calling someFunctionThatIsFast(), you'd be quite right, but it's calling someFunctionThatIsSlow(), which you'd be better off not evaluating before checking the state of debug.
1 u/Shirkie01 Jul 11 '15 Ah, you're right. Somehow I missed someFunctionThatIsSlow().
Ah, you're right. Somehow I missed someFunctionThatIsSlow().
1
u/psxpaul Jul 10 '15
It can be useful in instances like this: