in reply to Temporary Variables
The other ways of swapping might work without a hidden temporary, but all of them contribute more to a programmer's cognitive load than does the simple swap.
A developer with moderate Perl skills looks at ($b,$a) = ($a,$b); and thinks "oh, a swap", and moves on. But faced with
the developer has to stop and walk through it. It might look like an XOR swap, but that're still three statements to grok just to make sure. Think of this as a wetware performance hit.$a ^= $b; $b ^= $a; $a ^= $b;
A big part of the development game is containing cognitive load -- yours and others.
|
|---|