Live data from Hacker News

XOR Swap - Stack Overflow for Tech Interview Questions

xorswap.com

41–42 of 42 posts

Re: XOR Swap - Stack Overflow for Tech Interview Questions

#41
post #34

I think "XOR Swap" sums up my opinion on most Tech Interview Questions. The only question I would ever ask about the XOR Swap trick would probably be "Give 3 reasons never to use this" (assuming you are in a language as least as high level as C).

Hm, I thought the reason for not using it is hardware-related (if your CPU is multi-issue, the dependencies between the three assignments kill performance). What are the language-specific reasons?

Reasons not to use XOR swap:

1) It obfuscates (the most obvious thing, but still worth mentioning).

1) It is incorrect if you swap a memory location with itself (which many algorithms, like sorts, can end up doing without meaning to).

2) It is always slower on any modern optimising compiler than using a temporary in Java, C and C++ (a strong claim to make, but I stand by it. That's why I list specific languages where I know about the internals). Modern compilers use "flow" techniques for temporary variables. A swap will usually compile away to the compiler internally relabelling which value is in which register, and therefore no code at all.

Re: XOR Swap - Stack Overflow for Tech Interview Questions

#42

Earlier quoted context omitted.

Side note, but stretching before exercise increases the chance of injury. http://sportsmedicine.about.com/cs/flexibility/a/aa022102a.h...

That article is way too vague to be of any use. There are a handful of small studies that show less-than-optimal results for pre-exercise stretching when we're talking about running. Soccer, basketball, dancing, weight lifting, rock climbing, none of these have anything to do with those results, and you should talk to people who have been doing the activity for years about how to be healthy, not about.com.

I was wrong; there hasn't yet been a causal relationship established between pre-exercise stretching and increased injury (though some studies do suggest such a relationship).

The studies do agree in general, however, that stretching before exercise does NOT reduce the chance of injury.

Some scientific articles this time: http://scholar.google.com/scholar?q=stretching+injuries+stud...

Post reply on HN