<?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"
	>
<channel>
	<title>Comments on: Conditional Assignments</title>
	<atom:link href="http://mikeage.net/2006/10/15/conditional-assignments/feed/" rel="self" type="application/rss+xml" />
	<link>http://mikeage.net/2006/10/15/conditional-assignments/</link>
	<description>mikeage.net</description>
	<pubDate>Sat, 22 Nov 2008 10:25:22 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.6.3</generator>
		<item>
		<title>By: Mike Miller</title>
		<link>http://mikeage.net/2006/10/15/conditional-assignments/#comment-1789</link>
		<dc:creator>Mike Miller</dc:creator>
		<pubDate>Tue, 17 Oct 2006 15:12:45 +0000</pubDate>
		<guid isPermaLink="false">http://mikeage.net/2006/10/11/conditional-assignments/#comment-1789</guid>
		<description>I use it (then again, I'm a big time C hacker &lt;g&gt;).

This little trick is rather useless, I admit, but a fun piece of trivia (I'm interviewing some students now for a position, and so I've been collecting fun bits of trivial trivia). If you prefer if/else, be my guest... it is a little more readable, but sometimes, you have a long and complex statement that you really don't want to rewrite, or a print statement that needs some text:
&lt;code allow="none"&gt;
max = (i&gt;j) ? i : j; 
&lt;/code&gt;
instead of:

&lt;pre&gt;&lt;code allow="none"&gt;
if (i&gt;j)
  max = i;
else
  max = j;
&lt;/code&gt;&lt;/pre&gt;
I assume you also prefer brackets, which means you might have:
&lt;pre&gt;&lt;code allow="none"&gt;
if (i&gt;j) {
  max = i;
} else {
  max = j;
}
&lt;/code&gt;&lt;/pre&gt;
Is that really better? Sometimes, cleaner code is when you can see the entire thing on one screen, instead of having a really long spread out function.

Also, compare:
&lt;pre&gt;&lt;code allow="none"&gt;
if (0 == stat) {
  printf("Test number %d (input parameters %d, %04X, %6f) passed (status code %d)\n",index, foo, bar, fubar, stat);
} else {
  printf("Test number %d (input parameters %d, %04X, %6f) failed (status code %d)\n",index, foo, bar, fubar, stat);
}
&lt;/code&gt;&lt;/pre&gt;
with
&lt;pre&gt;&lt;code allow="none"&gt;
printf("Test number %d (input parameters %d, %04X, %6f) %s (status code %d)\n",index, foo, bar, fubar, (0 == stat) ? "passed" : "failed", stat);
&lt;/code&gt;&lt;/pre&gt;</description>
		<content:encoded><![CDATA[<p>I use it (then again, I&#039;m a big time C hacker <g>).</g></p>
<p>This little trick is rather useless, I admit, but a fun piece of trivia (I&#039;m interviewing some students now for a position, and so I&#039;ve been collecting fun bits of trivial trivia). If you prefer if/else, be my guest&#8230; it is a little more readable, but sometimes, you have a long and complex statement that you really don&#039;t want to rewrite, or a print statement that needs some text:<br />
<code allow="none"><br />
max = (i>j) ? i : j;<br />
</code><br />
instead of:</p>
<pre><code allow="none">
if (i>j)
  max = i;
else
  max = j;
</code></pre>
<p>I assume you also prefer brackets, which means you might have:</p>
<pre><code allow="none">
if (i>j) {
  max = i;
} else {
  max = j;
}
</code></pre>
<p>Is that really better? Sometimes, cleaner code is when you can see the entire thing on one screen, instead of having a really long spread out function.</p>
<p>Also, compare:</p>
<pre><code allow="none">
if (0 == stat) {
  printf("Test number %d (input parameters %d, %04X, %6f) passed (status code %d)\n",index, foo, bar, fubar, stat);
} else {
  printf("Test number %d (input parameters %d, %04X, %6f) failed (status code %d)\n",index, foo, bar, fubar, stat);
}
</code></pre>
<p>with</p>
<pre><code allow="none">
printf("Test number %d (input parameters %d, %04X, %6f) %s (status code %d)\n",index, foo, bar, fubar, (0 == stat) ? "passed" : "failed", stat);
</code></pre>
]]></content:encoded>
	</item>
	<item>
		<title>By: Isaac</title>
		<link>http://mikeage.net/2006/10/15/conditional-assignments/#comment-1787</link>
		<dc:creator>Isaac</dc:creator>
		<pubDate>Tue, 17 Oct 2006 13:21:31 +0000</pubDate>
		<guid isPermaLink="false">http://mikeage.net/2006/10/11/conditional-assignments/#comment-1787</guid>
		<description>Do you ever actually use the famous trinary operator
... in code that anyone else is going to read/maintain?

I'm no big-time C hacker, but C++ code is a major part of my job, and it seems to me that if/else is a great deal more readable, even for little one- or two-liners. The main utilities of ?/:, it seems to me, are to help you save a few bytes on the hard drive where you keep your code and to keep the ? and : characters from feeling bad for being left out of the language specification.</description>
		<content:encoded><![CDATA[<p>Do you ever actually use the famous trinary operator<br />
&#8230; in code that anyone else is going to read/maintain?</p>
<p>I&#039;m no big-time C hacker, but C++ code is a major part of my job, and it seems to me that if/else is a great deal more readable, even for little one- or two-liners. The main utilities of ?/:, it seems to me, are to help you save a few bytes on the hard drive where you keep your code and to keep the ? and : characters from feeling bad for being left out of the language specification.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
