3 ms·
I actually think that even as an interview question the real benefit is in using it as a lead-in to the "do you think this is a good idea?" area of questioning.
by pm215 14y ago
I actually think that even as an interview question the real benefit is in using it as a lead-in to the "do you think this is a good idea?" area of questioning. The xor sequence itself is just another "have you seen this trivia question before?" question, which doesn't really reveal any interesting information. Finding out what the candidate thinks about code readability, whether they know what kind of things a compiler or JVM might do, whether their mental model of assembler-level optimisation is still the "all the world is a Z80 and execution time is proportional to instruction count" flavour or if they are aware of caches, pipelines and so on -- these are all useful. You can also take the "ok, plug in some numbers and show me whether your sequence works" tack to find out whether your candidate can work through doing bitwise logical operations on integers, a sort of bit-flipping variant on fizzbuzz.
But "have you seen this before" is so uninteresting that I always tried to make it clear that I really wasn't interested in whether they knew the trick or not, but more in the ensuing discussion.
- praptak 14y agoI have actually passed an interview where a misuse of the swap trick was part of the "what's wrong with this piece of code" question. Maybe this is similar to "have you seen this trivia question before" but reverted: "can you spot this idiotic trick that causes bugs", which I believe is much more valuable.