3 ms·
True, the world could do with less code that looks like Fizz Buzz Enterprise Edition :) In this case, though, the OP makes a strong point that constructs like
by romwell 8y ago
True, the world could do with less code that looks like Fizz Buzz Enterprise Edition :)
In this case, though, the OP makes a strong point that constructs like data[index++] = value; aren't idiomatic to Java - even the spec advises against this.
And in any case, side effects in assignments can be a tricky thing to understand. Sometimes they are necessary, as in
status = perform_computation_on_data(some_mutable_data);
But in the example discussed is not in this vein. I'd say it's not pretty for the same reason as cramming two statements on one line:
data[i]=value; i++;
is not pretty: it's trying to do two things with one line, which kind of defeats the point of breaking up code into lines.
So I don't disagree with you - but there's a happy medium between Fizz Buzz Enterprise and Code Golf - style code :)