<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: One-line variables swap in PHP, Ruby, Perl, Python and C</title>
	<atom:link href="http://nexus.zteo.com/blog/2009/04/24/one-line-variables-swap-in-php-ruby-perl-python-and-c/feed/" rel="self" type="application/rss+xml" />
	<link>http://nexus.zteo.com/blog/2009/04/24/one-line-variables-swap-in-php-ruby-perl-python-and-c/</link>
	<description>Where Schtuff Happens</description>
	<lastBuildDate>Tue, 03 Aug 2010 21:29:19 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
	<item>
		<title>By: admin</title>
		<link>http://nexus.zteo.com/blog/2009/04/24/one-line-variables-swap-in-php-ruby-perl-python-and-c/comment-page-1/#comment-30619</link>
		<dc:creator>admin</dc:creator>
		<pubDate>Tue, 12 May 2009 09:08:19 +0000</pubDate>
		<guid isPermaLink="false">http://nexus.zteo.com/?p=2522#comment-30619</guid>
		<description>&lt;a href=&#039;#comment-30616&#039; rel=&quot;nofollow&quot;&gt;@Mike M&lt;/a&gt; - 

Fun alternative. A tad dangerous, though, not because of your use of commas but because your code could suffer from integer overflows.

&lt;a href=&#039;#comment-30617&#039; rel=&quot;nofollow&quot;&gt;@manveru&lt;/a&gt; - 

Right. What was I thinking? I guess I could use an anonymous function to create a new scope but then the swapped result would only live in that other scope, right? (You may have guessed that my knowledge of Erlang is very superficial so far)

&lt;a href=&#039;#comment-30618&#039; rel=&quot;nofollow&quot;&gt;@anonymous&lt;/a&gt; - 

