Re: Curious compiler warning
On 1/11/2012 6:58 AM, Lew wrote:
"Readability" is such a subjective term. Someone who knows C, C++, C#,
Java or certain other languages might find 'x[i++] = y[j++]" perfectly
readable. Someone not familiar with these programming languages might not.
I am familiar with C and C++. In the case of C, I've led a compiler
implementation project. I fully understand that expression.
It seems less obvious to me than it would written out as three
statements. Just as I like methods with a single clear purpose, I prefer
statements that have a single clear purpose such as "copy an element
from y to x", or "increment i".
If your observation that such expressions has any evidence to back it up
it's a good argument for something. Maybe not for changing the potency
of the auto-inc/decrement operator but for hiring better-trained
programmers, but for something. Assuming the evidence sustains the
If you have a hard time understanding that expression and you call
yourself a Java programmer, there's a disconnect.
Fortunately, I don't care about being a Java programmer, or a C
programmer, or any other qualified sort of programmer. I'm just a
programmer. For my purposes, writing simple, obvious code in whatever
language I happen to be using is far more important than showing off my
understanding of the JLS.
The JLS itself agrees with me on this: "It is recommended that code not
rely crucially on this specification. Code is usually clearer when each
expression contains at most one side effect, as its outermost operation,
and when code does not depend on exactly which exception arises as a
consequence of the left-to-right evaluation of expressions."
x[i] = y[i];
follows that recommendation. Squishing all three side effects into one
statement does not.
I would go against a JLS recommendation about how to use the language
only if I had a strong positive reason to do so. That is especially the
case when it is arguing for simplicity, which I would prefer anyway.