King Harold wrote:because it is optimized the same as a 'conventional swap', there's nothing wrong with the xor trick other then being "obfuscated" meaning that newbies have no clue what's going on.
That's most likely because the compiler writers are also aware of this trick and hardcoded it to be equivalent to the simple way of doing the same. But they obviously can't prepare for every case of 'cleverness' like that. Again, three XORs are not hard to read per se, but if you don't know the trick, it takes much more thinking time to realise what they do in the end. And when you look at an implementation of an algorithm you don't know, it's better be as clear as possible.
By the way, the quirkiness of the XOR trick is nicely illustrated by the following snippet:
Code: Select all
int a = 1, b = 2;
a ^= b ^= a ^= b;
What will be the value of a and b after execution if the language is C and what happens if it's Java and why?
King Harold wrote:sure but I never said that high-level optimization was bad, but imo low-lvl optimization (by hand) shouldn't be skipped altogether.
But don't you agree that optimisation is only necessary if performance is actually a problem? And that low-level optimisation should come as a last resort, after doing everything else to cure the problem?
King Harold wrote:they value development time more than performance.. Strange though, if you are paid per hour you'd better take as many hours as possible, no? withing certain limits ofcourse..
You're most likely bitten by deadlines (often set by brainless marketing drones) even if you do your work properly. You don't gain anything by sabotaging your own work...