r/programming • u/jonjonbee • Jun 05 '18
Code golfing challenge leads to discovery of string concatenation bug in JDK 9+ compiler
https://stackoverflow.com/questions/50683786/why-does-arrayin-i-give-different-results-in-java-8-and-java-10
2.2k
Upvotes
View all comments
Show parent comment
1
u/possessed_flea Jun 06 '18
because if I post the code snippet:
public boolean testValues() {
return (a == b) || ( c != a ) || (y == z) || (x == z);
}
you cannot tell me what operations are being executed without having to lookup the types yourself, and you can also guarantee that the following code shuffle will give identical results.
public boolean testValues() {
return (a == b) || ( c != a ) || (z == y) || ( x == z);
}
and you can also look at this code above and guarantee it will not have any side effects, ( im looking at C++ and ada developers at the moment. )
public boolean testValues() {
return ( a.equals(b) || c.doesNotEqual(a) || y.equals(z) || z.equals(x) );
}
Atleast with inheritance you get some huge visual warnings right away that:
public boolean equals(Object o) {
return getValueA() == ((MyObj)o).getValueA();
}
public int getValueA() { if (a == -1) { a = 0; } return a; }
Having the operator overload of "==" be replaced by something user definable all of a sudden leaves this open to abuse and makes it more difficult for anyone to be able to just read code.