<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	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/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Tudor Barbu&#039;s professional blog &#187; funny programming</title>
	<atom:link href="http://blog.motane.lu/tag/funny-programming/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.motane.lu</link>
	<description>Ramblings about software development</description>
	<lastBuildDate>Thu, 02 Feb 2012 17:38:27 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Open Hack EU</title>
		<link>http://blog.motane.lu/2011/05/16/open-hack-eu/</link>
		<comments>http://blog.motane.lu/2011/05/16/open-hack-eu/#comments</comments>
		<pubDate>Mon, 16 May 2011 07:14:55 +0000</pubDate>
		<dc:creator>Tudor</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[development]]></category>
		<category><![CDATA[events]]></category>
		<category><![CDATA[funny programming]]></category>
		<category><![CDATA[hackathon]]></category>
		<category><![CDATA[yahoo]]></category>

		<guid isPermaLink="false">http://blog.motane.lu/?p=1560</guid>
		<description><![CDATA[Some asshole flying a plane in front of my house at 7 in the morning just woke me up, interrupting my well deserved rest after Yahoo&#8217;s 24 hours hackathon. But this post is not about Cessnas spraying chemicals, it&#8217;s about one of the best programer oriented events I ever attended. Thank you Yahoo! for making [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://blog.motane.lu/wp-content/uploads/2011/05/photo-e1305524299267-224x300.jpg" alt="" title="Yahoo&#039;s hackathon" width="224" height="300" class="alignleft size-medium wp-image-1562" />Some asshole flying a plane in front of my house at 7 in the morning just woke me up, interrupting my well deserved rest after Yahoo&#8217;s 24 hours hackathon. But this post is not about Cessnas spraying chemicals, it&#8217;s about one of the best programer oriented events I ever attended. Thank you Yahoo! for making it possible.</p>
<p>I teamed up with my colleague from Vendo <a href="http://twitter.com/#!/adolfoabegg" title="Adolfo Abegg's twitter feed">Adolfo Abegg</a> and <a href="http://twitter.com/#!/abrausewetter" title="Alex Brausewetter's twitter feed">Alex Brausewetter</a>, a former colleague that decided to start his own company called Helpdesk, aimed at delivering the best <a href="http://www.helpdeskhq.com/" title="Free Customer Support and Ticketing System">customer support and ticketing software</a> on the market. Some friendly SEO can&#8217;t hurt, right <img src='http://blog.motane.lu/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' />  ? </p>
<p>The hacking event was great, a lot of cool hacks, both software and hardware. <a href="http://pipes.yahoo.com" title="Yahoo! Pipes">Yahoo&#8217;s Pipes</a> service was hacked by members of the <a href="http://rstcenter.com/" title="Romanian Security Team">Romanian Security Team</a> on the stage, while Yahoo&#8217;s CTO was watching &#8211; awkward. It seems that they got pulled into a &#8220;private chat&#8221; by Yahoo!&#8217;s officials shortly after. Read the whole story <a href="http://pastebin.com/7beywhqc" title="Pax's hack @ #openhackeu">here</a>. </p>
<p>Another hack that got my attention was evA-Ziune &#8211; a site where you can report small fraud, like not getting receipts, using Foursquare&#8217;s API. This will quickly overload their servers <img src='http://blog.motane.lu/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  ! </p>
<p>The hardware hacks were also impressive, especially the one called Yahoo! Farm, a table size farm which can tell you how many friends you have online on YMessenger using robotic sheep. Pretty nifty! It won the Hacker&#8217;s choice prize! Anyway, all the projects are available <a href="http://developer.yahoo.com/hacku/show/2011/may/openhackeu" title="Open Hack EU projects">here</a> and the winners <a href="http://openhackeu.pbworks.com/" title="Open Hack EU winners">here</a>. Take a look! There are a lot of cool projects out there!</p>
<p>Our project was <a href="http://www.mooooody.com" title="Mood music">mooooody.com</a>, a site which detects your location, queries Yahoo! Weather for that location and plays music accordingly. Although it has no market value &#8211; or any other value what so ever &#8211; we had fun building it and we got a lot of positive feedback from other attendees. We mashed up a lot of clever hacks and technologies but a project that doesn&#8217;t address a real problem and is built around illegally playing copyrighted music from Youtube &#8211; a service belonging to Yahoo!&#8217;s arch-rival Google &#8211; couldn&#8217;t possibly impress the jury so we didn&#8217;t win anything. Nevertheless, we&#8217;re proud of it! </p>
<p>Congratulations to the winners, congratulations to Yahoo! for organizing such an event and congratulations to all attendees for creating such a cool atmosphere.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.motane.lu/2011/05/16/open-hack-eu/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>How to have fun with your Linux server</title>
		<link>http://blog.motane.lu/2009/06/17/how-to-have-fun-with-your-linux-server/</link>
		<comments>http://blog.motane.lu/2009/06/17/how-to-have-fun-with-your-linux-server/#comments</comments>
		<pubDate>Wed, 17 Jun 2009 19:42:41 +0000</pubDate>
		<dc:creator>Tudor</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[fun stuff]]></category>
		<category><![CDATA[funny programming]]></category>
		<category><![CDATA[linux]]></category>

		<guid isPermaLink="false">http://blog.motane.lu/?p=824</guid>
		<description><![CDATA[I&#8217;ve found a great way to have fun with your linux server. First of all, install cowsay. If you use Ubuntu server or Debian, you can use apt-get install it: Now, you have to wait for another user to connect to the server via ssh. You can use the who command to see who is [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve found a great way to have fun with your linux server. First of all, install <a href="http://en.wikipedia.org/wiki/Cowsay" title="Cowsay page in Wikipedia" class="outgoing">cowsay</a>. If you use Ubuntu server or Debian, you can use apt-get install it: </p>
<pre class="brush: plain; title: ; notranslate">
sudo apt-get install cowsay
</pre>
<p>Now, you have to wait for another user to connect to the server via ssh. You can use the <strong>who</strong> command to see who is logged in. With two open terminals on my Ubuntu box, <strong>who</strong>&#8216;s output looks something like this.</p>
<pre class="brush: plain; title: ; notranslate">
tudor@thor:~$ who
tudor    tty7         2009-06-17 20:31 (:0)
tudor    pts/0        2009-06-17 20:36 (:0.0)
tudor    pts/2        2009-06-17 22:21 (:0.0)
</pre>
<p>Let&#8217;s assume that the victim is the one using the first terminal, <strong>pts/0</strong>. Now, all you have to do is punch the following like in your terminal:</p>
<pre class="brush: plain; title: ; notranslate">
cowsay -f tux &quot;I see you&quot; &gt; /dev/pts/0
</pre>
<p>&#8230;and his terminal will look like this:</p>
<p><img src="http://blog.motane.lu/wp-content/uploads/2009/06/tux.png" alt="tux" title="tux" width="494" height="307" class="aligncenter size-full wp-image-827" /></p>
<p>Doesn&#8217;t this make you feel better about yourself? </p>
<p>Later edit: the party continues <a href="http://radu.cotescu.com/2009/06/15/bash-fun" title="Bash Fun on Radu's blog" class="outgoing">here</a>!</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.motane.lu/2009/06/17/how-to-have-fun-with-your-linux-server/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>The Vendor Client relationship &#8211; in real world situations</title>
		<link>http://blog.motane.lu/2009/06/16/the-vendor-client-relationship-in-real-world-situations/</link>
		<comments>http://blog.motane.lu/2009/06/16/the-vendor-client-relationship-in-real-world-situations/#comments</comments>
		<pubDate>Tue, 16 Jun 2009 12:28:14 +0000</pubDate>
		<dc:creator>Tudor</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[funny programming]]></category>
		<category><![CDATA[office]]></category>
		<category><![CDATA[video]]></category>

		<guid isPermaLink="false">http://blog.motane.lu/?p=817</guid>
		<description><![CDATA[An incredibly cool movie. It&#8217;s funny because is true.]]></description>
			<content:encoded><![CDATA[<p>An incredibly cool movie.</p>
<p><iframe width="500" height="315" src="http://www.youtube.com/embed/R2a8TRSgzZY" frameborder="0" allowfullscreen></iframe></p>
<p>It&#8217;s funny because is true.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.motane.lu/2009/06/16/the-vendor-client-relationship-in-real-world-situations/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Coding music</title>
		<link>http://blog.motane.lu/2009/04/14/coding-music/</link>
		<comments>http://blog.motane.lu/2009/04/14/coding-music/#comments</comments>
		<pubDate>Tue, 14 Apr 2009 04:20:25 +0000</pubDate>
		<dc:creator>Tudor</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[funny programming]]></category>
		<category><![CDATA[thoughts]]></category>

		<guid isPermaLink="false">http://blog.motane.lu/?p=579</guid>
		<description><![CDATA[What do you do while programming? And more important, what kind of music do you listen while programming? My habits are: Starting a new project: Rammstein &#8211; Sonne Taking over a project originally started by a junior programmer: Nightwish &#8211; Wish I had an angel I&#8217;m assigned to 5 years old project that uses really [...]]]></description>
			<content:encoded><![CDATA[<p>What do you do while programming? And more important, what kind of music do you listen while programming? My habits are:</p>
<ul>
<li>Starting a new project: <em>Rammstein &#8211; Sonne</em></li>
<li>Taking over a project originally started by a junior programmer: <em>Nightwish &#8211; Wish I had an angel</em></li>
<li>I&#8217;m assigned to 5 years old project that uses really old technologies and frameworks: <em>Weird Al Yankovich &#8211; Amish paradise</em></li>
<li>Looking over a Perl script written by somebody else: <em>Prodigy &#8211; Voodoo people</em></li>
<li>After a long meeting with the project manager: <em>Zebda &#8211; Hasta siempre</em></li>
<li>Debugging (first 30 minutes): <em>Rammstein &#8211; Ich will</em></li>
<li>Debugging (after 30 minutes): <em>Prodigy &#8211; Fire starter</em></li>
<li>Looking for security flaws: <em>MC Hammer &#8211; Can&#8217;t touch this</em></li>
<li>When I see a QA guy heading for my desk: <em>Nana &#8211; He&#8217;s coming</em></li>
<li>When the project goes online: <em>Britney Spears &#8211; Ops, I did it again</em> (just kidding <img src='http://blog.motane.lu/wp-includes/images/smilies/icon_razz.gif' alt=':P' class='wp-smiley' /> ) I&#8217;m having a brew and listen to <em>Irish Rovers &#8211; Star of the county down</em></li>
</ul>
<p>What do you listen to while coding?</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.motane.lu/2009/04/14/coding-music/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>The six stages of debugging</title>
		<link>http://blog.motane.lu/2009/02/25/the-six-stages-of-debugging/</link>
		<comments>http://blog.motane.lu/2009/02/25/the-six-stages-of-debugging/#comments</comments>
		<pubDate>Wed, 25 Feb 2009 17:16:16 +0000</pubDate>
		<dc:creator>Tudor</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[debug]]></category>
		<category><![CDATA[funny programming]]></category>

		<guid isPermaLink="false">http://blog.motane.lu/?p=491</guid>
		<description><![CDATA[That can’t happen That doesn’t happen on my machine That shouldn’t happen Why does that happen? Oh, I see How did that ever work? via Mihai Brehar&#8230;and if debugging means taking the bugs out, then programming means putting the bugs in]]></description>
			<content:encoded><![CDATA[<ol>
<li>That can’t happen</li>
<li>That doesn’t happen on my machine</li>
<li>That shouldn’t happen</li>
<li>Why does that happen?</li>
<li>Oh, I see</li>
<li>How did that ever work?</li>
</ol>
<p>via <a href="http://www.mihaibrehar.ro/blog/" title="Mihai Brehar's blog" class="outgoing">Mihai Brehar</a>&#8230;and if debugging means taking the bugs out, then programming means putting the bugs in <img src='http://blog.motane.lu/wp-includes/images/smilies/icon_razz.gif' alt=':P' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://blog.motane.lu/2009/02/25/the-six-stages-of-debugging/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Dynamic or variable variables in PHP</title>
		<link>http://blog.motane.lu/2009/02/03/dynamic-variables-in-php/</link>
		<comments>http://blog.motane.lu/2009/02/03/dynamic-variables-in-php/#comments</comments>
		<pubDate>Tue, 03 Feb 2009 21:56:09 +0000</pubDate>
		<dc:creator>Tudor</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[extreme php]]></category>
		<category><![CDATA[funny programming]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[tips and tricks]]></category>

		<guid isPermaLink="false">http://blog.motane.lu/?p=284</guid>
		<description><![CDATA[Variable variables (or their official name &#8211; pointed out by Ionut Stan in the comments) or &#8220;dynamic variables&#8221; (how I like to call them) is the name of a feature of the PHP programming language which allows a programmer to define a variable that has its name given by the content of another variable. Like [...]]]></description>
			<content:encoded><![CDATA[<p>Variable variables (or their official name &#8211; pointed out by Ionut Stan in the comments) or &#8220;dynamic variables&#8221; (how I like to call them) is the name of a feature of the PHP programming language which allows a programmer to define a variable that has its name given by the content of another variable. Like such: </p>
<pre class="brush: php; title: ; notranslate">
$foo = 'bar';
/*
 * declare a variable called bar into the
 * current scope and initialise it with Hello world
 */
$$foo = 'Hello world';

echo $bar; // will echo Hello world
</pre>
<p>If find this really useless and very annoying, because a typo such as a double dollar sign in front of a variable can result in some very hard to track bugs. But this isn&#8217;t just another strange feature that made its way into the trunk. This is very, very well implemented and some programmers strived a lot to make it work under all possible circumstances. It works so well that you can use strings that cannot be normally used to represent variable names, such as !@#$%^&#038;*()_+-=/*. Really, it works! </p>
<pre class="brush: php; title: ; notranslate">
$foo = '!@#$%^&amp;*()_+-=/*';
$$foo = 'Hello world';

$variables = get_defined_vars();
echo $variables['!@#$%^&amp;*()_+-=/*'];
/**
 * will echo Hello world - the content of a variable called !@#$%^&amp;*()_+-=/*
 */
</pre>
<p>Further more, it even works with objects:</p>
<pre class="brush: php; title: ; notranslate">
class Example {
     /**
      * sample attribute
      *
      * @var string
      */
     private $value;

     /**
      * default constructor
      *
      * @param $_value
      */
     public function __construct( $_value ) {
          $this-&gt;value = (string) $_value;
     }

     /**
      * returns a string representation
      * of this object
      *
      * @return string
      */
     public function __toString() {
          return $this-&gt;value;
     }
}

$foo = new Example( 'bar' );
$$foo = 'Hello world';

echo $bar; // will echo Hello world
</pre>
<p>I think this one of those features reserved for the most gurus of the gurus, because after 5 years experience with PHP and a Zend Certification, I haven&#8217;t yet grasped the logic behind this&#8230;</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.motane.lu/2009/02/03/dynamic-variables-in-php/feed/</wfw:commentRss>
		<slash:comments>13</slash:comments>
		</item>
		<item>
		<title>Common lies in freelancing</title>
		<link>http://blog.motane.lu/2009/01/29/common-lies-in-freelancing/</link>
		<comments>http://blog.motane.lu/2009/01/29/common-lies-in-freelancing/#comments</comments>
		<pubDate>Thu, 29 Jan 2009 02:27:51 +0000</pubDate>
		<dc:creator>Tudor</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[development]]></category>
		<category><![CDATA[freelancing]]></category>
		<category><![CDATA[funny programming]]></category>

		<guid isPermaLink="false">http://blog.motane.lu/?p=253</guid>
		<description><![CDATA[At one time in our careers, we all worked as freelancers. It&#8217;s fun, you get to pick your work, no annoying project managers, no accounts managers, no managers at all. You&#8217;re your own boss. Just you and the project. And yeah, almost forgot, the client. Because most freelancers are cowboy programmers that work from home, [...]]]></description>
			<content:encoded><![CDATA[<p>At one time in our careers, we all worked as freelancers. It&#8217;s fun, you get to pick your work, no annoying project managers, no accounts managers, no managers at all. You&#8217;re your own boss. Just you and the project. And yeah, almost forgot, the client.</p>
<p>Because most freelancers are <a href="http://en.wikipedia.org/wiki/Cowboy_coding" title="Cowboy coding in Wikipedia" class="outgoing">cowboy programmers</a> that work from home, sooner or later the project will fall behind schedule. Reasons include proximity to the fridge (also has a devastating effect on the waist), games that are installed on that computer, movies and so on. What do you think most people will choose between eating a huge sandwich and drinking some beer while watching the new episode  of Heroes and working? Yeah, my point exactly. </p>
<p>And when you&#8217;re behind schedule and the client asks you for a status update, you&#8217;ll do what every other moral person would. Lie about it! But try to do it with style and in a way that won&#8217;t get you caught. Most common lies are: </p>
<ul>
<li>&#8220;<em>I&#8217;ve worked on the database</em>&#8221; since nobody can actually check that</li>
<li>&#8220;<em>I&#8217;ve solved some security issues</em>&#8221; again, really hard for somebody to actually check that</li>
<li>&#8220;<em>We have a small problem with the server&#8217;s configuration, I&#8217;m working on it now</em>&#8221; somehow implies that is not your fault</li>
<li>&#8220;<em>I haven&#8217;t done the layout part yet, but everything else is ready</em>&#8221; but I can&#8217;t show it to you without the layout now, can I?</li>
<li>&#8220;<em>My (retarded) neighbour flooded me, but don&#8217;t worry, your files are safe</em>&#8221; should work, as long as he&#8217;s not your neighbour&#8230;</li>
<li>&#8220;<em>We&#8217;re almost there, I&#8217;ll set up a demo environment for you by tomorrow noon</em>&#8221; like coping some files on a FTP host takes a day and a half</li>
<li><em>I&#8217;ve worked on optimization</em>&#8230;riiiiiiiiiiiiight</li>
</ul>
<p>And in the end, a meaningful quote: <cite>I did not have sexual relations with that woman</cite>  &#8211; Bill Clinton.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.motane.lu/2009/01/29/common-lies-in-freelancing/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>About the ++ incrementer</title>
		<link>http://blog.motane.lu/2009/01/27/about-the-plus-plus-incrementer/</link>
		<comments>http://blog.motane.lu/2009/01/27/about-the-plus-plus-incrementer/#comments</comments>
		<pubDate>Tue, 27 Jan 2009 20:52:58 +0000</pubDate>
		<dc:creator>Tudor</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[funny programming]]></category>
		<category><![CDATA[tips and tricks]]></category>
		<category><![CDATA[zce]]></category>

		<guid isPermaLink="false">http://blog.motane.lu/?p=309</guid>
		<description><![CDATA[Few weeks ago I was in the middle of a debate with my girlfriend &#8211; which is also a programmer &#8211; about the increment unary operator. The main topic was what will the following code display: I said 1, she said 2. Of course, I was right in the end. But we were having this [...]]]></description>
			<content:encoded><![CDATA[<p>Few weeks ago I was in the middle of a debate with my girlfriend &#8211; which is also a programmer &#8211; about the increment unary operator. The main topic was what will the following code display:</p>
<pre class="brush: php; title: ; notranslate">
$i = 1;
$i = $i++;
echo $i;
</pre>
<p>I said 1, she said 2. Of course, I was right in the end. But we were having this conversation while we were heading out to meet some friends, so, inevitably, others were drawn into the debate. One of which is Costin, who posted on his blog an entry called <a href="http://siderite.blogspot.com/2009/01/ii-trials-and-tribulations-of-c.html" title="Siderite Zachwehdex's blog - The trials and tribulations of the C incrementer" class="outgoing">The trials and tribulations of the C incrementer</a> on this subject. Long story short, if you post increment a variable, this operation will take place last and its result will be poped first from the stack and in some cases will be lost (our case &#8211; read Costin&#8217;s post for more details).</p>
<p>Other annoying examples using the increment operator:</p>
<pre class="brush: php; title: ; notranslate">
$i = 1;
function someFunction( $_value ) {
    echo $_value;
}

someFunction( $i++ ); // will display 1
someFunction( ++$i ); // will display 2

$j = 1;
$j = ++$j;
echo $j; // will display 2
</pre>
<p>And again, the ZCE exam features this kind of questions.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.motane.lu/2009/01/27/about-the-plus-plus-incrementer/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
		<item>
		<title>Variable interchange</title>
		<link>http://blog.motane.lu/2009/01/19/variable-interchange/</link>
		<comments>http://blog.motane.lu/2009/01/19/variable-interchange/#comments</comments>
		<pubDate>Mon, 19 Jan 2009 21:46:03 +0000</pubDate>
		<dc:creator>Tudor</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[funny programming]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[tips and tricks]]></category>
		<category><![CDATA[xor]]></category>

		<guid isPermaLink="false">http://blog.motane.lu/?p=258</guid>
		<description><![CDATA[How to interchange 2 variables? A simple question with a simple answer. Most people will do it like this: Quite elementary. But it can be done in a much more elegant manner, using arithmetical (addition &#038; subtraction) or logical (xor) operators. First of all, let&#8217;s interchange the variables using addition and subtraction. The code will [...]]]></description>
			<content:encoded><![CDATA[<p>How to interchange 2 variables? A simple question with a simple answer. Most people will do it like this:</p>
<pre class="brush: php; title: ; notranslate">
// interchanging using a temporary variable
$a = 2;
$b = 3;

$temp = $a;
$a = $b;
$b = $temp;

echo $a . ' ' . $b . PHP_EOL; // will display 3 2
</pre>
<p>Quite elementary. But it can be done in a much more elegant manner, using arithmetical (addition &#038; subtraction) or logical (xor) operators.<span id="more-258"></span><br />
First of all, let&#8217;s interchange the variables using addition and subtraction. The code will look like this:</p>
<pre class="brush: php; title: ; notranslate">
// arithmentical operations
$a = 2;
$b = 3;

$a = $a + $b; // a = 5, b = 3
$b = $a - $b; // a = 5, b = 2
$a = $a - $b; // a = 3, b = 2

echo $a . ' ' . $b . PHP_EOL;
</pre>
<p>&#8230;or, in a more &#8220;hacker&#8221; style&#8230;</p>
<pre class="brush: plain; title: ; notranslate">
// arithmetical operations - one line
$a = 2;
$b = 3;

$a = $a + $b - ( $b = $a );

echo $a . ' ' . $b . PHP_EOL;
</pre>
<p>But variable interchange can also done using the XOR operator. This is also supposed to be the fastest way.</p>
<pre class="brush: php; title: ; notranslate">
// xor

$a = 2; // 10 (in binary)
$b = 3; // 11 (in binary)

$a = $a ^ $b; // a = 01, b = 11
$b = $a ^ $b; // a = 01, b = 10
$a = $a ^ $b; // a = 11, b = 10

echo $a . ' ' . $b . PHP_EOL;
</pre>
<p>Again, one line variable interchange, this time using xor.</p>
<pre class="brush: php; title: ; notranslate">
// xor - one line
$a = 10;
$b = 5;

$a = $a ^ $b ^ ( $b = $a );

echo $a . ' ' . $b . PHP_EOL;
</pre>
<p>What are these good for? Well, let&#8217;s see, you can post them on your blog late at night when you&#8217;re not sleepy and pretend you know everything. Of course, this isn&#8217;t my case, since is not *that* late at night.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.motane.lu/2009/01/19/variable-interchange/feed/</wfw:commentRss>
		<slash:comments>16</slash:comments>
		</item>
		<item>
		<title>Language constructs fun</title>
		<link>http://blog.motane.lu/2009/01/16/language-constructs-fun/</link>
		<comments>http://blog.motane.lu/2009/01/16/language-constructs-fun/#comments</comments>
		<pubDate>Thu, 15 Jan 2009 22:36:22 +0000</pubDate>
		<dc:creator>Tudor</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[funny programming]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[zce]]></category>

		<guid isPermaLink="false">http://blog.motane.lu/?p=230</guid>
		<description><![CDATA[What will the following code produce? Tough question? Not quite. Just run the code and find out the answer. If you&#8217;re too lazy or don&#8217;t have a PHP server at hand, I&#8217;ll tell you the result. It will print 511 to the screen. Now comes the tough question. Why is that? We &#8211; me and [...]]]></description>
			<content:encoded><![CDATA[<p>What will the following code produce?</p>
<pre class="brush: php; title: ; notranslate">
echo '1' . print( 2 ) + 3;
</pre>
<p>Tough question? Not quite. Just run the code and find out the answer. If you&#8217;re too lazy or don&#8217;t have a PHP server at hand, I&#8217;ll tell you the result. It will print 511 to the screen. Now comes the tough question. Why is that? We &#8211; me and my colleagues at <a href="http://www.zitec.com" title="Zitec" class="outgoing">Zitec</a> &#8211; sat quite a while before figuring it out. It goes like this (special thanks go the Alex &#8220;the badger&#8221; Novac &#8211; see his pic on Zitec&#8217;s Team page): print is a language construct. It doesn&#8217;t need brackets to work. The following lines do the same thing:</p>
<pre class="brush: php; title: ; notranslate">
print( 5 ); // will print 5
print 5; // again, will print 5
</pre>
<p>Thus, the line <code>print(2) + 3</code> will translate as <code>print 5</code>, because the brackets are used &#8220;arithmetically&#8221; here, stating that their content should be evaluated first. Basically it happens like this: it evaluates (2) to 2, adds 3 and prints the result. This will give us the 5 on the first position. As stated in the php manual, print always returns 1. So after displaying the first 5, the code becomes <code>echo '1' . 1</code>. Pretty self explanatory.</p>
<p>If you want to take the Zend Certified Engineer exam, expect this type of questions.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.motane.lu/2009/01/16/language-constructs-fun/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

