<?xml version="1.0" encoding="UTF-8"?>
<!-- generator="wordpress/2.3.3" -->
<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/"
	>

<channel>
	<title>Principles, Patterns and Practices</title>
	<link>http://www.principlespatternsandpractices.com</link>
	<description>Andrew Culver, an inexperienced software engineer, vents opinions of questionable value on PHP and software development while inviting rebuke from strangers.</description>
	<pubDate>Mon, 22 Sep 2008 17:02:07 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.3.3</generator>
	<language>en</language>
			<item>
		<title>Vespa: Refining Our Definition of MVC</title>
		<link>http://www.principlespatternsandpractices.com/2008/09/22/vespa-refining-our-definition-of-mvc/</link>
		<comments>http://www.principlespatternsandpractices.com/2008/09/22/vespa-refining-our-definition-of-mvc/#comments</comments>
		<pubDate>Mon, 22 Sep 2008 08:00:29 +0000</pubDate>
		<dc:creator>andrew</dc:creator>
		
		<category><![CDATA[Uncategorized]]></category>

		<category><![CDATA[controllers]]></category>

		<category><![CDATA[design patterns]]></category>

		<category><![CDATA[mvc]]></category>

		<guid isPermaLink="false">http://www.principlespatternsandpractices.com/2008/09/22/vespa-refining-our-definition-of-mvc/</guid>
		<description><![CDATA[Bennett McElwee recently published an article titled &#8220;Vespa: A Better MVC&#8220;.  As the title suggests, he presents his observations of the traditional understanding of an MVC structure and provides his own suggestions for how it might be improved.  If this sounds interesting to you, I&#8217;d recommend you read the article.
Given it&#8217;s relevance to [...]]]></description>
			<content:encoded><![CDATA[<p>Bennett McElwee recently published an article titled &#8220;<a href="http://www.thunderguy.com/semicolon/2008/06/23/vespa-a-better-mvc/" onclick="javascript:pageTracker._trackPageview('/outbound/article/www.thunderguy.com');">Vespa: A Better MVC</a>&#8220;.  As the title suggests, he presents his observations of the traditional understanding of an MVC structure and provides his own suggestions for how it might be improved.  If this sounds interesting to you, I&#8217;d recommend you <a href="http://www.thunderguy.com/semicolon/2008/06/23/vespa-a-better-mvc/" onclick="javascript:pageTracker._trackPageview('/outbound/article/www.thunderguy.com');">read the article</a>.</p>
<p>Given it&#8217;s relevance to the work I&#8217;ve been doing recently, I was particularly interested in Bennett&#8217;s improvements to the controller component of the traditional MVC pattern.  He distinguishes between two types of controllers, calling them &#8220;actors&#8221; and &#8220;presenters&#8221;.</p>
<p>In the context of web applications, this clarification makes great sense to those of us who have implemented the Post-Redirect-Get pattern as a means of fixing the back button in our user&#8217;s browser and allowing them to bookmark resources throughout our application.  The &#8220;presenters&#8221; that Bennett speaks of correspond to the controllers that handle GET requests.  The &#8220;actors&#8221; correspond to the controllers that handle POST requests and then redirect to another GET request.</p>
<p>That being said, this improvement really stands on it&#8217;s own as a single improvement the controller component of the MVC design pattern.  However, Bennett has coupled it together with another model-and-view related improvement which, great as it may be, is less obvious and relevant to me, and I may or may not want to use.</p>
<p>Both improvements may be valuable.  I&#8217;m confident one is and I&#8217;m thankful Bennett has taken the time to document it.  But in the end they stand or fall individually.  If our purpose is to build a shared vocabulary, why not decouple the two improvements and name them individually?</p>
<p>Thanks again, Bennett!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.principlespatternsandpractices.com/2008/09/22/vespa-refining-our-definition-of-mvc/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Ticketing System Emails</title>
		<link>http://www.principlespatternsandpractices.com/2008/06/26/ticketing-system-emails/</link>
		<comments>http://www.principlespatternsandpractices.com/2008/06/26/ticketing-system-emails/#comments</comments>
		<pubDate>Thu, 26 Jun 2008 19:11:32 +0000</pubDate>
		<dc:creator>andrew</dc:creator>
		
		<category><![CDATA[Uncategorized]]></category>

		<category><![CDATA[email]]></category>

		<category><![CDATA[process]]></category>

		<category><![CDATA[productivity]]></category>

		<category><![CDATA[the zone]]></category>

		<category><![CDATA[tickets]]></category>

		<category><![CDATA[trac]]></category>

		<guid isPermaLink="false">http://www.principlespatternsandpractices.com/2008/06/26/ticketing-system-emails/</guid>
		<description><![CDATA[Our ticketing system, Trac, spits out an email to everyone who has ever been associated with a ticket anytime anyone makes a change to it.  For me, on this team, it generates an enormous amount of email.
And I love it.  It&#8217;s great information.  It keeps me in the loop in a great way.  I set [...]]]></description>
			<content:encoded><![CDATA[<p>Our ticketing system, Trac, spits out an email to everyone who has ever been associated with a ticket anytime anyone makes a change to it.  For me, on this team, it generates an enormous amount of email.</p>
<p>And I love it.  It&#8217;s great information.  It keeps me in the loop in a great way.  I set aside time at the beginning or end of each day to review all of those emails at once.  Otherwise they would only distract me all day and clutter up my inbox.</p>
<p>However, in the storm of emails Trac spits out at me, there are a select few that really do require immediate attention.  We want Trac to be a legitimate and centralized means of documenting important needs.</p>
<p>Solution?  A couple household filters in your mail client.  Not every change or comment on a ticket assigned to me required my immediate attention, but many do.  Furthermore, all of the changes and comments that do require my immediate attention are on tickets that are being or have been assigned to me.</p>
<p>So filtering all emails with &#8220;Owner: andrew.culver&#8221; to my inbox and all other identifiable Trac tickets into a separate folder does the trick.</p>
<p>A simple strategy designed to defend my &#8220;flow&#8221; or &#8220;the zone&#8221; or whatever you like to call it.  All care of a few basic email filters.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.principlespatternsandpractices.com/2008/06/26/ticketing-system-emails/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Ah, My Favorite Resource</title>
		<link>http://www.principlespatternsandpractices.com/2008/06/24/ah-my-favorite-resource/</link>
		<comments>http://www.principlespatternsandpractices.com/2008/06/24/ah-my-favorite-resource/#comments</comments>
		<pubDate>Tue, 24 Jun 2008 13:33:30 +0000</pubDate>
		<dc:creator>andrew</dc:creator>
		
		<category><![CDATA[Uncategorized]]></category>

		<category><![CDATA[design patterns]]></category>

		<category><![CDATA[resources]]></category>

		<guid isPermaLink="false">http://www.principlespatternsandpractices.com/2008/06/24/ah-my-favorite-resource/</guid>
		<description><![CDATA[Just a brief one today, since my point is simple.  An email came in this morning with a link to a section of Martin Fowler&#8217;s Catalog of Patterns of Enterprise Application Architecture and when I saw it, I got butterflies in my stomach.
The catalog includes brief summaries of many important object-oriented design patterns with some [...]]]></description>
			<content:encoded><![CDATA[<p>Just a brief one today, since my point is simple.  An email came in this morning with a link to a section of Martin Fowler&#8217;s <a href="http://martinfowler.com/eaaCatalog/" onclick="javascript:pageTracker._trackPageview('/outbound/article/martinfowler.com');">Catalog of Patterns of Enterprise Application Architecture</a> and when I saw it, I got butterflies in my stomach.</p>
<p>The catalog includes brief summaries of many important object-oriented design patterns with some accompanying UML class and sequence diagrams.</p>
<p>I&#8217;m notorious for being long winded, but you may be surprised to discover that I absolutely adore brevity.  Martin&#8217;s catalog of design pattern summaries is probably my favorite software engineering resource online.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.principlespatternsandpractices.com/2008/06/24/ah-my-favorite-resource/feed/</wfw:commentRss>
		</item>
		<item>
		<title>php&#124;tek 2008 Recap</title>
		<link>http://www.principlespatternsandpractices.com/2008/05/28/phptek-2008-recap/</link>
		<comments>http://www.principlespatternsandpractices.com/2008/05/28/phptek-2008-recap/#comments</comments>
		<pubDate>Wed, 28 May 2008 13:00:42 +0000</pubDate>
		<dc:creator>andrew</dc:creator>
		
		<category><![CDATA[Uncategorized]]></category>

		<category><![CDATA[conference]]></category>

		<category><![CDATA[php]]></category>

		<category><![CDATA[phptek]]></category>

		<category><![CDATA[tek08]]></category>

		<guid isPermaLink="false">http://www.principlespatternsandpractices.com/2008/05/28/phptek-2008-recap/</guid>
		<description><![CDATA[What a great week.
I had the opportunity to meet a lot of people with whom I shared a common perspective on the development of software.  Some of them stretched what I expect from myself as a developer and have helped me set new goals.  Even though I only came knowing one person at the conference, [...]]]></description>
			<content:encoded><![CDATA[<p>What a great week.</p>
<p>I had the opportunity to meet a lot of people with whom I shared a common perspective on the development of software.  Some of them stretched what I expect from myself as a developer and have helped me set new goals.  Even though I only came knowing one person at the conference, it never felt like networking.  It always felt like socializing.</p>
<p>One of my largest take-aways for the week was a general sense for the direction and increasing maturity of the PHP development community.</p>
<p>The community at php|tek is definitely a skewed sample of the PHP community as a whole.  For one example, I&#8217;d venture a guess that you&#8217;ve got a higher concentration of developers who are considered leaders in the general PHP community.  But that also makes it a great opportunity to observe trends in what principles, practices, and patterns of software development are being promoted.</p>
<p>Just to name a few of the great practices I heard being promoted:</p>
<ul>
<li>habitual automated testing</li>
<li>scalable software architecture</li>
<li>good object-oriented design</li>
<li>accessibility and usability</li>
<li>sane project management</li>
</ul>
<p>A lot of the voices promoting these things can be heard in other channels such as magazines or books.  But seeing the sessions covering these topics drawing so many attendees and filling up the rooms leaves me optimistic about the actual interest from the community.</p>
<p>So, I arrived unsure about the PHP community.  I departed saying, &#8220;Count me in.&#8221;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.principlespatternsandpractices.com/2008/05/28/phptek-2008-recap/feed/</wfw:commentRss>
		</item>
		<item>
		<title>A Week in Chicago</title>
		<link>http://www.principlespatternsandpractices.com/2008/05/19/a-week-in-chicago/</link>
		<comments>http://www.principlespatternsandpractices.com/2008/05/19/a-week-in-chicago/#comments</comments>
		<pubDate>Tue, 20 May 2008 03:55:14 +0000</pubDate>
		<dc:creator>andrew</dc:creator>
		
		<category><![CDATA[Uncategorized]]></category>

		<category><![CDATA[conference]]></category>

		<category><![CDATA[nice hotel room]]></category>

		<category><![CDATA[php]]></category>

		<category><![CDATA[phptek]]></category>

		<guid isPermaLink="false">http://www.principlespatternsandpractices.com/2008/05/19/a-week-in-chicago/</guid>
		<description><![CDATA[So, I&#8217;m in Chicago for the remainder of the week attending php&#124;tek 2008.  The conference is both business and pleasure, since work is paying my way but being here is significantly interesting on a personal level.  I&#8217;ve really enjoyed developing in PHP even since that first project in which I was forced to [...]]]></description>
			<content:encoded><![CDATA[<p>So, I&#8217;m in Chicago for the remainder of the week attending <a href="http://tek.phparch.com/" onclick="javascript:pageTracker._trackPageview('/outbound/article/tek.phparch.com');">php|tek 2008</a>.  The conference is both business and pleasure, since work is paying my way but being here is significantly interesting on a personal level.  I&#8217;ve really enjoyed developing in PHP even since that first project in which I was forced to work with it, but I&#8217;m terribly out of touch with the PHP community in general.  There is so much noise out there, and when you&#8217;ve already got a small team of developers that you enjoy interacting with, it&#8217;s easy to stop searching for the signals out there.</p>
<p>That being said, I honestly believe that it&#8217;s a short-sighted snare that sells short both the individual and the team they serve on.  That&#8217;s part of why I&#8217;m here.  I&#8217;m sure there will be some noise, but I&#8217;m hoping for some solid signal in there too.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.principlespatternsandpractices.com/2008/05/19/a-week-in-chicago/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Biblical Proverbs for Software Development</title>
		<link>http://www.principlespatternsandpractices.com/2008/04/09/biblical-proverbs-for-software-development/</link>
		<comments>http://www.principlespatternsandpractices.com/2008/04/09/biblical-proverbs-for-software-development/#comments</comments>
		<pubDate>Wed, 09 Apr 2008 12:01:41 +0000</pubDate>
		<dc:creator>andrew</dc:creator>
		
		<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.principlespatternsandpractices.com/2008/04/09/biblical-proverbs-for-software-development/</guid>
		<description><![CDATA[My wife and I read the Bible regularly and fairly systematically.  As we were reading the eighteenth chapter of Proverbs last night, the following stood out to me as being relevant in the context of software development and team dynamics.
A man who isolates himself seeks his own desire;
He rages against all wise judgment.
A fool [...]]]></description>
			<content:encoded><![CDATA[<p>My wife and I read the Bible regularly and <a href="http://www.christadelphia.org/chart.pdf" onclick="javascript:pageTracker._trackPageview('/outbound/article/www.christadelphia.org');">fairly systematically</a>.  As we were reading the eighteenth chapter of Proverbs last night, the following stood out to me as being relevant in the context of software development and team dynamics.</p>
<blockquote><p>A man who isolates himself seeks his own desire;<br />
He rages against all wise judgment.</p></blockquote>
<blockquote><p>A fool has no delight in understanding,<br />
But in expressing his own heart.</p></blockquote>
<blockquote><p>The words of a man’s mouth are deep waters;<br />
The wellspring of wisdom is a flowing brook.</p></blockquote>
<blockquote><p>He who is slothful in his work<br />
Is a brother to him who is a great destroyer.</p></blockquote>
<blockquote><p>He who answers a matter before he hears it,<br />
It is folly and shame to him.</p></blockquote>
<blockquote><p>The first one to plead his cause seems right,<br />
Until his neighbor comes and examines him.</p></blockquote>
<p>These are just the tip of the ice berg.  I hope you enjoyed them. <img src='http://www.principlespatternsandpractices.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /></p>
]]></content:encoded>
			<wfw:commentRss>http://www.principlespatternsandpractices.com/2008/04/09/biblical-proverbs-for-software-development/feed/</wfw:commentRss>
		</item>
		<item>
		<title>PHP&#8217;s Output Buffer</title>
		<link>http://www.principlespatternsandpractices.com/2008/03/25/phps-output-buffer/</link>
		<comments>http://www.principlespatternsandpractices.com/2008/03/25/phps-output-buffer/#comments</comments>
		<pubDate>Tue, 25 Mar 2008 16:14:34 +0000</pubDate>
		<dc:creator>andrew</dc:creator>
		
		<category><![CDATA[Uncategorized]]></category>

		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://www.principlespatternsandpractices.com/2008/03/25/phps-output-buffer/</guid>
		<description><![CDATA[Are you familiar with PHP&#8217;s output buffering?  You should be.  If you already are, you can disregard this post.  
When we print, echo, provide inline HTML, etc., PHP&#8217;s default default behavior is to write to the standard output.  Typically that means the web browser or terminal you&#8217;re using to execute the [...]]]></description>
			<content:encoded><![CDATA[<p>Are you familiar with PHP&#8217;s output buffering?  You should be.  If you already are, you can disregard this post. <img src='http://www.principlespatternsandpractices.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>When we <code>print</code>, <code>echo</code>, provide inline HTML, etc., PHP&#8217;s default default behavior is to write to the <em>standard output</em>.  Typically that means the web browser or terminal you&#8217;re using to execute the script.  But this isn&#8217;t always ideal.  Sometimes we need to capture the output of one script for use in another script.  We want to <code>include</code> it, but instead of printing the results to a user, we would like to store them in a variable.  PHP&#8217;s output buffering allows us to do just that, using simple output control functions like <code>ob_start()</code>, <code>ob_get_contents()</code>, and <code>ob_end_clean()</code>.</p>
<div class="dean_ch" style="white-space: wrap;">
<ol>
<li class="li1">
<div class="de1"><span class="co1">// Turn on output buffering.</span></div>
</li>
<li class="li1">
<div class="de1"><span class="kw3">ob_start</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="co1">// Execute a script.</span></div>
</li>
<li class="li2">
<div class="de2"><span class="co1">// Results go into the output buffer instead of the standard output.</span></div>
</li>
<li class="li1">
<div class="de1"><span class="kw1">include</span><span class="br0">&#40;</span><span class="st0">&#8216;template.php&#8217;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="co1">// Return the contents of the output buffer.</span></div>
</li>
<li class="li1">
<div class="de1"><span class="re0">$html</span> = <span class="kw3">ob_get_contents</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li2">
<div class="de2">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="co1">// Clean the output buffer and turn off output buffering.</span></div>
</li>
<li class="li1">
<div class="de1"><span class="kw3">ob_end_clean</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;</div>
</li>
</ol>
</div>
<p>Using these functions to capture the output of a presentational template is just one real-world example.  Understanding it is one step toward adding a familiarity with output buffering and other output control functions to your personal PHP toolbox.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.principlespatternsandpractices.com/2008/03/25/phps-output-buffer/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Method Chaining</title>
		<link>http://www.principlespatternsandpractices.com/2008/03/19/method-chaining/</link>
		<comments>http://www.principlespatternsandpractices.com/2008/03/19/method-chaining/#comments</comments>
		<pubDate>Wed, 19 Mar 2008 17:28:52 +0000</pubDate>
		<dc:creator>andrew</dc:creator>
		
		<category><![CDATA[Uncategorized]]></category>

		<category><![CDATA[patterns]]></category>

		<guid isPermaLink="false">http://www.principlespatternsandpractices.com/2008/03/19/method-chaining/</guid>
		<description><![CDATA[Are you familiar with method chaining?  If not, the concept is very simple and you should at least understand enough to recognize when it&#8217;s being used. Consider the following example: 



$select = new Select&#40;&#41;;


$select-&#62;columns&#40;&#8216;id, name&#8217;&#41;-&#62;from&#40;&#8216;person&#8217;&#41;-&#62;where&#40;&#8216;age &#62; 25&#8242;&#41;;



 Why?  The purpose of the class author is to provide a fluid syntax and flexible interface [...]]]></description>
			<content:encoded><![CDATA[<p>Are you familiar with method chaining?  If not, the concept is very simple and you should at least understand enough to recognize when it&#8217;s being used. Consider the following example: </p>
<div class="dean_ch" style="white-space: wrap;">
<ol>
<li class="li1">
<div class="de1"><span class="re0">$select</span> = <span class="kw2">new</span> Select<span class="br0">&#40;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1"><span class="re0">$select</span>-&gt;<span class="me1">columns</span><span class="br0">&#40;</span><span class="st0">&#8216;id, name&#8217;</span><span class="br0">&#41;</span>-&gt;<span class="me1">from</span><span class="br0">&#40;</span><span class="st0">&#8216;person&#8217;</span><span class="br0">&#41;</span>-&gt;<span class="me1">where</span><span class="br0">&#40;</span><span class="st0">&#8216;age &gt; 25&#8242;</span><span class="br0">&#41;</span>;</div>
</li>
</ol>
</div>
<p> <strong>Why?</strong>  The purpose of the class author is to provide a fluid syntax and flexible interface for configuring an object.
</p>
<p> <strong>How?</strong>  None of these methods would have previously returned any meaningful information about the operation performed, so the class author has returned <code>$this</code> instead.  By returning <code>$this</code>, any additional method call will continue to target the same object.  You can also use regular methods that do return meaningful information in a method chain, but they terminate the chain by returning something other than <code>$this</code>.
</p>
<p> What I haven&#8217;t covered in this extremely brief introduction are the design considerations that exist when designing a class that provides chaining syntax.  Why not make all mutator methods support method chaining (ie. <code>$person-&gt;setName('Andrew')-&gt;setAge(25);</code>)?  That belongs to a group of more involved topics which have been covered <a href="http://martinfowler.com/dslwip/MethodChaining.html" onclick="javascript:pageTracker._trackPageview('/outbound/article/martinfowler.com');">elsewhere</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.principlespatternsandpractices.com/2008/03/19/method-chaining/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Consistency</title>
		<link>http://www.principlespatternsandpractices.com/2008/03/18/9/</link>
		<comments>http://www.principlespatternsandpractices.com/2008/03/18/9/#comments</comments>
		<pubDate>Tue, 18 Mar 2008 18:04:26 +0000</pubDate>
		<dc:creator>andrew</dc:creator>
		
		<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.principlespatternsandpractices.com/2008/03/18/9/</guid>
		<description><![CDATA[While a single complex accomplishment may earn my praise, simple expectations met with consistency will earn my trust.
]]></description>
			<content:encoded><![CDATA[<p>While a single complex accomplishment may earn my praise, simple expectations met with consistency will earn my trust.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.principlespatternsandpractices.com/2008/03/18/9/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Statements and Evaluations</title>
		<link>http://www.principlespatternsandpractices.com/2008/03/11/statements-and-evaluations/</link>
		<comments>http://www.principlespatternsandpractices.com/2008/03/11/statements-and-evaluations/#comments</comments>
		<pubDate>Tue, 11 Mar 2008 21:08:59 +0000</pubDate>
		<dc:creator>andrew</dc:creator>
		
		<category><![CDATA[Uncategorized]]></category>

		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://www.principlespatternsandpractices.com/2008/03/11/statements-and-evaluations/</guid>
		<description><![CDATA[Introduction
How many evaluations take place on each of the following three statements?



class &#8230; &#123;


&#160;public function &#8230;&#40;&#41; &#123;


&#160; // Statement one.


&#160; $this-&#62;_name = $name;


&#160;


&#160; // Statement two.


&#160; $accounts = $this-&#62;_accounts-&#62;get&#40;$return&#41;;


&#160;


&#160; // Statement three.


&#160; $this-&#62;_replies = new Relationship_OneToMany&#40;&#8216;Email&#8217;,


&#160; &#160;Finder_Factory::create&#40;&#8216;Email&#8217;&#41;-&#62;findByParent&#40;$this&#41;,


&#160; &#160;$this-&#62;_replies&#41;;


&#160;&#125;


&#125;



If your answers for each statement were at least 3, 5, and 10, you are hereby dismissed for [...]]]></description>
			<content:encoded><![CDATA[<h3>Introduction</h3>
<p>How many evaluations take place on each of the following three statements?</p>
<div class="dean_ch" style="white-space: wrap;">
<ol>
<li class="li1">
<div class="de1"><span class="kw2">class</span> &#8230; <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;<span class="kw2">public</span> <span class="kw2">function</span> &#8230;<span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="co1">// Statement one.</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="re0">$this</span>-&gt;_name = <span class="re0">$name</span>;</div>
</li>
<li class="li2">
<div class="de2">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="co1">// Statement two.</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="re0">$accounts</span> = <span class="re0">$this</span>-&gt;_accounts-&gt;<span class="me1">get</span><span class="br0">&#40;</span><span class="re0">$return</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="co1">// Statement three.</span></div>
</li>
<li class="li2">
<div class="de2">&nbsp; <span class="re0">$this</span>-&gt;_replies = <span class="kw2">new</span> Relationship_OneToMany<span class="br0">&#40;</span><span class="st0">&#8216;Email&#8217;</span>,</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;Finder_Factory::<span class="me2">create</span><span class="br0">&#40;</span><span class="st0">&#8216;Email&#8217;</span><span class="br0">&#41;</span>-&gt;<span class="me1">findByParent</span><span class="br0">&#40;</span><span class="re0">$this</span><span class="br0">&#41;</span>,</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;<span class="re0">$this</span>-&gt;_replies<span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;<span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
</ol>
</div>
<p>If your answers for each statement were at least 3, 5, and 10, you are hereby dismissed for the remainder of the post.  If you (like most I&#8217;ve asked) answered 1 for the first statement, please stay awhile.  I suspect this post may aid you in becoming a stronger programmer.When we&#8217;re done, you should hopefully have a clear understanding of the terms:</p>
<ul>
<li>Statement</li>
<li>Evaluation</li>
</ul>
<h3>Statements and Evaluations</h3>
<p>You might think of a statement as a line of code with a semicolon at the end or the conditions we put in a <code>while</code> loop.  While that&#8217;s true, a more generic and granular definition would be to think of a statement as anything you can wrap parenthesis around and smack an <code>echo</code> in front of.  When you think of statements this way you realize that each line of code is often made up of many, many statements, all of which need to be evaluated individually in the process of evaluating the entire larger statement.So our first statement had one assignment.  That resulted in the following evaluations:</p>
<ul>
<li>The entire right hand side, which we&#8217;ll say was <code>$name</code> evaluating to a string.</li>
<li>The <code>$this</code> variable needed to evaluate to an instance of an object to set a property on.</li>
<li>Assignments don&#8217;t only assign the value, but also evaluate to whatever value was assigned.</li>
</ul>
<p>(Depending on your knowledge of the PHP engine you may be able to come up with a better number but I think those are sufficient for practical purposes.)</p>
<h3>Order of Evaluation</h3>
<p>Knowing the order in which these smaller statements are evaluated can also be helpful.A few rules might help:</p>
<ul>
<li>Statements are evaluated as they&#8217;re needed.</li>
<li>Function (or method) parameters are evaluated before a function is called.</li>
<li>Think of the <code>return</code> statement as the function saying &#8220;I&#8217;m done!  I evaluate to &#8230;&#8221;</li>
</ul>
<p>For example, consider our second statement:</p>
<ul>
<li>If we&#8217;re going to evaluate an assignment, we must first evaluate the right hand side.</li>
<li>If we&#8217;re going to evaluate the <code>get()</code> method, the <code>$this-&gt;_accounts</code> property must first evaluate to an object.</li>
<li>If we&#8217;re going to evaluate the <code>$this-&gt;_accounts</code> property, <code>$this</code> itself must first evaluate to an object.</li>
<li>Now we&#8217;ve got the object from the property but before we can evaluate the <code>get()</code> method, we must evaluate it&#8217;s parameter.</li>
<li>With that we can call the <code>get()</code> method which evaluates to an array.  (Its return value.)</li>
<li>We can finally perform the assignment which itself evaluates to whatever value was assigned.</li>
</ul>
<h3>Why Know It</h3>
<p>Consider our third statement.  Not only does it have many (10+) smaller evaluations going on, but the object-oriented syntax and execution can be a little daunting to the uninitiated.  But being armed with a solid understanding of the concepts we&#8217;ve covered will enable you to more easily jump into whatever code is thrown at you.  Rather than struggle with what seems like complicated syntax, you&#8217;ll be able to break it down, understand it, and debug it with greater ease.  It&#8217;s a precursor for recognizing the use of design patterns in another developers code. Do whatever it takes to understand how and in what order complex statements evaluate!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.principlespatternsandpractices.com/2008/03/11/statements-and-evaluations/feed/</wfw:commentRss>
		</item>
	</channel>
</rss>
