On 25 Jun 2017, at 20:57, kant kodali <kanth...@gmail.com<mailto:kanth...@gmail.com>> wrote:
impressive! I need to learn more about scala. What I mean stripping away conditional check in Java is this. static final boolean isLogInfoEnabled = false; public void logMessage(String message) { if(isLogInfoEnabled) { log.info<http://log.info/>(message) } } If you look at the byte code the dead if check will be removed. Generally it's skipped in Java too now people move to SLF4J APIs, which does on-demand string expansion LOG.info<http://LOG.info>("network IO failure from {} source to {}", src, dest, ex). That only builds the final string callis src.toString() and dest.toString() when needed; handling null values too. So you can skip those guards everywhere. But the string template is still constructed; it's not free, and there's some merit in maintaining the guard @ debug level, though I don't personally bother. The spark one takes a closure, so it can do much more. However, you shouldn't do anything with side effects, or indeed, anything prone to throwing exceptions. Always try to write .toString() methods which are robust against null values, that is: valid for the entire life of an instance. Your debuggers will appreciate it too.