<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xml:base="http://php.dzone.com"  xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:dz="http://www.developerzone.com/modules/dz/1.0">
<channel>
 <title>PHP Zone - Comments for &quot;Tips &amp;amp;amp; Tricks of Learning Ternary Operators&quot;</title>
 <link>http://php.dzone.com/news/tips-tricks-learning-ternary-o</link>
 <description>Comments for &quot;Tips &amp; Tricks of Learning Ternary Operators&quot;</description>
 <language>en</language>
<item>
 <title>Good, article.</title>
 <link>http://php.dzone.com/news/tips-tricks-learning-ternary-o#comment-3307</link>
 <description>&lt;!--paging_filter--&gt;Good, article.</description>
 <pubDate>Thu, 15 May 2008 22:22:22 -0400</pubDate>
 <dc:creator>mohayus</dc:creator>
 <guid isPermaLink="false">comment 3307 at http://php.dzone.com</guid>
</item>
<item>
 <title>Good article, I do agree</title>
 <link>http://php.dzone.com/news/tips-tricks-learning-ternary-o#comment-3047</link>
 <description>&lt;!--paging_filter--&gt;&lt;p&gt;Good article, I do agree with Stoyan however on using the ternary for more complex scenarios. I imagine though that David was purely showing what you &lt;i&gt;can&lt;/i&gt; do...not really recommending a best practice approach as such.&lt;/p&gt;&lt;p&gt;Ternary&#039;s can be fantastic, good to know what you can and can&#039;t do but readability and maintability is king. &lt;/p&gt;</description>
 <pubDate>Fri, 02 May 2008 23:02:37 -0400</pubDate>
 <dc:creator>sharmo</dc:creator>
 <guid isPermaLink="false">comment 3047 at http://php.dzone.com</guid>
</item>
<item>
 <title>Dear PHP newcomer reading</title>
 <link>http://php.dzone.com/news/tips-tricks-learning-ternary-o#comment-1913</link>
 <description>&lt;!--paging_filter--&gt;&lt;p&gt;Dear PHP newcomer reading this post. Please read it carefully and try to understand the logic behind the ternary operator.  After this brain-excercise, just use your if()&#039;s and almost forget about the ternary. With unnecessary use of ternary operators you just DON&#039;T &amp;quot;keep your code organized for later maintenance&amp;quot;, you keep your code more difficult for others (and later for you) to read:&lt;/p&gt;&lt;p&gt;Compare:&lt;br /&gt;&lt;/p&gt;&lt;pre class=&quot;php&quot;&gt;$age_code = ($age &amp;gt; 10 ? ($age &amp;gt; 20 ? ($age &amp;gt; 30 ? &#039;senior&#039; : &#039;adult&#039;) : &#039;teen&#039;) : &#039;youngster&#039;);&lt;br /&gt;&lt;/pre&gt;&lt;p&gt;and&lt;/p&gt;&lt;pre class=&quot;php&quot;&gt;If ($age &amp;lt;= 10) $age_code = &#039;youngster&#039;;&lt;br /&gt;else&lt;br /&gt;if ($age &amp;lt;= 20) $age_code = &#039;teen&#039;;&lt;br /&gt;else&lt;br /&gt;if ($age &amp;lt;= 30) $age_code = &#039;senior&#039;;&lt;br /&gt;else&lt;br /&gt;if ($age &amp;gt; 30)  $age_code = &#039;adult&#039;;&lt;/pre&gt;&lt;p&gt;&lt;br /&gt;Which one is easier to understand at first reading ? To which is easier to add more conditions ?&lt;br /&gt;The good programming is not the tricky programming. &lt;/p&gt;&lt;p&gt;If you have one short and simple condition, you could use ternary operator:&lt;/p&gt;&lt;pre class=&quot;php&quot;&gt;$decision = ($condition &amp;gt; 50) ? &#039;action1&#039; : &#039;action2&#039;;&lt;br /&gt;&lt;/pre&gt;&lt;p&gt;But in this situation I wouldn&#039;t recommend its use:&lt;/p&gt;&lt;pre class=&quot;php&quot;&gt;$decision = ($condition = $this-&amp;gt;getAnotherCond($foo) &amp;amp;&amp;amp; $condition &amp;gt; 50) ? &#039;justVeryLongActionToTake&#039; : &#039;justMoreLongerActionToTake&#039;;&lt;br /&gt;&lt;/pre&gt;&lt;p&gt;The code is long and hard to read. Just rewrite it:&lt;/p&gt;&lt;pre class=&quot;php&quot;&gt;$condition = $this-&amp;gt;getAnotherCond($foo);&lt;br /&gt;if ($condition &amp;gt; 50) {&lt;br /&gt;$decision = &#039;justVeryLongActionToTake&#039;;&lt;br /&gt;} else {&lt;br /&gt;$decision = &#039;justMoreLongerActionToTake&#039;;&lt;br /&gt;}&lt;/pre&gt;&lt;p&gt; Keep your code easy to read even at the expense of some extra chars typed. It&#039;s good to know a language features, but do not overuse them.&lt;br /&gt;&lt;br /&gt; &lt;/p&gt;</description>
 <pubDate>Thu, 20 Mar 2008 10:58:59 -0400</pubDate>
 <dc:creator>dolorian</dc:creator>
 <guid isPermaLink="false">comment 1913 at http://php.dzone.com</guid>
</item>
<item>
 <title>:P </title>
 <link>http://php.dzone.com/news/tips-tricks-learning-ternary-o#comment-1887</link>
 <description>&lt;!--paging_filter--&gt;&lt;p&gt;:P &lt;/p&gt;</description>
 <pubDate>Wed, 19 Mar 2008 00:31:17 -0400</pubDate>
 <dc:creator>kenman</dc:creator>
 <guid isPermaLink="false">comment 1887 at http://php.dzone.com</guid>
</item>
<item>
 <title>My paste borked...hence I</title>
 <link>http://php.dzone.com/news/tips-tricks-learning-ternary-o#comment-1886</link>
 <description>&lt;!--paging_filter--&gt;&lt;p&gt;My paste borked...hence I gave up &lt;/p&gt;</description>
 <pubDate>Tue, 18 Mar 2008 22:08:42 -0400</pubDate>
 <dc:creator>FuzzyOne</dc:creator>
 <guid isPermaLink="false">comment 1886 at http://php.dzone.com</guid>
</item>
<item>
 <title>Another great use for</title>
 <link>http://php.dzone.com/news/tips-tricks-learning-ternary-o#comment-1881</link>
 <description>&lt;!--paging_filter--&gt;&lt;p&gt;Another great use for ternary op&#039;s is in templating engines where the dev and designer can work more easily... &lt;/p&gt;&lt;pre class=&quot;php&quot;&gt;&amp;lt;?php foreach($items as $item) : ?&amp;gt;&lt;br /&gt;&lt;/pre&gt;&lt;pre class=&quot;php&quot;&gt;&amp;lt;div&amp;gt;&lt;br /&gt;	&amp;lt;p&amp;gt;&amp;lt;?php echo $item; ?&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;&amp;lt;/div&lt;/pre&gt;&lt;pre class=&quot;php&quot;&gt;&amp;lt;?php endforeach; ?&amp;gt;&lt;/pre&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;</description>
 <pubDate>Tue, 18 Mar 2008 14:54:46 -0400</pubDate>
 <dc:creator>FuzzyOne</dc:creator>
 <guid isPermaLink="false">comment 1881 at http://php.dzone.com</guid>
</item>
</channel>
</rss>
