The order of evaluation in a complex expression is important. The basic rules:
You should use parentheses in particularly complex expressions, since the precedence rules can be difficult to remember. In fact, some of them are counterintuitive. Parenthesizing is worth the effort to ensure that there is no misunderstanding about how an expression will be evaluated. Just don't go overboard with the parenthesesmost developers should be familiar with the basic precedence rules.
Here are a few examples of how precedence affects the result of an expression: assertEquals(7, 3 * 4 - 5); // left to right assertEquals(-11, 4 - 5 * 3); // multiplication before subtraction assertEquals(-3, 3 * (4 - 5)); // parentheses evaluate first When in doubt, write a test! |