The Lurker
JSR 666: post-assignment operator
These handy operators and expressions proposed for JSR-666: Programmability Enhancements are all very well and good, but I think there is an important operator missing. Happily, this crucial enhancement requires no changes to the JVM.
C-derived languages usually support ++i and i++, and --i and i--. Both of the former increment the value of i, and the latter decrement i; but the value of the first of each of those pairs of expressions is the new value of i, while the latter of each pair is the previous value.
I argue that we should have a similar alternative assignment operator. The value of the expression i=3 is three; I propose that the := operator be defined so that i:=3 return the value of i before the assignment takes place. Similarly, the shorthand operations such as i+=3 should be complemented by i+:=3.
The benefits of this should be obvious. Foremost among them would be that the familiar temp = a; a = b; b = temp; "swap a and b" code could be written as the much more desirable a := b := a, thus eliminating the need for an unsightly temporary local variable. (Of course, a = b := a would be equivalent, but I predict that the attractive symmetry of the previous example will find favour.)
Related topics: Java Mindless Link Propagation Mooax
All timestamps are Melbourne time.