L
Lawrence D'Oliveiro
One of the awkwardnesses Java carries over from C/C++ is the precedence of
bitwise operators is lower than that of comparisons. Thus you need the
parentheses in expressions like
(val & mask) != 0
and so on. Presumably this was done for compatibility reasons.
And yet Python manages to flip the priorities around
<http://docs.python.org/py3k/reference/expressions.html> (see sections 5.8
and 5.9) without tripping anybody up. In fact, for a long time, I wrote
expressions in Python with the parentheses as above. Then one day I happened
to make it
val & mask != 0
and actually didn’t notice at first; it was only in looking the code over
later did I realize I’d done this, and the code still worked.
bitwise operators is lower than that of comparisons. Thus you need the
parentheses in expressions like
(val & mask) != 0
and so on. Presumably this was done for compatibility reasons.
And yet Python manages to flip the priorities around
<http://docs.python.org/py3k/reference/expressions.html> (see sections 5.8
and 5.9) without tripping anybody up. In fact, for a long time, I wrote
expressions in Python with the parentheses as above. Then one day I happened
to make it
val & mask != 0
and actually didn’t notice at first; it was only in looking the code over
later did I realize I’d done this, and the code still worked.