&quot;But that&#039;s cheating!&quot; he whined ;)</description>
		<content:encoded><![CDATA[<p><a href='#comment-30616' rel="nofollow">@Mike M</a> &#8211; </p>
<p>Fun alternative. A tad dangerous, though, not because of your use of commas but because your code could suffer from integer overflows.</p>
<p><a href='#comment-30617' rel="nofollow">@manveru</a> &#8211; </p>
<p>Right. What was I thinking? I guess I could use an anonymous function to create a new scope but then the swapped result would only live in that other scope, right? (You may have guessed that my knowledge of Erlang is very superficial so far)</p>
<p><a href='#comment-30618' rel="nofollow">@anonymous</a> &#8211; </p>
<p>&#8220;But that&#8217;s cheating!&#8221; he whined <img src='http://nexus.zteo.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
	<item>
		<title>By: anonymous</title>
		<link>http://nexus.zteo.com/blog/2009/04/24/one-line-variables-swap-in-php-ruby-perl-python-and-c/comment-page-1/#comment-30618</link>
		<dc:creator>anonymous</dc:creator>
		<pubDate>Tue, 12 May 2009 07:57:14 +0000</pubDate>
		<guid isPermaLink="false">http://nexus.zteo.com/?p=2522#comment-30618</guid>
		<description>template 
void inline swap(T &amp;a, T &amp;b) { T &amp;tmp = a; a = b; b = tmp; }</description>
		<content:encoded><![CDATA[<p>template<br />
void inline swap(T &amp;a, T &amp;b) { T &amp;tmp = a; a = b; b = tmp; }</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: manveru</title>
		<link>http://nexus.zteo.com/blog/2009/04/24/one-line-variables-swap-in-php-ruby-perl-python-and-c/comment-page-1/#comment-30617</link>
		<dc:creator>manveru</dc:creator>
		<pubDate>Tue, 12 May 2009 06:41:06 +0000</pubDate>
		<guid isPermaLink="false">http://nexus.zteo.com/?p=2522#comment-30617</guid>
		<description>Regarding Erlang, there is no way to do this I know of, as you can bind one variable name only once.</description>
		<content:encoded><![CDATA[<p>Regarding Erlang, there is no way to do this I know of, as you can bind one variable name only once.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Mike M</title>
		<link>http://nexus.zteo.com/blog/2009/04/24/one-line-variables-swap-in-php-ruby-perl-python-and-c/comment-page-1/#comment-30616</link>
		<dc:creator>Mike M</dc:creator>
		<pubDate>Mon, 11 May 2009 21:15:11 +0000</pubDate>
		<guid isPermaLink="false">http://nexus.zteo.com/?p=2522#comment-30616</guid>
		<description>How about using the (little-known) comma operator in your C/C++ examples:

int a = 1;
int b = 27;

a = b - a, b = b - a, a = a + b;</description>
		<content:encoded><![CDATA[<p>How about using the (little-known) comma operator in your C/C++ examples:</p>
<p>int a = 1;<br />
int b = 27;</p>
<p>a = b &#8211; a, b = b &#8211; a, a = a + b;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: admin</title>
		<link>http://nexus.zteo.com/blog/2009/04/24/one-line-variables-swap-in-php-ruby-perl-python-and-c/comment-page-1/#comment-30614</link>
		<dc:creator>admin</dc:creator>
		<pubDate>Mon, 11 May 2009 08:43:03 +0000</pubDate>
		<guid isPermaLink="false">http://nexus.zteo.com/?p=2522#comment-30614</guid>
		<description>&lt;a href=&#039;#comment-30613&#039; rel=&quot;nofollow&quot;&gt;@admin&lt;/a&gt; - 

Hmf I realized, after re-reading your test harness, that the amount of parsing should be the same. Shame on me.</description>
		<content:encoded><![CDATA[<p><a href='#comment-30613' rel="nofollow">@admin</a> &#8211; </p>
<p>Hmf I realized, after re-reading your test harness, that the amount of parsing should be the same. Shame on me.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: admin</title>
		<link>http://nexus.zteo.com/blog/2009/04/24/one-line-variables-swap-in-php-ruby-perl-python-and-c/comment-page-1/#comment-30613</link>
		<dc:creator>admin</dc:creator>
		<pubDate>Mon, 11 May 2009 08:41:58 +0000</pubDate>
		<guid isPermaLink="false">http://nexus.zteo.com/?p=2522#comment-30613</guid>
		<description>&lt;a href=&#039;#comment-30610&#039; rel=&quot;nofollow&quot;&gt;@EllisGL&lt;/a&gt; - 

Ha! I do not think that I would have bothered writing a test harness for PHP&#039;s assignment. And, apparently, I would have been wrong: your results are surprising since they show that parsing more code will, in the end, be as fast as calling a built-in function.</description>
		<content:encoded><![CDATA[<p><a href='#comment-30610' rel="nofollow">@EllisGL</a> &#8211; </p>
<p>Ha! I do not think that I would have bothered writing a test harness for PHP&#8217;s assignment. And, apparently, I would have been wrong: your results are surprising since they show that parsing more code will, in the end, be as fast as calling a built-in function.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: EllisGL</title>
		<link>http://nexus.zteo.com/blog/2009/04/24/one-line-variables-swap-in-php-ruby-perl-python-and-c/comment-page-1/#comment-30610</link>
		<dc:creator>EllisGL</dc:creator>
		<pubDate>Mon, 11 May 2009 03:56:27 +0000</pubDate>
		<guid isPermaLink="false">http://nexus.zteo.com/?p=2522#comment-30610</guid>
		<description>I did a test with a 100K loop on each and yours is actually faster by .001 to .005 seconds. I did another test where I removed the unset out of mine and my was .040 - .042 seconds faster. Here&#039;s my test code:

&lt;?php
$time_start = microtime(true);
$i          =0;

do
 {
    $a = 1;
    $b = 2;
    list($a, $b) = array($b, $a);
 }while(++$i &lt; 100000);


$time_end   = microtime(true);
$time       = $time_end - $time_start;

echo &#039;Test 1: &#039;,$time,&#039;&#039;;

$time_start = microtime(true);
$i          =0;

do
 {
    $a = 1;
    $b = 2;
    $x = $a;
    $y = $b;
    $a = $y;
    $b = $x;
    unset($x, $y);
 }while(++$i &lt; 100000);


$time_end   = microtime(true);
$time       = $time_end - $time_start;

echo &#039;Test 2: &#039;,$time,&#039;&#039;;

$time_start = microtime(true);
$i          =0;

do
 {
    $a = 1;
    $b = 2;
    $x = $a;
    $y = $b;
    $a = $y;
    $b = $x;
 }while(++$i &lt; 100000);


$time_end   = microtime(true);
$time       = $time_end - $time_start;

echo &#039;Test 3: &#039;,$time,&#039;&#039;;</description>
		<content:encoded><![CDATA[<p>I did a test with a 100K loop on each and yours is actually faster by .001 to .005 seconds. I did another test where I removed the unset out of mine and my was .040 &#8211; .042 seconds faster. Here&#8217;s my test code:</p>
<p>&lt;?php<br />
$time_start = microtime(true);<br />
$i          =0;</p>
<p>do<br />
 {<br />
    $a = 1;<br />
    $b = 2;<br />
    list($a, $b) = array($b, $a);<br />
 }while(++$i &lt; 100000);</p>
<p>$time_end   = microtime(true);<br />
$time       = $time_end &#8211; $time_start;</p>
<p>echo &#8216;Test 1: &#8216;,$time,&#8221;;</p>
<p>$time_start = microtime(true);<br />
$i          =0;</p>
<p>do<br />
 {<br />
    $a = 1;<br />
    $b = 2;<br />
    $x = $a;<br />
    $y = $b;<br />
    $a = $y;<br />
    $b = $x;<br />
    unset($x, $y);<br />
 }while(++$i &lt; 100000);</p>
<p>$time_end   = microtime(true);<br />
$time       = $time_end &#8211; $time_start;</p>
<p>echo &#8216;Test 2: &#8216;,$time,&#8221;;</p>
<p>$time_start = microtime(true);<br />
$i          =0;</p>
<p>do<br />
 {<br />
    $a = 1;<br />
    $b = 2;<br />
    $x = $a;<br />
    $y = $b;<br />
    $a = $y;<br />
    $b = $x;<br />
 }while(++$i &lt; 100000);</p>
<p>$time_end   = microtime(true);<br />
$time       = $time_end &#8211; $time_start;</p>
<p>echo &#8216;Test 3: &#8216;,$time,&#8221;;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: EllisGL</title>
		<link>http://nexus.zteo.com/blog/2009/04/24/one-line-variables-swap-in-php-ruby-perl-python-and-c/comment-page-1/#comment-30609</link>
		<dc:creator>EllisGL</dc:creator>
		<pubDate>Mon, 11 May 2009 03:47:07 +0000</pubDate>
		<guid isPermaLink="false">http://nexus.zteo.com/?p=2522#comment-30609</guid>
		<description>Of course that wouldn&#039;t be a one liner thou.</description>
		<content:encoded><![CDATA[<p>Of course that wouldn&#8217;t be a one liner thou.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: EllisGL</title>
		<link>http://nexus.zteo.com/blog/2009/04/24/one-line-variables-swap-in-php-ruby-perl-python-and-c/comment-page-1/#comment-30607</link>
		<dc:creator>EllisGL</dc:creator>
		<pubDate>Mon, 11 May 2009 02:52:42 +0000</pubDate>
		<guid isPermaLink="false">http://nexus.zteo.com/?p=2522#comment-30607</guid>
		<description>On the PHP one, you could also do:
$a = 1;
$b = 2;
$x = $a
$y = $b
$a = $y
$b = $x

unset($x, $y);
echo &#039;a=&#039;,$a&#039;, b=&#039;,$b,&quot;\n&quot;;


Would be interesting to do a test of speed and memory usage between the two.</description>
		<content:encoded><![CDATA[<p>On the PHP one, you could also do:<br />
$a = 1;<br />
$b = 2;<br />
$x = $a<br />
$y = $b<br />
$a = $y<br />
$b = $x</p>
<p>unset($x, $y);<br />
echo &#8216;a=&#8217;,$a&#8217;, b=&#8217;,$b,&#8221;\n&#8221;;</p>
<p>Would be interesting to do a test of speed and memory usage between the two.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
