<?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: Using PHP&#8217;s alternate syntaxes</title>
	<atom:link href="http://coffeepowered.co.uk/2010/01/using-phps-alternate-syntaxes-to-aid-code-readability/feed/" rel="self" type="application/rss+xml" />
	<link>http://coffeepowered.co.uk/2010/01/using-phps-alternate-syntaxes-to-aid-code-readability/</link>
	<description>The online ramblings of Paul Stanton</description>
	<lastBuildDate>Thu, 17 May 2012 10:25:09 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
	<item>
		<title>By: Stanton</title>
		<link>http://coffeepowered.co.uk/2010/01/using-phps-alternate-syntaxes-to-aid-code-readability/comment-page-1/#comment-1098</link>
		<dc:creator>Stanton</dc:creator>
		<pubDate>Tue, 26 Jan 2010 07:25:26 +0000</pubDate>
		<guid isPermaLink="false">http://coffeepowered.co.uk/?p=348#comment-1098</guid>
		<description>@Andrew Pryde

Perhaps you&#039;re right about the ternary operator reducing readability, although I feel that for small evaluations which may be inline with PHP, It&#039;s great :)

@Dan Brown

Thanks for taking the time to reply :) I deliberately kept the example code simple but you&#039;re right, there should be a step in there which protects against an undefined variable throwing a warning. One thing I love (and hate, sometimes) is that there&#039;s a thousand ways you can do things in PHP, I&#039;d probably do this:

&lt;code lang=&quot;php&quot;&gt;$comments = (isset($count) &amp;&amp; $count == 1) ? &#039;comment&#039; : &#039;comments&#039;;&lt;/code&gt;

Of course this then poses the question of &quot;If $count isn&#039;t set, you wouldn&#039;t want to echo &#039;comments&#039; at all, and we start making the example too verbose to explain the initial meaning... but I know what you mean :)</description>
		<content:encoded><![CDATA[<p>@Andrew Pryde</p>
<p>Perhaps you&#8217;re right about the ternary operator reducing readability, although I feel that for small evaluations which may be inline with PHP, It&#8217;s great <img src='http://coffeepowered.co.uk/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>@Dan Brown</p>
<p>Thanks for taking the time to reply <img src='http://coffeepowered.co.uk/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  I deliberately kept the example code simple but you&#8217;re right, there should be a step in there which protects against an undefined variable throwing a warning. One thing I love (and hate, sometimes) is that there&#8217;s a thousand ways you can do things in PHP, I&#8217;d probably do this:</p>
<div class="codecolorer-container php default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br /></div></td><td><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000088;">$comments</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$count</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #000088;">$count</span> <span style="color: #339933;">==</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span> ? <span style="color: #0000ff;">'comment'</span> <span style="color: #339933;">:</span> <span style="color: #0000ff;">'comments'</span><span style="color: #339933;">;</span></div></td></tr></tbody></table></div>
<p>Of course this then poses the question of &#8220;If $count isn&#8217;t set, you wouldn&#8217;t want to echo &#8216;comments&#8217; at all, and we start making the example too verbose to explain the initial meaning&#8230; but I know what you mean <img src='http://coffeepowered.co.uk/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Dan Brown</title>
		<link>http://coffeepowered.co.uk/2010/01/using-phps-alternate-syntaxes-to-aid-code-readability/comment-page-1/#comment-1094</link>
		<dc:creator>Dan Brown</dc:creator>
		<pubDate>Mon, 25 Jan 2010 22:36:47 +0000</pubDate>
		<guid isPermaLink="false">http://coffeepowered.co.uk/?p=348#comment-1094</guid>
		<description>I prefer to do this -

&lt;code lang=&quot;php&quot;&gt;
$comments = ‘comments’;
if ($count = 1) {
$comments = ‘comment’;
}
echo $count . ‘ ‘ . $comments;
&lt;/code&gt;

- than use the ternary operator. It also means the variable is always set to a known value (preferably the safest of he options) rather than undefined if the setting code doesn&#039;t get run due to some logic error.</description>
		<content:encoded><![CDATA[<p>I prefer to do this -</p>
<div class="codecolorer-container php default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br /></div></td><td><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000088;">$comments</span> <span style="color: #339933;">=</span> ‘comments’<span style="color: #339933;">;</span><br />
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$count</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
<span style="color: #000088;">$comments</span> <span style="color: #339933;">=</span> ‘comment’<span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span><br />
<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$count</span> <span style="color: #339933;">.</span> ‘ ‘ <span style="color: #339933;">.</span> <span style="color: #000088;">$comments</span><span style="color: #339933;">;</span></div></td></tr></tbody></table></div>
<p>- than use the ternary operator. It also means the variable is always set to a known value (preferably the safest of he options) rather than undefined if the setting code doesn&#8217;t get run due to some logic error.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Andrew Pryde</title>
		<link>http://coffeepowered.co.uk/2010/01/using-phps-alternate-syntaxes-to-aid-code-readability/comment-page-1/#comment-1093</link>
		<dc:creator>Andrew Pryde</dc:creator>
		<pubDate>Mon, 25 Jan 2010 10:35:50 +0000</pubDate>
		<guid isPermaLink="false">http://coffeepowered.co.uk/?p=348#comment-1093</guid>
		<description>Many argue that omitting brackets and using the ternary operator reduces readability. I agree with you when you have embedded blocks of HTML but I think the ternary operator reduces readability.

My ten cents anyway, 

&lt;a href=&quot;http://www.pryde-design.co.uk&quot; rel=&quot;nofollow&quot;&gt;@Prydie&lt;/a&gt;</description>
		<content:encoded><![CDATA[<p>Many argue that omitting brackets and using the ternary operator reduces readability. I agree with you when you have embedded blocks of HTML but I think the ternary operator reduces readability.</p>
<p>My ten cents anyway, </p>
<p><a href="http://www.pryde-design.co.uk" rel="nofollow">@Prydie</a></p>
]]></content:encoded>
	</item>
</channel>
</rss>

