<?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>Professional PHP &#187; Software Design</title>
	<atom:link href="http://www.procata.com/blog/archives/category/software-design/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.procata.com/blog</link>
	<description>PHP Programming, Web Development, PHP Advocacy and PHP Best Practices.</description>
	<lastBuildDate>Tue, 20 Oct 2009 00:57:46 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.6</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Closures are coming to PHP</title>
		<link>http://www.procata.com/blog/archives/2009/03/22/closures-are-coming-to-php/</link>
		<comments>http://www.procata.com/blog/archives/2009/03/22/closures-are-coming-to-php/#comments</comments>
		<pubDate>Sun, 22 Mar 2009 22:09:16 +0000</pubDate>
		<dc:creator>Jeff</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Software Design]]></category>
		<category><![CDATA[closures]]></category>

		<guid isPermaLink="false">http://www.procata.com/blog/?p=293</guid>
		<description><![CDATA[Dagfinn has a post looking at using the new closure feature of PHP 5.3.  He compares using foreach for iteration versus array_map. &#8220;Interesting,&#8221; he concludes, &#8220;but not necessarily better than conventional alternatives.&#8221;
I agree for that case.  Consider instead, a more complicated operation that requires a setup and a tear down after.
&#160;
setup&#40;&#41;;
operation&#40;&#41;;
teardown&#40;&#41;;
&#160;
Now what happens [...]]]></description>
			<content:encoded><![CDATA[<p>Dagfinn has a <a href="http://blog.agilephp.com/2009/03/19/real-programming-with-php-53-part-1-array-processing/">post</a> looking at using the new closure feature of PHP 5.3.  He compares using foreach for iteration versus array_map. &#8220;Interesting,&#8221; he concludes, &#8220;but not necessarily better than conventional alternatives.&#8221;</p>
<p>I agree for that case.  Consider instead, a more complicated operation that requires a setup and a tear down after.<br />
<pre class="php">&nbsp;
setup<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
operation<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
teardown<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;</pre></p>
<p>Now what happens if we need to be able to customize operation?  That&#8217;s common enough, one way of doing this is to create a template method.</p>
<p><pre class="php">&nbsp;
<span style="color: #000000; font-weight: bold;">class</span> MyExample <span style="color: #66cc66;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">function</span> operation<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span><span style="color: #66cc66;">&#125;</span>
    <span style="color: #000000; font-weight: bold;">function</span> setup<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span><span style="color: #66cc66;">&#125;</span>
    <span style="color: #000000; font-weight: bold;">function</span> teardown<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span><span style="color: #66cc66;">&#125;</span>
    <span style="color: #000000; font-weight: bold;">function</span> doit<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
        <span style="color: #0000ff;">$this</span>-&gt;<span style="color: #006600;">setup</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
        <span style="color: #0000ff;">$this</span>-&gt;<span style="color: #006600;">operation</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
        <span style="color: #0000ff;">$this</span>-&gt;<span style="color: #006600;">teardown</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
    <span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span>
&nbsp;</pre></p>
<p>Now, we can subclass MyExample and override operation() with custom logic.  This is well and good, but what the customization we need is fairly small.  Creating a new class carries a certain weight.  Especially if you are religious about one class per file.  </p>
<p><pre class="php">&nbsp;
<span style="color: #000000; font-weight: bold;">class</span> MyExampleExtension <span style="color: #000000; font-weight: bold;">extends</span> MyExample <span style="color: #66cc66;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">function</span> operation<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
        <span style="color: #808080; font-style: italic;">// custom logic</span>
    <span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span>
&nbsp;</pre></p>
<p>Plus, you now have to deal with some creational patterns to make sure your custom class is used in the right context.</p>
<p><pre class="php">&nbsp;
<span style="color: #0000ff;">$myObject</span> = <span style="color: #0000ff;">$registery</span>-&gt;<span style="color: #006600;">get</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'MyExample'</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #0000ff;">$myObject</span>-&gt;<span style="color: #006600;">doit</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;</pre></p>
<p>So, instead of encapsulating the pattern, its also very common to just copy and paste:</p>
<p><pre class="php">&nbsp;
setup<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
custom_operation1<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
teardown<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #808080; font-style: italic;">//...</span>
setup<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
custom_operation2<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
teardown<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;</pre></p>
<p>But that&#8217;s not good on the duplicate code front.  So here is an alternate implementation, but using a <del datetime="2009-03-24T17:34:07+00:00">closure</del> anonymous function as a callback.</p>
<p><pre class="php">&nbsp;
<span style="color: #000000; font-weight: bold;">class</span> MyExample2 <span style="color: #66cc66;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">function</span> setup<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span><span style="color: #66cc66;">&#125;</span>
    <span style="color: #000000; font-weight: bold;">function</span> teardown<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span><span style="color: #66cc66;">&#125;</span>
    <span style="color: #000000; font-weight: bold;">function</span> doit<span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$operation</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
        <span style="color: #0000ff;">$this</span>-&gt;<span style="color: #006600;">setup</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
        <span style="color: #0000ff;">$operation</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
        <span style="color: #0000ff;">$this</span>-&gt;<span style="color: #006600;">teardown</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
    <span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span>
&nbsp;</pre></p>
<p>The advantage of MyExample2 is that extending is that the setup and teardown pattern is encapsulated in one spot.  You konw that if setup is called, teardown will also be called.  But, extending the operation is very light weight.</p>
<p><pre class="php">&nbsp;
<span style="color: #0000ff;">$myObject</span> = <span style="color: #000000; font-weight: bold;">new</span> MyExample2<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #0000ff;">$myObject</span>-&gt;<span style="color: #006600;">doIt</span><span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">function</span> <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span> <span style="color: #808080; font-style: italic;">/* custom logic 1 */</span> <span style="color: #66cc66;">&#125;</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #808080; font-style: italic;">// ...</span>
<span style="color: #0000ff;">$myObject</span>-&gt;<span style="color: #006600;">doIt</span><span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">function</span> <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span> <span style="color: #808080; font-style: italic;">/* custom logic 2 */</span> <span style="color: #66cc66;">&#125;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;</pre></p>
<p>There is  another significant benefit to this and that is locality of reference.  Here, the custom1 logic and the custom2 logic appears in context, not far away in some custom class or function declaration.  So you get encapsulation and reuse for the common code parts, but without the sprawl and overhead of declaring structures that will only be used once in a context far away their declaration.</p>
<p>Closures and anonymous functions decrease the activation energy to write good code.</p>
<p>That&#8217;s not to say that closures and anonymous functions can&#8217;t be abused.  If you keep seeing the same logic over and over in an anonymous block, you should probably give it a name in the form of a class, method or function.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.procata.com/blog/archives/2009/03/22/closures-are-coming-to-php/feed/</wfw:commentRss>
		<slash:comments>15</slash:comments>
		</item>
		<item>
		<title>php &#124; tek Wrapup</title>
		<link>http://www.procata.com/blog/archives/2008/05/26/php-tek-wrapup/</link>
		<comments>http://www.procata.com/blog/archives/2008/05/26/php-tek-wrapup/#comments</comments>
		<pubDate>Tue, 27 May 2008 05:57:30 +0000</pubDate>
		<dc:creator>Jeff</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Software Design]]></category>
		<category><![CDATA[books]]></category>
		<category><![CDATA[phptek]]></category>
		<category><![CDATA[talks]]></category>

		<guid isPermaLink="false">http://www.procata.com/blog/?p=290</guid>
		<description><![CDATA[I really enjoyed myself at this year&#8217;s php &#124; tek.  The conference seemed even better than last year.  Here are the slides from my talks&#8230;

Exceptional PHP
Coding for Success: Writing Software You’ll Be Able To Understand Next Month

Here are some of the books I mentioned&#8230;

Refactoring: Improving the Design of Existing Code
php&#124;architect&#8217;s Guide to PHP [...]]]></description>
			<content:encoded><![CDATA[<p>I really enjoyed myself at this year&#8217;s php | tek.  The conference seemed even better than last year.  Here are the slides from my talks&#8230;</p>
<ul>
<li><a href="http://www.procata.com/talks/phptek-may2008-exceptional.pdf">Exceptional PHP</a></li>
<li><a href="http://www.procata.com/talks/phptek-may2008-maintainable.pdf">Coding for Success: Writing Software You’ll Be Able To Understand Next Month</a></li>
</ul>
<p>Here are some of the books I mentioned&#8230;</p>
<ul>
<li><a href="http://www.amazon.com/Refactoring-Improving-Existing-Addison-Wesley-Technology/dp/0201485672/ref=pd_bbs_sr_1?ie=UTF8&#038;s=books&#038;qid=1211867585&#038;sr=1-1">Refactoring: Improving the Design of Existing Code</a></li>
<li><a href="http://www.phparch.com/c/books/id/0973589825">php|architect&#8217;s Guide to PHP Design Patterns</a></li>
<li><a href="http://www.amazon.com/PHP-Action-Objects-Design-Agility/dp/1932394753/ref=pd_bbs_sr_1?ie=UTF8&#038;s=books&#038;qid=1211867300&#038;sr=1-1">PHP in Action: Objects, Design, Agility</a></li>
<li><a href="http://www.amazon.com/Design-Patterns-Object-Oriented-Addison-Wesley-Professional/dp/0201633612/ref=pd_bbs_sr_1?ie=UTF8&#038;s=books&#038;qid=1211867382&#038;sr=1-1">Design Patterns: Elements of Reusable Object-Oriented Software</a></li>
<li><a href="http://www.amazon.com/Implementation-Patterns-Addison-Wesley-Signature-Kent/dp/0321413091/ref=pd_bbs_sr_1?ie=UTF8&#038;s=books&#038;qid=1211867430&#038;sr=1-1">Implementation Patterns</a></li>
<li><a href="http://www.amazon.com/Fundamentals-Object-Oriented-Design-Addison-Wesley-Technology/dp/020169946X/ref=sr_1_1?ie=UTF8&#038;s=books&#038;qid=1211867490&#038;sr=1-1">Fundamentals of Object-Oriented Design in UML</a></li>
</ul>
<p>I&#8217;m already looking forward to next year.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.procata.com/blog/archives/2008/05/26/php-tek-wrapup/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>Benchmarking PHP&#8217;s Magic Methods</title>
		<link>http://www.procata.com/blog/archives/2007/11/04/benchmarking-phps-magic-methods/</link>
		<comments>http://www.procata.com/blog/archives/2007/11/04/benchmarking-phps-magic-methods/#comments</comments>
		<pubDate>Mon, 05 Nov 2007 00:01:02 +0000</pubDate>
		<dc:creator>Jeff</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Software Design]]></category>
		<category><![CDATA[benchmarks]]></category>
		<category><![CDATA[performance-optimization]]></category>
		<category><![CDATA[profiling]]></category>

		<guid isPermaLink="false">http://www.procata.com/blog/archives/2007/11/04/benchmarking-phps-magic-methods/</guid>
		<description><![CDATA[Larry Garfield has an interesting set of benchmarks covering many of PHP&#8217;s magic methods.  His results correspond pretty well to my own benchmarks in the area.  The thing to take away is that its not necessarily the overhead of the magic methods, but rather what you do inside them.  Its hard to [...]]]></description>
			<content:encoded><![CDATA[<p>Larry Garfield has an interesting <a href="http://www.garfieldtech.com/blog/magic-benchmarks">set of benchmarks</a> covering many of PHP&#8217;s <a href="http://php.net/oop5.magic">magic methods</a>.  His results correspond pretty well to my own benchmarks in the area.  The thing to take away is that its not necessarily the overhead of the magic methods, but rather what you do inside them.  Its hard to do anything useful inside a magic method, such as __get or __call that isn&#8217;t <b>10 to 20 times slower</b> than the &#8220;non-magic&#8221; solution.</p>
<p>There are probably more than a few naive programmers who would read results like this and start to avoid these constructs in their own code for performance reasons.  These are the same kinds of people obsessing over a few single or double quotes, who eschew &#8220;slow&#8221; objects in favor of switch statements that are many times slower than the polymorphic method calls they are trying to avoid.</p>
<p>But, that&#8217;s not the end of the story.  Larry ran his benchmarks using 2,000,000 iterations.  The <b>N</b> really matters here.  Sure, iterators are slower than arrays, but you aren&#8217;t going to be iterating over two million things.  I tend to fetch my database records in lots of 25 or 50.  You aren&#8217;t going to be making two million invocations of __call.  But how many will you make?  Under what value of N does the performance of these techniques cease to matter?  Is it ten, one hundred, one thousand, or ten thousand?  You may be surprised at how few calls your program actually does and how little impact it has on performance.</p>
<p>As <a href="http://netevil.org/">Wez</a> and <a href="http://www.travisswicegood.com/">Travis</a> point out in their comments, profiling is the way to find out the potential impact and to discover your true N.</p>
<p>Paul M. Jones has a <a href="http://paul-m-jones.com/blog/?p=182">good example</a> of what I&#8217;m talking about.  There, call_user_func_array appears to be a bottleneck, but it turns out that its the function being called, htmlspecialchars, not the calling process that consumes the balance of the time.  In that case, the function was &#8220;only&#8221; called 300 times.  I find that order of magnitude to be fairly typical.  Something to be aware of, perhaps, but not something to obsess over.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.procata.com/blog/archives/2007/11/04/benchmarking-phps-magic-methods/feed/</wfw:commentRss>
		<slash:comments>13</slash:comments>
		</item>
		<item>
		<title>The Endpoints of the Scale of Stupidity on Video</title>
		<link>http://www.procata.com/blog/archives/2007/11/02/the-endpoints-of-the-scale-of-stupidity-on-video/</link>
		<comments>http://www.procata.com/blog/archives/2007/11/02/the-endpoints-of-the-scale-of-stupidity-on-video/#comments</comments>
		<pubDate>Fri, 02 Nov 2007 20:55:22 +0000</pubDate>
		<dc:creator>Jeff</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Software Design]]></category>
		<category><![CDATA[oop]]></category>

		<guid isPermaLink="false">http://www.procata.com/blog/archives/2007/11/02/the-endpoints-of-the-scale-of-stupidity-on-video/</guid>
		<description><![CDATA[A quote from Cal Henderson (via simonwillison) presents a &#8220;Web Application Scale of Stupidity:&#8221;

&#124; OGF (One Giant Function) ---- Sanity ---- OOP (Object Oriented Programming) &#124;

The scale that Cal is talking about is actually better known as modularity:

&#124; Few large modules ----  Sanity? ---- Many Small Modules &#124;

If you haven&#8217;t listened to Alan Kay [...]]]></description>
			<content:encoded><![CDATA[<p>A quote from Cal Henderson (via <a href="http://simonwillison.net/2007/Nov/2/cal/">simonwillison</a>) presents a &#8220;Web Application Scale of Stupidity:&#8221;<br />
<code><br />
| OGF (One Giant Function) ---- Sanity ---- OOP (Object Oriented Programming) |<br />
</code></p>
<p>The scale that Cal is talking about is actually better known as <a href="http://sunnyday.mit.edu/16.355/parnas-criteria.html">modularity</a>:</p>
<p><code><br />
| Few large modules ----  Sanity? ---- Many Small Modules |<br />
</code></p>
<p>If you haven&#8217;t listened to Alan Kay talk about the benefits of many small modules, you should do so now.  Alan Kay coined the term Object Oriented.  Love OO or hate OO, if you have an opinion on it, you should know what he was thinking.  Hint, it wasn&#8217;t C++.</p>
<p><embed style="width:400px; height:326px;" id="VideoPlayback" type="application/x-shockwave-flash" src="http://video.google.com/googleplayer.swf?docId=-2950949730059754521&#038;hl=en" flashvars=""> </embed></p>
<p>On the other end of the scale, One Giant Function is generally known as <a href="http://www.laputan.org/pub/foote/mud.pdf">Big ball of Mud</a>(PDF)  Here is Brian Foote&#8217;s presentation on the paper (read the paper first).</p>
<p><embed style="width:400px; height:326px;" id="VideoPlayback" type="application/x-shockwave-flash" src="http://video.google.com/googleplayer.swf?docId=8693679271218408739&#038;hl=en" flashvars=""> </embed></p>
]]></content:encoded>
			<wfw:commentRss>http://www.procata.com/blog/archives/2007/11/02/the-endpoints-of-the-scale-of-stupidity-on-video/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Let Your Properties be Properties</title>
		<link>http://www.procata.com/blog/archives/2007/05/08/let-your-properties-be-properties/</link>
		<comments>http://www.procata.com/blog/archives/2007/05/08/let-your-properties-be-properties/#comments</comments>
		<pubDate>Tue, 08 May 2007 17:41:51 +0000</pubDate>
		<dc:creator>Jeff</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Software Design]]></category>
		<category><![CDATA[php-patterns]]></category>
		<category><![CDATA[properties]]></category>
		<category><![CDATA[refactoring]]></category>

		<guid isPermaLink="false">http://www.procata.com/blog/archives/2007/05/08/let-your-properties-be-properties/</guid>
		<description><![CDATA[There is a coding pattern that I see (and have used) in PHP code that defines generic methods on a class for setting and getting properties.
&#160;
function set&#40;$name, $value&#41;;
function get&#40;$name&#41;;
&#160;Google code search for examples
Some times there are some ancillary methods to deal with unsetting, checking for existence, setting via an array, or dealing with references in [...]]]></description>
			<content:encoded><![CDATA[<p>There is a coding pattern that I see (and have used) in PHP code that defines generic methods on a class for setting and getting properties.<br />
<pre class="php">&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> set<span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$name</span>, <span style="color: #0000ff;">$value</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #000000; font-weight: bold;">function</span> get<span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$name</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;</pre><a href="http://www.google.com/codesearch?hl=en&#038;lr=&#038;q=lang%3Aphp+function%5Cs%2Bset%5Cw*%5Cs*%5C%28%5Cs*%5C%24name%5Cs*%2C%5Cs*%26%3F%5Cs*%5C%24value%5Cs*%5C%29&#038;btnG=Search">Google code search for examples</a></p>
<p>Some times there are some ancillary methods to deal with unsetting, checking for existence, setting via an array, or dealing with references in PHP 4.  They can really clutter up the definition of a class.  That&#8217;s not good.  All this code is fairly standard, too, but it gets duplicated on every class that does this.  That&#8217;s not good, either.</p>
<p>Oh, I&#8217;ll solve this problem by making a base class, some may say.  Wrong.  This a very feeble reason to spend your one shot at inheritance.  Trust me, I know, I&#8217;ve done it.</p>
<p>I think the idea is to make the class extensible.  But PHP is really ok with just setting new properties on a class.<br />
<pre class="php">&nbsp;
<span style="color: #0000ff;">$obj</span>-&gt;<span style="color: #006600;">foo</span> = <span style="color: #ff0000;">'bar'</span>;
&nbsp;</pre><br />
So why not just do this?</p>
<p>Another variation of this pattern is to use setXXX($name, $value) or setYYY($name, $value) methods.  This happens alot with &#8220;options&#8221; or &#8220;vars&#8221; or &#8220;properties.&#8221;  It also happens on request wrapper classes.  To me this looks like there is an object here just begging to get out for each XXX and YYY.<br />
<pre class="php">&nbsp;
<span style="color: #0000ff;">$obj</span>-&gt;<span style="color: #006600;">xxx</span>-&gt;<span style="color: #006600;">prop</span> = <span style="color: #ff0000;">'foo'</span>;
<span style="color: #0000ff;">$obj</span>-&gt;<span style="color: #006600;">yyy</span>-&gt;<span style="color: #006600;">prop</span> = <span style="color: #ff0000;">'foo'</span>;
<span style="color: #0000ff;">$obj</span>-&gt;<span style="color: #006600;">zzz</span>-&gt;<span style="color: #006600;">prop</span> = <span style="color: #ff0000;">'foo'</span>;
&nbsp;</pre><br />
This eliminates a slew of property manipulation methods and leaves the original class free to implement its true purpose.  Methods of the form getXXX($name) and setXXX($name, $value) should be the solution of last resort.  </p>
<p>Since I&#8217;ve started eliminating these in my own code in favor of direct properties, intermediate objects or __set and __get, I feel I&#8217;ve seen nothing but positive results.  Try it.  You may like it, too.  Let your properties be properties.</p>
<p><b>UPDATE:</b><br />
From reading the comments, I think there was some confusion about what I meant in this post.  I am not talking about using naked properties instead of accessor methods.  I&#8217;m not talking about accessor methods at all in this post.  A specific accessor method, such as<br />
<pre class="php"><span style="color: #0000ff;">$obj</span>-&gt;<span style="color: #006600;">getFoo</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span></pre><br />
where the name of the property is part of the method name is very different than<br />
<pre class="php"><span style="color: #0000ff;">$obj</span>-&gt;<span style="color: #006600;">get</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'foo'</span><span style="color: #66cc66;">&#41;</span>;</pre><br />
Where you pass the name of the property as a string parameter.  Its only the latter pattern, where the property name is an actual parameter to the method, that I am talking about in this post and that I think should generally be refactored.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.procata.com/blog/archives/2007/05/08/let-your-properties-be-properties/feed/</wfw:commentRss>
		<slash:comments>14</slash:comments>
		</item>
		<item>
		<title>On the Perils of Inline API Documentation</title>
		<link>http://www.procata.com/blog/archives/2007/04/13/on-the-perils-of-inline-api-documentation/</link>
		<comments>http://www.procata.com/blog/archives/2007/04/13/on-the-perils-of-inline-api-documentation/#comments</comments>
		<pubDate>Fri, 13 Apr 2007 15:55:26 +0000</pubDate>
		<dc:creator>Jeff</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Software Design]]></category>
		<category><![CDATA[api-design]]></category>
		<category><![CDATA[api-documentation]]></category>
		<category><![CDATA[docblocks]]></category>
		<category><![CDATA[phpdocumentor]]></category>

		<guid isPermaLink="false">http://www.procata.com/blog/archives/2007/04/13/on-the-perils-of-inline-api-documentation/</guid>
		<description><![CDATA[Travis Swicegood has a post questioning the value of the docblock.  I have a deep sympathy with this sentiment.
Even on projects with extensive generated documentation, I find that kind of documentation to be of extremely low value.  The problem with inline API documentation is that there is no sense of priority.  Developers [...]]]></description>
			<content:encoded><![CDATA[<p>Travis Swicegood has a post <a href="http://www.travisswicegood.com/index.php/2007/04/11/programming_languages_are_declarative">questioning the value of the docblock</a>.  I have a deep sympathy with this sentiment.</p>
<p>Even on projects with extensive generated documentation, I find that kind of documentation to be of extremely low value.  The problem with inline API documentation is that there is no sense of priority.  Developers are encouraged to document every element that can possibly be documented. Then, when the documentation is generated, there is no way to distinguish the important from noise.</p>
<p>Another problem is restating the obvious.  When a property or method really is well named, there may not be much more to say in the docblock.  But, the mechanics of docblocks invites the programmer to say it anyway.  So, you end up with comments like &#8220;$widget the widget.&#8221;</p>
<p>Duplication is also a significant problem.  If you inherit from a base class or you implement an interface, there is a tendency to copy and paste the doc block from the parent to the children.  This is an obvious maintenance problem.  In fact, this is one of the major problems with comments.  If comments restate what the code does, its a form of code duplication.  When the code is changed, it requires changes in the comments.  In this sense, comments make code harder to maintain.</p>
<p>Lately, I&#8217;ve been trying to curb the <a href="http://en.wikipedia.org/wiki/Attractive_nuisance_doctrine">attractive nuisance</a> aspect of docblock comments by replacing docblocks with comments like<br />
<pre class="php">&nbsp;
<span style="color: #808080; font-style: italic;">// Definition in parent</span>
&nbsp;</pre><br />
 or<br />
<pre class="php">&nbsp;
<span style="color: #808080; font-style: italic;">// docblock intentionally omitted.</span>
&nbsp;</pre><br />
It would be nice if there were standard abbreviations for things like these.  The idea being to eliminate the attractive nuisance of the commentable element by placing a comment there that is not a docblock, and then commenting only the elements where you have something to say.</p>
<p>Well, if docblocks are so bad, what is the alternative?  Well, I&#8217;ve tried a few, including using a wiki for API documentation.  Here is the problem.  If duplication between the comment and the code is created by inline documentation, that maintenance problem becomes significantly worse with distance.  If the documentation is external to the code, that distance really harms the ability to keep the documentation in sync with the code.  So, docblocks are bad, but everything else is worse.</p>
<p>Docblocks were popularized by Sun and Java (or maybe Donald Knuth).  But when sun was documenting their Java APIs with docblocks, they had a professional documentation team to do the work.  When teams that don&#8217;t have a dedicated documenter role use these tools, I think they fall short.</p>
<p>So what is the solution?  I&#8217;d like to see better techniques and conventions for solving the problems of docblocks: avoiding duplication, avoiding restating the obvious, and avoiding the tendency to docblock everything thats docblockable.  Maybe there are more successful documenters out there who are handling these API documentation anti-patterns better than I am.  I&#8217;d sure like to hear how.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.procata.com/blog/archives/2007/04/13/on-the-perils-of-inline-api-documentation/feed/</wfw:commentRss>
		<slash:comments>13</slash:comments>
		</item>
		<item>
		<title>Software Development Team Diversity</title>
		<link>http://www.procata.com/blog/archives/2007/03/26/software-development-team-diversity/</link>
		<comments>http://www.procata.com/blog/archives/2007/03/26/software-development-team-diversity/#comments</comments>
		<pubDate>Mon, 26 Mar 2007 14:00:24 +0000</pubDate>
		<dc:creator>Jeff</dc:creator>
				<category><![CDATA[Agile Methods]]></category>
		<category><![CDATA[Software Design]]></category>
		<category><![CDATA[agile-php]]></category>
		<category><![CDATA[extreme-programming]]></category>
		<category><![CDATA[hiring]]></category>
		<category><![CDATA[programmer-education]]></category>
		<category><![CDATA[programming]]></category>

		<guid isPermaLink="false">http://www.procata.com/blog/archives/2007/03/26/software-development-team-diversity/</guid>
		<description><![CDATA[Matt Mullenweg has a post about Hiring Diversity.    A successful software project must fulfill many competing goals and factors and meet a wide variety of challenges.   Diversity is the combined arms of software development.  In my personal experience, the diverse team performs better.  A diverse team allows the [...]]]></description>
			<content:encoded><![CDATA[<p>Matt Mullenweg has a post about <a href="http://photomatt.net/2007/03/24/kapor-vs-zuckerberg/">Hiring Diversity</a>.    A successful software project must fulfill many competing goals and factors and meet a wide variety of challenges.   Diversity is the combined arms of software development.  In my personal experience, the diverse team performs better.  A diverse team allows the most appropriate team member to step up to a challenge.  The interaction between team members with different points of view helps a project balance competing goals.</p>
<h3>Technical Background</h3>
<p>A team needs members with a technical background.  These guys are the ones that ensure everything works.  They can write the hard bits of code, keep everything performing and make sure the code is maintainable.  Without these guys, you will have problems.  On the other hand, sometimes those with a technical background view problems solving as a puzzle, where the solution is the end in itself.<br />
In my experience, team members with a less technical background are more empathic toward the user community.  They view problem solving as a means to a goal.  A customer focus is what makes a project successful.  Software can be successful despite technical problems, but it cannot be successful if doesn&#8217;t meet the customer&#8217;s needs.  Having some non-technical people helps prevent your resident technocrats from building a system that will service 10,000 concurrent users, but doesn&#8217;t meet the needs of the 329 users you have today.<br />
Perhaps at the extreme end of this spectrum is the extreme programming practice of including a customer on the development team.</p>
<h3>Experience</h3>
<p>In <a href="http://www.procata.com/blog/archives/2005/05/10/expert-programmers/">expert versus novice programmers</a>, I make the distinction between skill level and experience.  Age, skill and experience often correlate, but not always.  Your young apprentice programmers are important to have on a team.  They can react faster.  Sometimes not knowing better is a bonus.  They&#8217;ll do things more senior team members don&#8217;t want to do.  They do things they&#8217;re not supposed to do, sometimes for the benefit of the team.<br />
I think people underestimate how long it takes to actually become an expert, as I mention in my previous post.  But, then they also underestimate how similar all software projects are.  They also overestimate the impact of their toolset.  Generally the technologies in the laundry lists that form most job listings are not the critical success factors for that project.<br />
People want a programmer with who can hit the ground running, who is familiar with all of the teams tools, languages and libraries.  But, this is a monoculture as well.  Sometimes you need people who aren&#8217;t from your toolset culture to point out where you have swallowed the hook too deeply or to introduce new tools and techniques from their alternate background.  Sometimes their learning process can teach you something.<br />
While some experience is valued in programmers, age sometimes isn&#8217;t.  However, you need the older, more stable people as well.  They keep the young ones from repeating the mistakes of the past.  They keep the project on an even keel.  It helps to have an older perspective on the team.  I think they help keep attention focused on what matters.  The tension between the older and younger team members helps keep the team on track.</p>
<h3>Traditional Diversity Factors</h3>
<p>I have no opinion on the impact of race.  I have an opinion about women on software teams.  I wish there were more of them.  I have worked on software development teams with diverse nationalities.  I regard that experience as positive.  Different cultures have different tolerances for risk, different respect for authority or tradition.  I think cultural diversity on a team is a good thing.</p>
<h3>Managing Diversity</h3>
<p>Over the years, there have been many methods proposed of matching people with the jobs they are best at.  The solution that works best is to ask them.  People gravitate toward the tasks that require their special skill sets.  Good team management means hiring diversely and allowing that migration.  On a well managed, diverse team, people will self select the jobs they are best at.  As a result, the diverse team is more resilient and I believe potentially more successful.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.procata.com/blog/archives/2007/03/26/software-development-team-diversity/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>The Problem with Markup Languages</title>
		<link>http://www.procata.com/blog/archives/2007/03/14/the-problem-with-markup-languages/</link>
		<comments>http://www.procata.com/blog/archives/2007/03/14/the-problem-with-markup-languages/#comments</comments>
		<pubDate>Wed, 14 Mar 2007 17:30:14 +0000</pubDate>
		<dc:creator>Jeff</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Software Design]]></category>
		<category><![CDATA[Usability]]></category>
		<category><![CDATA[html-markup]]></category>
		<category><![CDATA[input-filtering]]></category>
		<category><![CDATA[markup-languages]]></category>
		<category><![CDATA[regular-expressions]]></category>
		<category><![CDATA[security]]></category>
		<category><![CDATA[wiki-syntax]]></category>
		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://www.procata.com/blog/archives/2007/03/14/the-problem-with-markup-languages/</guid>
		<description><![CDATA[Chris Shiflett has a post today, Allowing HTML and Preventing XSS.  The problem is how to allow users to format their contributed content without introducing security vulnerabilities.  The answer is usually some sort of markup language or filtering and sanitization of HTML.
BBCODE was designed for this purpose.  There is no actual standard, [...]]]></description>
			<content:encoded><![CDATA[<p>Chris Shiflett has a post today, <a href="http://shiflett.org/blog/2007/mar/allowing-html-and-preventing-xss">Allowing HTML and Preventing XSS</a>.  The problem is how to allow users to format their contributed content without introducing security vulnerabilities.  The answer is usually some sort of markup language or filtering and sanitization of HTML.</p>
<p>BBCODE was designed for this purpose.  There is no actual standard, but the core syntax seems fairly uniform.  It&#8217;s good for those used to forums, where it seems to norm.</p>
<p>HTML markup is nice because it is a standard, even if varying subsets are supported.  Learning a little HTML isn&#8217;t going to hurt anyone, at least for the next 20 years or so.  The problem is that HTML was never intended to be hand edited.  The syntax is not the most inviting, and different HTML-like markup languages handle whitespace differently than the HTML standard.</p>
<p>Wiki markup syntaxes were designed to be human friendly. The main problem I have with wiki syntax is that there is no standard.  It seems like every wiki has a different way to formulate a link, for example.  I guess there is some progress with <a href="http://www.wikicreole.org/">Wiki Creole</a>, but I still have a bad taste in my mouth.</p>
<p>The other problem I have with wiki markup is that I find it to be non-deterministic.  When I edit any given wiki and try to use more than basic formatting, I never know what I am going to get.  Most of the markup processing engines for these wikis are impenetrable morasses of regular expressions.  It can be hard to gauge interactions.  Are you really sure they are secure?</p>
<p>Speaking of impenetrable morasses of regular expressions, have you ever looked at WordPress&#8217;s input path?  I&#8217;m sure every one with a WordPress blog who likes to blog about PHP code knows that it is a code eater.  I&#8217;ve been particularly disappointed with WordPress in this area.  Most the &#8220;code formatting&#8221; plugins still have problems protecting code from WordPress&#8217; heavy hand.</p>
<p>But the WordPress preg_replace gauntlet doesn&#8217;t just mangle code.  I have a post which has been sitting in draft mode for several weeks because I can&#8217;t figure out how to give it the proper markup.  WordPress is somehow taking my perfectly balanced input markup and producing &#8220;unbalanced&#8221; output markup.  I haven&#8217;t yet tracked down the problem to either submit a fix or to do a good bug report.  Frankly, I&#8217;m not looking forward to trudging through all those regular expressions.</p>
<p>In Chris&#8217; post, he takes the regular expression approach.  Folks in the comments have pointed out a few problems with his approach, including the problem of interleaved tags.  If you can&#8217;t tell by now, I am not a fan of the regular expression gauntlet approach to markup languages.  I prefer a defined syntax and a traditional computer science style parser (which may use regular expressions).</p>
<p>The other must-have is a preview option.  With so much variation in markup languages, not having a preview leaves the user to play Russian roulette with their submitted content.  I&#8217;ve talked about that before in the <a href="http://www.procata.com/blog/archives/2005/03/31/the-usability-of-input-filtering/">usability of input filtering</a>.  This is another area where WordPress leaves the user high and dry.  </p>
<p>The complex input path in WordPress combined with its reliance on global variables seems to leave it unable to do an in-page preview.  The admin area preview is an IFRAME so that it launches a separate request.  The various live preview plugins are JavaScript based and don&#8217;t work when it is disabled.  They also don&#8217;t pass the input through the same input path that WordPress uses, so they are not a true preview.</p>
<p>I don&#8217;t mean for this to be a WordPress rant, on the whole, I like WordPress.  Rather, I just wanted to point out how hard it can be to do good input filtering, that is safe, reliable, deterministic, and usable.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.procata.com/blog/archives/2007/03/14/the-problem-with-markup-languages/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
		<item>
		<title>Delphi for PHP</title>
		<link>http://www.procata.com/blog/archives/2007/02/23/delphi-for-php/</link>
		<comments>http://www.procata.com/blog/archives/2007/02/23/delphi-for-php/#comments</comments>
		<pubDate>Fri, 23 Feb 2007 18:55:39 +0000</pubDate>
		<dc:creator>Jeff</dc:creator>
				<category><![CDATA[Open Source]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Software Design]]></category>
		<category><![CDATA[delphi]]></category>
		<category><![CDATA[delphi-for-php]]></category>
		<category><![CDATA[delphi4php]]></category>
		<category><![CDATA[vcl]]></category>
		<category><![CDATA[vcl4php]]></category>

		<guid isPermaLink="false">http://www.procata.com/blog/archives/2007/02/23/delphi-for-php/</guid>
		<description><![CDATA[I have to comment on this week&#8217;s annoucement of Delphi for PHP.  I was a Delphi programmer for about 5 years before taking up PHP about 6 years ago.  What a convergence.
I have a great fondness and respect for the old Object Pascal based Delphi.  Delphi&#8217;s VCL has been influential, inspiring the [...]]]></description>
			<content:encoded><![CDATA[<p>I have to comment on this week&#8217;s annoucement of <a href="http://www.codegear.com/Products/Delphi/DelphiforPHP/tabid/237/Default.aspx">Delphi for PHP</a>.  I was a Delphi programmer for about 5 years before taking up PHP about 6 years ago.  What a convergence.</p>
<p>I have a great fondness and respect for the old Object Pascal based Delphi.  Delphi&#8217;s VCL has been influential, inspiring the GUI components in Java.  And, of course <a href="http://en.wikipedia.org/wiki/Anders_Hejlsberg">Ander Heijlsberg</a> went on to put a huge stamp on C# and .NET that would be familiar to any Delphi programmers.</p>
<p>I&#8217;ve always admired this approach of extending the language syntax to make common things easy and for the integration between the language and the tools. In Delphi, this was evidenced by the excellent properties support.  Six years later, this is the feature I miss the most in PHP.  This language extension approach has seen its culmination in C# and <a href="http://msdn2.microsoft.com/en-us/netframework/aa904594.aspx">LINQ</a>.  It almost pains me to say it, but the cutting edge of commercial language design is at Microsoft now.</p>
<p>On the other hand, I&#8217;ve never had that much respect for Borland as a company. We were big enough to have Borland representative&#8217;s come to our office and try sell us their products.  They were terrible at the mechanics of selling into big companies.  I was in their beta programs.  I went to their conferences.  I&#8217;ve never had any sense that they know what they are doing business wise.  Inprise?  What were they thinking?  Now here they are, just having gotten their asses kicked by eclipse in the Java IDE space and what are they working on?  They release an IDE for PHP, just as Zend is embracing Eclipse in the PHP space.  Brilliant!</p>
<p>I don&#8217;t quite know what Delphi means now.  To me, its always been and IDE plus Object Pascal.  What is it now? I also don&#8217;t quite know what Borland has become.  Is it <a href="http://www.codegear.com/">CodeGear</a> now?  I guess that the Delphi for PHP IDE comes from <a href="http://www.qadram.com/">Quadram</a> and their now discontinued QStudio product.  And the VCL is their WCL (no linkage found).  Anytime I&#8217;ve been touched by the corporate entity that was Borland, confusion ensued.  I&#8217;m confused now.</p>
<p>It appears that the <a href="http://sourceforge.net/projects/vcl4php">PHP version of the VCL</a> will be released on open source.  There is nothing at the sourceforge project, yet, but I&#8217;ll be interested to see what it looks like, if only for old times sake.</p>
<p>The Delphi tool approach was to serialize an object based representation of an application, then offer tools to create that serialized representation, and to load that representation at run time.  In Delphi, that serialization was done into the form files (.DFM).  I&#8217;ll be interested to see how Delphi for PHP does it.  Perhaps, this is an area where the <a href="http://www.zend.com/pdt">Eclipse PHP Development Tool</a> can learn. I know that I definitely had Delphi in mind when I was writing my column  on <a href="http://www.phparch.com/issue.php?mid=98">Object Serialization</a> for this month&#8217;s php | Architect.</p>
<p>Meanwhile, if you want to see the Delphi influence in PHP with code that you can download today, take a look at the <a href="http://www.xisc.com/">Prado</a> framework, which I imagine to be like the VCL for PHP, but without the supporting IDE.</p>
<p>This is a space I&#8217;ll definitely be watching.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.procata.com/blog/archives/2007/02/23/delphi-for-php/feed/</wfw:commentRss>
		<slash:comments>34</slash:comments>
		</item>
		<item>
		<title>OOP is Mature, not Dead</title>
		<link>http://www.procata.com/blog/archives/2007/01/07/oop-is-mature-not-dead/</link>
		<comments>http://www.procata.com/blog/archives/2007/01/07/oop-is-mature-not-dead/#comments</comments>
		<pubDate>Sun, 07 Jan 2007 20:51:16 +0000</pubDate>
		<dc:creator>Jeff</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Software Design]]></category>
		<category><![CDATA[closures]]></category>
		<category><![CDATA[late-static-binding]]></category>
		<category><![CDATA[object-oriented-programming]]></category>
		<category><![CDATA[oop]]></category>
		<category><![CDATA[properties]]></category>
		<category><![CDATA[uniform-access-principle]]></category>

		<guid isPermaLink="false">http://www.procata.com/blog/archives/2007/01/07/oop-is-mature-not-dead/</guid>
		<description><![CDATA[I ran across an interesting series of blog posts by Karsten Wagner claiming that OOP is dead (part 2 and part 3).  The premise behind these posts is that OOP has failed to deliver and that it is on the decline in favor of more functional or meta programming techniques.  Maybe its true [...]]]></description>
			<content:encoded><![CDATA[<p>I ran across an interesting series of blog posts by Karsten Wagner claiming that <a href="http://kawagner.blogspot.com/2006/08/oop-is-dead.html">OOP is dead</a> (<a href="http://kawagner.blogspot.com/2006/08/oop-is-dead-part-2.html">part 2</a> and <a href="http://kawagner.blogspot.com/2006/08/oop-is-dead-part-3.html">part 3</a>).  The premise behind these posts is that OOP has failed to deliver and that it is on the decline in favor of more functional or meta programming techniques.  Maybe its true that the discussion of the merits of OOP is on the decline.  At least if you read <a href="http://reddit.com/">reddit</a>.</p>
<p>However, OOP is not on the decline.  Quite simply, it has become mature.  The discussion may be on the decline because almost every language that anyone actually uses implements a core set of OOP features.  OOP has won its arguments.  Good luck taking a language mainstream without it.</p>
<p>Oh, yeah, there are some OOP features that are still controversial or unusual.  There is the single versus multiple inheritance debate, or perhaps Ruby&#8217;s open classes.  But, I think these things have a way of cross-pollinating across the popular languages when they make sense.</p>
<p>A good example of this cross-pollination is happening now with properties, accessor methods and the <a href="http://en.wikipedia.org/wiki/Uniform_access_principle">uniform access principle</a>.  Language support for declared accessor method is slowly creeping across all of the major languages.  Not that Objective C is all that popular, but <a href="http://developer.apple.com/leopard/overview/tools.html">Objective C 2.0</a> adds support for &#8216;em.  Even stodgy old Java is considering <a href="http://www.javalobby.org/java/forums/t88090.html">language level property support</a>.</p>
<p>Sadly, PHP does not yet have language support for declared properties with accessor methods.  What are <a href="http://us2.php.net/manual/en/language.oop5.overloading.php">__get and __set</a>?  They&#8217;re property missing handlers, not accessor methods.  You can simulate accessor methods with them, but that is a poor solution for most applications.  There is no way to support differing visibility, for example protected setters and public getters.  Property not found handlers are prohibitively verbose to write, have a poor performance profile, have no capability for reflection, cause interoperability problems, and have inheritance edge case gotchas (not present in the java beans model, for example).  My hope is to see good language support for properties in PHP 6.</p>
<p>Closures may not be object oriented, but they seem to be undergoing that same language cross-pollination.  Thats seems to be a pretty good sign that they are useful.  It doesn&#8217;t have to be closures OR objects, it can be closures AND objects.  We can use each when they make sense.</p>
<p>Closures are another wish list item for PHP 6.  PHP is almost wired for them with its <a href="http://us2.php.net/callback">callback</a> psuedo type.  Everywhere you can use a callback in PHP, you could use a closure.  I&#8217;d like to see the callback Pinocchio become a real boy like integer or boolean.  The cool thing is that with PHP&#8217;s weak typing the string and array forms of the callback pseudo-type can automatically be converted to a native closure type when needed.</p>
<p>As I said, the core OOP features that most programmers use are in all the mainstream languages.  The interesting part is how they handle the OOP edge cases.  This is the space where the framework developers live.  As I wrote in <a href="http://www.procata.com/blog/archives/2006/01/13/building-a-culture-of-objects-in-php/">culture of objects</a>, PHP has some problems here.  In some ways I think Ruby&#8217;s support for edge cases is exactly what allow a framework such as rails to be built in it, although, I&#8217;m not familiar enough with Ruby to say for certain.</p>
<p>I think addressing some of these issues in PHP 6 will make it a Ruby killer for web applications.  It isn&#8217;t necessary to be perfect here, just to be good enough and allow the larger community, distribution, and stability to take over.  Unfortunately, there is a long lead time here.  If PHP 6  were to add support for declared accessor methods, closures, and late static binding &#8212; my top three framework enablers &#8212; it would still be at least 2-3 years before PHP 6 was sufficiently deployed and the frameworks could adapt to the new features.</p>
<p>In the meantime, while the PHP culture may have problems, the Ruby culture may not be without its own problems.  The influx of <a href="http://www.randomhacks.net/articles/2005/12/03/why-ruby-is-an-acceptable-lisp">lisp</a> and smalltalk programmers, two languages that did not go &#8220;mainstream&#8221; may <a href="http://beust.com/weblog/archives/000382.html">prevent Ruby from going mainstream</a>.  Take a look at <a href="http://blog.lostlake.org/index.php?/archives/11-The-Impending-Ruby-Fracture.html">The impending ruby fracture</a>.  Isn&#8217;t this one of the things that happened to SmallTalk and Lisp?  I&#8217;m still not convinced that Ruby hasn&#8217;t inherited many of the same maintenance problems from its Perl heritage.  Just like english, huh?  Only time will reveal Ruby&#8217;s maintenance characteristics.  I give it about 2 to 3 years for today&#8217;s Rails systems to hit full legacy mode. How long do you think it will take for top notch unicode support in Ruby?</p>
<p>Obviously PHP 6 is all about teh unicode.  Including an opcode cache is going to be an important performance and adoption driver.  However, I&#8217;d like to see more progress on framework enablers.  I really want to see these in the next major PHP deployment cycle and not in the PHP 7 deployment cycle.  Are there framework enablers other than closures, declared property accessors and late static binding that I have overlooked?</p>
<p>I have high hopes for PHP 6 as a mature and mainstream language.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.procata.com/blog/archives/2007/01/07/oop-is-mature-not-dead/feed/</wfw:commentRss>
		<slash:comments>17</slash:comments>
		</item>
	</channel>
</rss>
