DEV Community

Discussion on: An Algorithm to Swap Two Variables Synchronously, Without Creating a Temporary Variable

Collapse
 
moopet profile image
Ben Sinclair

I can't imagine this being useful even at an enormous scale unless you're talking about processing millions of threads, and if you're doing that, you presumably have a spare megabyte or two of RAM to cope with it.

All it really does is obfuscate the code a little. It's an interesting puzzle for people who are learning about algorithms but it has no role in the real world except for that one programmer your friend met one time.

Collapse
 
ninofiliu profile image
Nino Filiu

Defo. I only had to swap variables in exercises in my old uni, and to answer people on stack overflow. Since then I've been in the industry for years and I never had to do that.

Collapse
 
gdledsan profile image
Edmundo Sanchez

It might be some close to metal thing that needs to happen in metofs we use daily.

I can see the benefit of not needing to reservu, use and clean up some variable, remmber io ooerations are slower than just adding and subtracting.