I’m updating some code, and I have a void method (validateFile) that tests files and writes failures directly to some log files. I want to add a counter for each file that passes, but I don’t want to lose the logging that’s done in case of failure.
In terms strictly of the validateFile method running successfully, is this:
validateFile(filename);
functionally equivalent to this? (assuming I change the return type to boolean and put return statements in correctly)
if(validateFile(filename)){
passCount++;
}
If it is equivalent, is there a reason (best practices, etc.) that I shouldn’t do this?
Yes, it is equivalent. No, there is no reason I can think of that you should not do this.
Just one possible caveat that comes to mind, take care when mixing this with conditional operators:
In that case,
b()will be called if and only ifa()returnstrue.