Useless parentheses are not useless if they make it easier to comprehend code.

Not everyone remembers && vs. || precedence rules as well as */ vs +- precedence.

On 5/13/2013 10:09 AM, Nick Williams wrote:
The PMD inspector says the following if statement contains "Useless 
parentheses."

         if ((isEventTimestamp && isLiteralValue) || (isEventTimestamp && isPattern) || 
(isLiteralValue && isPattern)) {
             LOGGER.error("The pattern, literal, and isEventTimestamp attributes are 
mutually exclusive.");
             return null;
         }

I'm all for removing useless parentheses; unfortunately, I don't see how these 
are useless. The way I see it, if isLiteralValue is false, with parentheses it 
will (correctly) continue to evaluate after the first grouped condition but 
without parentheses it would (incorrectly) short circuit after the first use of 
isLiteralValue.

Am I missing something here? Or is this a PMD bug?

Nick
---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-dev-unsubscr...@logging.apache.org
For additional commands, e-mail: log4j-dev-h...@logging.apache.org




---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-dev-unsubscr...@logging.apache.org
For additional commands, e-mail: log4j-dev-h...@logging.apache.org

Reply via email to