Re:Java: "+=" applied to String operands can provoke side ef...
by gowld on Wednesday June 06, 2018 @01:06PM
(#17248908)
It's a bug for sure, but anyone who cares about correctness ought to be using a style that doesn't allow this tortured contortion:
[ Parent
| on HN ]
Re:Java: "+=" applied to String operands can provoke side ef...
by simias on Wednesday June 06, 2018 @01:19PM
(#17249032)
If I understand correctly "array[i++] += ..." alone is enough to trigger the bug which doesn't seem particularly tortured to me. Actually any "array[side_effect()] +=" would trigger the bug. That's pretty bad IMO.
Re:Java: "+=" applied to String operands can provoke side ef...
by seandougall on Wednesday June 06, 2018 @03:46PM
(#17250444)
Even if the function within the subscript were free if side effects, calling it twice would be a ridiculous performance regression. Iām no compiler developer, but this really seems like a rookie mistake.
Re:Java: "+=" applied to String operands can provoke side ef...
by Dylan16807 on Wednesday June 06, 2018 @01:19PM
(#17249035)
Don't focus too much on the first example.
array[i++] += "a"
is just is broken. So is appending to array[foo()] or foo().field