
<?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>brandontreb.com &#187; Programming Tip Of The Day</title>
	<atom:link href="http://brandontreb.com/category/nerdyness/programming-nerdyness/programming-tip-of-the-day-programming-nerdyness-nerdyness/feed/" rel="self" type="application/rss+xml" />
	<link>http://brandontreb.com</link>
	<description>Code, Nerdyness, and Nonsense</description>
	<lastBuildDate>Wed, 07 Jul 2010 00:23:24 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Programming Tip Of The Day #2 &#8211; Difference Between i++ and ++i</title>
		<link>http://brandontreb.com/programming-tip-of-the-day-2-difference-between-i-and-i/</link>
		<comments>http://brandontreb.com/programming-tip-of-the-day-2-difference-between-i-and-i/#comments</comments>
		<pubDate>Sat, 05 Dec 2009 01:00:20 +0000</pubDate>
		<dc:creator>brandontreb</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Programming Tip Of The Day]]></category>
		<category><![CDATA[decremental operator]]></category>
		<category><![CDATA[i++]]></category>
		<category><![CDATA[incremental operator]]></category>

		<guid isPermaLink="false">http://brandontreb.com/?p=677</guid>
		<description><![CDATA[Ok, so this should seem obvious and if I am insulting your intelligence by stating it, I am sorry.  One of the main reasons I want to discuss this is, I was asked this exact question in a job interview for Lockheed Martin.]]></description>
			<content:encoded><![CDATA[<p>To some, this should seem a bit obvious and if I am insulting your intelligence by discussing it, I am sorry.  But, one of the main reasons I want to discuss this topic is, I was asked this question in a job interview for Lockheed Martin.</p>
<p><b>What is the difference between i++ and ++i?</b></p>
<p>The answer is actually quite simple.</p>
<h3><span style="color: #00ccff;">i++</span> first evaluates the value of i and then increments it</h3>
<h3><span style="color: #00ccff;">++i</span> increments the value of i and then evaluates it</h3>
<p>Here is a brief example to demonstrate what I mean.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">// Example: i++ </span>
<span style="color: #000088;">$i</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">5</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;The value of i is &quot;</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$i</span><span style="color: #339933;">++</span> <span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">// Output &quot;The value of i is 5&quot;</span>
<span style="color: #666666; font-style: italic;">// i = 6</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Example: ++i </span>
<span style="color: #000088;">$i</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">5</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;The value of i is &quot;</span> <span style="color: #339933;">.</span> <span style="color: #339933;">++</span><span style="color: #000088;">$i</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">// Output &quot;The value of i is 6&quot;</span>
<span style="color: #666666; font-style: italic;">// i = 6</span></pre></div></div>

<p>So, now if you are ever asked about this in an interview, you will have a response.</p>
<p>Happy programming!</p>
]]></content:encoded>
			<wfw:commentRss>http://brandontreb.com/programming-tip-of-the-day-2-difference-between-i-and-i/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Programming Tip Of The Day #1 &#8211; Ternary Operator</title>
		<link>http://brandontreb.com/programming-tip-of-the-day-1-ternary-operator/</link>
		<comments>http://brandontreb.com/programming-tip-of-the-day-1-ternary-operator/#comments</comments>
		<pubDate>Fri, 04 Dec 2009 00:30:48 +0000</pubDate>
		<dc:creator>brandontreb</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Programming Tip Of The Day]]></category>
		<category><![CDATA[coding]]></category>
		<category><![CDATA[programming tip of the day]]></category>
		<category><![CDATA[programming tips]]></category>
		<category><![CDATA[ptotd]]></category>
		<category><![CDATA[ternary]]></category>
		<category><![CDATA[ternary operator]]></category>

		<guid isPermaLink="false">http://brandontreb.com/?p=667</guid>
		<description><![CDATA[<p>So, I though I'd start this series called Programming Tip Of The Day to write about useful things I come across in programming.  Both to educate my readers and as a personal archive of ideas and tips.</p>

<p>I will kick it off today with a quick rant about the <strong>ternary operator</strong>.  I &#60;3 the ternary operator.  It's quick, efficient and saves a lot of ugly code.</p>]]></description>
			<content:encoded><![CDATA[<p>So, I though I&#8217;d start this series called Programming Tip Of The Day to write about useful things I come across in programming.  Both to educate my readers and as a personal archive of ideas and tips.</p>
<p>I will kick it off today with a quick rant about the <strong>ternary operator</strong>.  I &lt;3 the ternary operator.  It&#8217;s quick, efficient and saves a lot of ugly code.</p>
<p>For those of you who don&#8217;t know, the ternary operator is made up of 3 elements: The condition and two results.  It is of the form:</p>
<h2>(condition) ? (result if true) : (result if false);</h2>
<p>This is much nicer than an if statement.  So here is a brief example about how a ternary operator can replace an if-statement.</p>
<h3>if-statement</h3>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;"><span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span>isSnowing<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	iMustBe <span style="color: #339933;">=</span> <span style="color: #ff0000;">&quot;cold&quot;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
	iMustBe <span style="color: #339933;">=</span> <span style="color: #ff0000;">&quot;warm&quot;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<h3>Same thing using ternary</h3>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;">iMustBe <span style="color: #339933;">=</span> isSnowing <span style="color: #339933;">?</span> <span style="color: #ff0000;">&quot;cold&quot;</span> <span style="color: #339933;">:</span> <span style="color: #ff0000;">&quot;warm&quot;</span><span style="color: #339933;">;</span></pre></div></div>

<p>That is so much easier to read (IMHO).  You can even do clever things in printing.  Here is a small example in PHP for using the ternary operator when doing an echo.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
  <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;I am a &quot;</span><span style="color: #339933;">.</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>height <span style="color: #339933;">&gt;</span> <span style="color: #cc66cc;">72</span><span style="color: #009900;">&#41;</span> ? <span style="color: #0000ff;">&quot;tall&quot;</span> <span style="color: #339933;">:</span> <span style="color: #0000ff;">&quot;short&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot; person!&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>Most languages support the ternary operator.  Check out <a href="http://en.wikipedia.org/wiki/Ternary_operation">this wiki page</a> if you want more info.</p>
<p>Happy programming!</p>
]]></content:encoded>
			<wfw:commentRss>http://brandontreb.com/programming-tip-of-the-day-1-ternary-operator/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>
