<?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>PHP in Action &#187; PHP</title>
	<atom:link href="http://blog.agilephp.com/category/php/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.agilephp.com</link>
	<description>Dagfinn Reiersøl on PHP, agile development, Ruby and other addictive substances</description>
	<lastBuildDate>Mon, 28 Sep 2009 14:35:32 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Bad code is good for you?</title>
		<link>http://blog.agilephp.com/2009/09/28/bad-code-is-good-for-you/</link>
		<comments>http://blog.agilephp.com/2009/09/28/bad-code-is-good-for-you/#comments</comments>
		<pubDate>Mon, 28 Sep 2009 12:08:43 +0000</pubDate>
		<dc:creator>dagfinn</dc:creator>
				<category><![CDATA[Application design]]></category>
		<category><![CDATA[Clean code]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Domain-Driven Design]]></category>
		<category><![CDATA[Open source]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://blog.agilephp.com/?p=1630</guid>
		<description><![CDATA[



Image by Balakov via Flickr



In The importance of bad code (or, WordPress and why I am a psychic), Marco Tabini proposes the idea that we need bad code. Or at least that we should be tolerant of bad code in open source projects because that invites participants that might otherwise not contribute.
This is an interesting [...]]]></description>
			<content:encoded><![CDATA[<div class="zemanta-img" style="margin: 1em; display: block;">
<div>
<dl class="wp-caption alignleft" style="width: 250px;">
<dt class="wp-caption-dt"><a href="http://www.flickr.com/photos/71447254@N00/1544234007"><img title="Spaghetti Code" src="http://farm3.static.flickr.com/2257/1544234007_dd7686d788_m.jpg" alt="Spaghetti Code" width="240" height="155" /></a></dt>
<dd class="wp-caption-dd zemanta-img-attribution" style="font-size: 0.8em;">Image by <a href="http://www.flickr.com/photos/71447254@N00/1544234007">Balakov</a> via Flickr</dd>
</dl>
</div>
</div>
<p>In <a href="http://mtabini.blogspot.com/2009/09/importance-of-bad-code-or-wordpress-and.html">The importance of bad code (or, WordPress and why I am a psychic)</a>, Marco Tabini proposes the idea that we <em>need</em> bad code. Or at least that we should be tolerant of bad code in open source projects because that invites participants that might otherwise not contribute.</p>
<p>This is an interesting idea that struck me as novel. But after thinking more about it, I believe it&#8217;s not a radical departure from what we&#8217;re all implicitly accepting, no matter how fanatical we might be about clean code.</p>
<p><span id="more-1630"></span></p>
<p><a class="zem_slink" title="Luke Welling" rel="wikipedia" href="http://en.wikipedia.org/wiki/Luke_Welling"> Luke Welling</a>&#8217;s comment to the blog post is particularly enlightening and worth quoting in full:</p>
<blockquote><p>I&#8217;d argue that bad code is often a sign and a side effect of a thriving, welcoming user community around a project.</p>
<p>The OSS projects with good code tend to have a relatively small group of committers doing nearly all the work. There is a big learning curve to<br />
working within the project&#8217;s (probably unwritten) architectural guidelines, and a big reputation curve that a new person has to climb<br />
to get their patches accepted.</p>
<p>Bad code is often a sign of welcoming new contributors, taking patches that do something useful even if the approach is ugly.</p>
<p>We  all know the problems bad code brings, but I would argue that some  projects are not just successful in spite of bad code, but successful  because they allow bad code.</p></blockquote>
<p>I commented:</p>
<blockquote><p>If  we&#8217;re looking for the optimal strategy (which is likely to depend a lot  on the specific project), the question may be what parts of the code  need to be held to high quality standards, and what parts don&#8217;t require such strictness. And how to separate the two. Security is one of the key issues, since bugs can hide in bad code, and some of those will be security bugs.</p></blockquote>
<p>Perhaps even more important is the question of whether and how to keep a clean separation between good and bad code. Bad code becomes a problem to me mainly when I need to maintain bad code written by others. Not that I dislike it so much; I sometimes enjoy cleaning up messes, but it slows me down. But if the person who wrote it is maintaining it, it doesn&#8217;t affect me much. So a clean separation would be helpful.</p>
<p>That also makes the whole issue clearer to me. Most of us use operating systems, library software and applications that aren&#8217;t necessarily up to our coding standards. Having lower code quality in parts of a project is not much different in principle. In fact, it may be less of a problem in some cases. When you a program library that has code of poor quality, the good code is dependent on that bad code. If you are programming the core of an open-source project and someone else is adding bad code in the form of an extension, the bad code is dependent on the good code, making it even less likely that the bad code can affect the good code.</p>
<p>In <a class="zem_slink" title="Domain-driven design" rel="wikipedia" href="http://en.wikipedia.org/wiki/Domain-driven_design">Domain-Driven Design</a>, there is a pattern called Anti-Corruption Layer which can be helpful in preventing the bad code from having an undue influence on the structure of the good code. It&#8217;s worth thinking about, especially when the bad code has an illogical and confusing API.</p>
<div class="zemanta-pixie" style="margin-top: 10px; height: 15px;"><a class="zemanta-pixie-a" title="Reblog this post [with Zemanta]" href="http://reblog.zemanta.com/zemified/eb6b55e2-85da-88bd-a263-dc329004c320/"><img class="zemanta-pixie-img" style="border: medium none; float: right;" src="http://img.zemanta.com/reblog_a.png?x-id=eb6b55e2-85da-88bd-a263-dc329004c320" alt="Reblog this post [with Zemanta]" /></a><span class="zem-script more-related pretty-attribution"><script src="http://static.zemanta.com/readside/loader.js" type="text/javascript"></script></span></div>
<p class="addtoany_share_save_container">
    <a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save?sitename=PHP%20in%20Action&amp;siteurl=http%3A%2F%2Fblog.agilephp.com%2F&amp;linkname=Bad%20code%20is%20good%20for%20you%3F&amp;linkurl=http%3A%2F%2Fblog.agilephp.com%2F2009%2F09%2F28%2Fbad-code-is-good-for-you%2F"><img src="http://blog.agilephp.com/wp-content/plugins/add-to-any/share_save_256_24.png" width="256" height="24" alt="Share/Save/Bookmark"/></a>

	</p>]]></content:encoded>
			<wfw:commentRss>http://blog.agilephp.com/2009/09/28/bad-code-is-good-for-you/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>Don&#8217;t refactor without unit tests</title>
		<link>http://blog.agilephp.com/2009/09/03/dont-refactor-without-unit-tests/</link>
		<comments>http://blog.agilephp.com/2009/09/03/dont-refactor-without-unit-tests/#comments</comments>
		<pubDate>Thu, 03 Sep 2009 13:56:49 +0000</pubDate>
		<dc:creator>dagfinn</dc:creator>
				<category><![CDATA[Clean code]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Refactoring]]></category>
		<category><![CDATA[Testing]]></category>
		<category><![CDATA[Unit testing]]></category>

		<guid isPermaLink="false">http://blog.agilephp.com/?p=1596</guid>
		<description><![CDATA[



Image by niallkennedy via Flickr



Brandon Savage is writing a series on code improvement using a code example (starting with Peer Review: Taking Code And Making It Better). In other words, it&#8217;s about refactoring, which is practically my favorite subject. Although I don&#8217;t agree with all of it, it&#8217;s mostly good advice. I recommend it.
That said, [...]]]></description>
			<content:encoded><![CDATA[<div class="zemanta-img" style="margin: 1em; display: block;">
<div>
<dl class="wp-caption alignleft" style="width: 250px;">
<dt class="wp-caption-dt"><a href="http://www.flickr.com/photos/35034351734@N01/330227455"><img title="Google &quot;Testing on the Toilet&quot;" src="http://farm1.static.flickr.com/155/330227455_738b83c72e_m.jpg" alt="Google &quot;Testing on the Toilet&quot;" width="240" height="79" /></a></dt>
<dd class="wp-caption-dd zemanta-img-attribution" style="font-size: 0.8em;">Image by <a href="http://www.flickr.com/photos/35034351734@N01/330227455">niallkennedy</a> via Flickr</dd>
</dl>
</div>
</div>
<p>Brandon Savage is writing a series on code improvement using a code example (starting with <a href="http://www.brandonsavage.net/peer-review-taking-code-and-making-it-better/">Peer Review: Taking Code And Making It Better</a>). In other words, it&#8217;s about <a class="zem_slink" title="Code refactoring" rel="wikipedia" href="http://en.wikipedia.org/wiki/Code_refactoring">refactoring</a>, which is practically my favorite subject. Although I don&#8217;t agree with all of it, it&#8217;s mostly good advice. I recommend it.</p>
<p>That said, I do have something important to add. The series is missing the first, most basic rule: Don&#8217;t refactor unless you have good automated test coverage (typically with <a class="zem_slink" title="Unit testing" rel="wikipedia" href="http://en.wikipedia.org/wiki/Unit_testing">unit tests</a>). And if there are no test, write them before you start refactoring. If you don&#8217;t, you&#8217;ll make mistakes and get lost in a frustrating bug search, unless you&#8217;re very stingy and don&#8217;t refactor too much. With test coverage, you have freedom to experiment, to change something and change it back if you don&#8217;t like the result. This, above all, is what makes refactoring such a great learning experience.</p>
<p>Some of those who have commented on the post <a href="http://www.brandonsavage.net/peer-review-looking-into-abstraction/">Peer Review: Looking Into Abstraction</a> (Greg Beaver, Jeff Carouth) mention testing and point out the need to inject objects so that they can be replaced with mock objects for testing. This is a wise move, and practically unavoidable in this case. To support refactoring, unit tests need to be run frequently, without accessing outside services (twitter or email in this case) that take time to process.</p>
<p>This means that in this case, it&#8217;s actually necessary to refactor a bit before proper unit tests can be implemented. This is what Michael Feathers calls the <em>Legacy Code Dilemma</em> in his book <a href="http://www.amazon.com/gp/product/0131177052?ie=UTF8&amp;tag=phinac-20&amp;linkCode=as2&amp;camp=1789&amp;creative=9325&amp;creativeASIN=0131177052">Working Effectively with Legacy Code</a><img class=" lmfwcewjbjvyqgtkyshz lmfwcewjbjvyqgtkyshz lmfwcewjbjvyqgtkyshz lmfwcewjbjvyqgtkyshz lmfwcewjbjvyqgtkyshz lmfwcewjbjvyqgtkyshz lmfwcewjbjvyqgtkyshz lmfwcewjbjvyqgtkyshz lmfwcewjbjvyqgtkyshz lmfwcewjbjvyqgtkyshz lmfwcewjbjvyqgtkyshz lmfwcewjbjvyqgtkyshz lmfwcewjbjvyqgtkyshz lmfwcewjbjvyqgtkyshz lmfwcewjbjvyqgtkyshz lmfwcewjbjvyqgtkyshz lmfwcewjbjvyqgtkyshz lmfwcewjbjvyqgtkyshz lmfwcewjbjvyqgtkyshz lmfwcewjbjvyqgtkyshz lmfwcewjbjvyqgtkyshz lmfwcewjbjvyqgtkyshz wjtwchqpuszatsnifmwm wjtwchqpuszatsnifmwm wjtwchqpuszatsnifmwm wjtwchqpuszatsnifmwm wjtwchqpuszatsnifmwm wjtwchqpuszatsnifmwm wjtwchqpuszatsnifmwm wjtwchqpuszatsnifmwm wjtwchqpuszatsnifmwm wjtwchqpuszatsnifmwm wjtwchqpuszatsnifmwm wjtwchqpuszatsnifmwm wjtwchqpuszatsnifmwm wjtwchqpuszatsnifmwm wjtwchqpuszatsnifmwm wjtwchqpuszatsnifmwm wjtwchqpuszatsnifmwm wjtwchqpuszatsnifmwm wjtwchqpuszatsnifmwm wjtwchqpuszatsnifmwm wjtwchqpuszatsnifmwm wjtwchqpuszatsnifmwm" style="border: medium none  ! important; margin: 0px ! important;" src="http://www.assoc-amazon.com/e/ir?t=phinac-20&amp;l=as2&amp;o=1&amp;a=0131177052" border="0" alt="" width="1" height="1" />. Certainly building this dilemma into new code is not a good idea. Make the code unit-testable before it&#8217;s too late.</p>
<div class="zemanta-pixie" style="margin-top: 10px; height: 15px;"><a class="zemanta-pixie-a" title="Reblog this post [with Zemanta]" href="http://reblog.zemanta.com/zemified/20aff681-c4c1-8462-a15b-12d73157b0de/"><img class="zemanta-pixie-img" style="border: medium none; float: right;" src="http://img.zemanta.com/reblog_a.png?x-id=20aff681-c4c1-8462-a15b-12d73157b0de" alt="Reblog this post [with Zemanta]" /></a><span class="zem-script more-related pretty-attribution"><script src="http://static.zemanta.com/readside/loader.js" type="text/javascript"></script></span></div>
<p class="addtoany_share_save_container">
    <a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save?sitename=PHP%20in%20Action&amp;siteurl=http%3A%2F%2Fblog.agilephp.com%2F&amp;linkname=Don%26%238217%3Bt%20refactor%20without%20unit%20tests&amp;linkurl=http%3A%2F%2Fblog.agilephp.com%2F2009%2F09%2F03%2Fdont-refactor-without-unit-tests%2F"><img src="http://blog.agilephp.com/wp-content/plugins/add-to-any/share_save_256_24.png" width="256" height="24" alt="Share/Save/Bookmark"/></a>

	</p>]]></content:encoded>
			<wfw:commentRss>http://blog.agilephp.com/2009/09/03/dont-refactor-without-unit-tests/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Real programming with PHP 5.3 (part 4): A more realistic example</title>
		<link>http://blog.agilephp.com/2009/06/02/real-programming-with-php-53-part-4-a-more-realistic-example/</link>
		<comments>http://blog.agilephp.com/2009/06/02/real-programming-with-php-53-part-4-a-more-realistic-example/#comments</comments>
		<pubDate>Tue, 02 Jun 2009 21:12:54 +0000</pubDate>
		<dc:creator>dagfinn</dc:creator>
				<category><![CDATA[JavaScript/Ajax]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[PHP 5.3]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Object-Oriented]]></category>

		<guid isPermaLink="false">http://blog.agilephp.com/?p=1580</guid>
		<description><![CDATA[



Image by hartboy via Flickr



My previous example in part 2 was just &#8220;hello world&#8221;, so I&#8217;m going to try for something more like the real world. You may find this example unusual, but it does work. I took the PageRange class I used in my July 2007 php&#124;architect article and converted it to the JavaScript [...]]]></description>
			<content:encoded><![CDATA[<div class="zemanta-img" style="margin: 1em; display: block;">
<div>
<dl class="wp-caption alignleft">
<dt class="wp-caption-dt"><a href="http://www.flickr.com/photos/26013750@N00/2801578749"><img src="http://farm4.static.flickr.com/3162/2801578749_4768ccc57f_m.jpg" alt="Let's be realistic" title="Let's be realistic"></a></dt>
<dd class="wp-caption-dd zemanta-img-attribution" style="font-size: 0.8em;">Image by <a href="http://www.flickr.com/photos/26013750@N00/2801578749">hartboy</a> via Flickr</dd>
</dl>
</div>
</div>
<p>My previous example in <a href="http://blog.agilephp.com/2009/03/31/real-programming-with-php-53-part-2-javascript-style-classes/">part 2</a> was just &#8220;hello world&#8221;, so I&#8217;m going to try for something more like the real world. You may find this example unusual, but it does work. I took the PageRange class I used in my <a href="http://phparch.com/c/magazine/issue/56">July 2007 php|architect</a> article and converted it to the JavaScript style. The class is a variation on Martin Fowler&#8217;s Range pattern, and is the hub of a re-implementation of the main functionality of PEAR Pager, using a more object-oriented style.</p>
<p>A Range object is defined by just two values (three in my variation), so it might seem like too much to have an object just to keep these values, but as you can see from the example, a Range class can have behaviors to change and compare ranges.</p>
<p>As before, I&#8217;m defining most of the methods inside the constructor.</p>
<pre class="brush: php">
&lt;?php
class PageRange {
    public $start;
    public $end;
    public $length;

    private $moveToStartAt;
    private $moveToEndAt;
    private $changeLengthToEndAt;
    private $includes;
    private $isInside;
    private $extendsBeyondStartOf;
    private $extendsBeyondEndOf;
    private $truncateToFitInside;
    private $moveToFitInside;
    private $asArray;

    public function __construct($start,$end,$length) {
        $self = $this;
        $this-&gt;start = $start;
        $this-&gt;end = $end;
        $this-&gt;length = $length;

        $this-&gt;moveToStartAt = function($start) use ($self) {
            return PageRange::withStartAndLength(
                $start,$self-&gt;length);
        };

        $this-&gt;moveToEndAt = function($end) use ($self) {
            return PageRange::withEndAndLength($end,$self-&gt;length);
        };

        $this-&gt;changeLengthToEndAt = function($end) use ($self) {
            return PageRange::withStartAndEnd($self-&gt;start,$end);
        };

        // Comparisons

        $this-&gt;includes = function($page) use ($self) {
            return $page &gt;= $self-&gt;start
                &amp;&amp; $page &lt;= $self-&gt;end;
        };

        $this-&gt;isInside = function($range) use ($self) {
            return $range-&gt;includes($self-&gt;getStart())
                &amp;&amp; $range-&gt;includes($self-&gt;getEnd());
        };

        $this-&gt;extendsBeyondStartOf = function(PageRange $range) use ($self) {
            return ($self-&gt;getStart() &lt; $range-&gt;getStart());
        };

        $this-&gt;extendsBeyondEndOf = function(PageRange $range) use ($self) {
            return ($self-&gt;getEnd() &gt; $range-&gt;getEnd());
        };

        // Changes

        $this-&gt;truncateToFitInside = function(PageRange $larger) use ($self) {
            if ($self-&gt;isInside($larger)) return clone $self;
            return $self-&gt;changeLengthToEndAt(
                $larger-&gt;getEnd());
        };

        $this-&gt;moveToFitInside = function(PageRange $larger) use ($self) {
            if ($self-&gt;isInside($larger)) return clone $self;
            if ($self-&gt;extendsBeyondEndOf($larger))
                return $self-&gt;moveToEndAt($larger-&gt;getEnd());
            if ($self-&gt;extendsBeyondStartOf($larger))
                return $self-&gt;moveToStartAt(
                    $larger-&gt;getStart());
        };

        // Convert to array

        $this-&gt;asArray = function() use ($self) {
            return range($self-&gt;start,$self-&gt;end);
        };

    }
</pre>
<p>I&#8217;ve defined the static methods in the usual way, non-JavaScript style. And there is, of course, the mandatory __call() method.</p>
<pre class="brush: php">
class PageRange...

    public function __call($method,$args) {
        return call_user_func_array($this-&gt;$method,$args);
    }

    public function getStart() { return $this-&gt;start; }

    public function getEnd() { return $this-&gt;end; }

    public function getLength() { return $this-&gt;length; }

    private static function calculateEnd($start,$length) {
        return $start + $length - 1;
    }

    private static function calculateStart($end,$length) {
        return $end - $length + 1;
    }

    private static function calculateLength($start,$end) {
        return $end - $start + 1;
    }

    public static function withStartAndLength(
        $start,$length)
    {
        return new self(
            $start,
            self::calculateEnd($start,$length),
            $length
        );
    }

    public static function withEndAndLength($end,$length) {
        return new self(
            self::calculateStart($end,$length),
            $end,
            $length
        );
    }

    public static function withStartAndEnd($start,$end) {
        return new self(
            $start,
            $end,
            self::calculateLength($start,$end)
        );
    }

}
</pre>
<p>An interesting aspect of this class is the fact that the constructor is private, so you have to use one of the creation methods. That&#8217;s part of my variation on the range pattern.</p>
<p class="addtoany_share_save_container">
    <a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save?sitename=PHP%20in%20Action&amp;siteurl=http%3A%2F%2Fblog.agilephp.com%2F&amp;linkname=Real%20programming%20with%20PHP%205.3%20%28part%204%29%3A%20A%20more%20realistic%20example&amp;linkurl=http%3A%2F%2Fblog.agilephp.com%2F2009%2F06%2F02%2Freal-programming-with-php-53-part-4-a-more-realistic-example%2F"><img src="http://blog.agilephp.com/wp-content/plugins/add-to-any/share_save_256_24.png" width="256" height="24" alt="Share/Save/Bookmark"/></a>

	</p>]]></content:encoded>
			<wfw:commentRss>http://blog.agilephp.com/2009/06/02/real-programming-with-php-53-part-4-a-more-realistic-example/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Sounds like an average PHP app to me</title>
		<link>http://blog.agilephp.com/2009/05/04/sounds-like-an-average-php-app-to-me/</link>
		<comments>http://blog.agilephp.com/2009/05/04/sounds-like-an-average-php-app-to-me/#comments</comments>
		<pubDate>Mon, 04 May 2009 18:59:18 +0000</pubDate>
		<dc:creator>dagfinn</dc:creator>
				<category><![CDATA[Application design]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://blog.agilephp.com/?p=1577</guid>
		<description><![CDATA[



Image via Wikipedia



Dean Wampler blogs: Is the Supremacy of Object-Oriented Programming Over?
&#8220;The fact is, for a lot of these applications, it’s just data. The ceremony of object wrappers doesn’t carry its weight. Just put the data in a hash map (or a list if you don’t need the bits “labeled”) and then process the collection [...]]]></description>
			<content:encoded><![CDATA[<div class="zemanta-img" style="margin: 1em; display: block;">
<div>
<dl class="wp-caption alignleft" style="width: 164px;">
<dt class="wp-caption-dt"><a href="http://commons.wikipedia.org/wiki/Image:Key_delete.jpg"><img title="Delete key on PC keyboard" src="http://upload.wikimedia.org/wikipedia/commons/2/2c/Key_delete.jpg" alt="Delete key on PC keyboard" width="154" height="164" /></a></dt>
<dd class="wp-caption-dd zemanta-img-attribution" style="font-size: 0.8em;">Image via <a href="http://commons.wikipedia.org/wiki/Image:Key_delete.jpg">Wikipedia</a></dd>
</dl>
</div>
</div>
<p>Dean Wampler blogs: <a href="http://blog.objectmentor.com/articles/2009/04/20/is-the-supremacy-of-object-oriented-programming-over">Is the Supremacy of Object-Oriented Programming Over?</a></p>
<blockquote><p>&#8220;The fact is, for a lot of these applications, it’s just data. The ceremony of object wrappers doesn’t carry its weight. Just put the data in a hash map (or a list if you don’t need the bits “labeled”) and then process the collection with your iterate, map, and reduce functions. This may sound heretical, but how much Java code could you delete today if you replaced it with a stored procedure?&#8221;</p></blockquote>
<div class="zemanta-pixie" style="margin-top: 10px; height: 15px;"><span class="zem-script more-related pretty-attribution"><script src="http://static.zemanta.com/readside/loader.js" type="text/javascript"></script></span></div>
<p class="addtoany_share_save_container">
    <a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save?sitename=PHP%20in%20Action&amp;siteurl=http%3A%2F%2Fblog.agilephp.com%2F&amp;linkname=Sounds%20like%20an%20average%20PHP%20app%20to%20me&amp;linkurl=http%3A%2F%2Fblog.agilephp.com%2F2009%2F05%2F04%2Fsounds-like-an-average-php-app-to-me%2F"><img src="http://blog.agilephp.com/wp-content/plugins/add-to-any/share_save_256_24.png" width="256" height="24" alt="Share/Save/Bookmark"/></a>

	</p>]]></content:encoded>
			<wfw:commentRss>http://blog.agilephp.com/2009/05/04/sounds-like-an-average-php-app-to-me/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Most confused discussion in the known universe</title>
		<link>http://blog.agilephp.com/2009/05/02/most-confused-discussion-in-the-known-universe/</link>
		<comments>http://blog.agilephp.com/2009/05/02/most-confused-discussion-in-the-known-universe/#comments</comments>
		<pubDate>Sat, 02 May 2009 20:03:12 +0000</pubDate>
		<dc:creator>dagfinn</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Refactoring]]></category>
		<category><![CDATA[Source code]]></category>

		<guid isPermaLink="false">http://blog.agilephp.com/?p=1573</guid>
		<description><![CDATA[



Image by B Tal via Flickr



How confused can a discussion get? As confused as the discussion in the comments to Benjamin Eberlei&#8217;s Explicit Code requires no comments &#8211; Only bad code does. This discussion has a fake identity, and nobody seems to notice. As you can see, the blog post claims to be about code [...]]]></description>
			<content:encoded><![CDATA[<div class="zemanta-img" style="margin: 1em; display: block;">
<div>
<dl class="wp-caption alignleft" style="width: 250px;">
<dt class="wp-caption-dt"><a href="http://www.flickr.com/photos/68634595@N00/163450213"><img title="If You're Not Confused" src="http://farm1.static.flickr.com/73/163450213_18478d3aa6_m.jpg" alt="If You're Not Confused" width="240" height="160" /></a></dt>
<dd class="wp-caption-dd zemanta-img-attribution" style="font-size: 0.8em;">Image by <a href="http://www.flickr.com/photos/68634595@N00/163450213">B Tal</a> via Flickr</dd>
</dl>
</div>
</div>
<p>How confused can a discussion get? As confused as the discussion in the comments to Benjamin Eberlei&#8217;s <a href="http://www.whitewashing.de/blog/articles/116">Explicit Code requires no comments &#8211; Only bad code does</a>. This discussion has a fake identity, and nobody seems to notice<strong>.</strong> As you can see, the blog post claims to be about code comments, but it isn&#8217;t. The example given does not adress the issue of commenting. In the refactored version, Benjamin has not removed the comment from the original, and done nothing (OK, a tiny bit) to replace it with expressive code.  Since the example is irrelevant to the subject matter, it fails to keep the discussion grounded, allowing it to degenerate into dogmatic opinion and subjective speculation.</p>
<p>Also contributing to the confusion is an apparent lack of understanding of the process of refactoring. Refactoring is not a deterministic process, nor is it a strait jacket. You have choice, and you should learn to exercise it judiciously. You take a chunk of code, change it somewhat, and then you decide whether there&#8217;s actually been an improvement. If there hasn&#8217;t, as many think in this case (and I&#8217;m somewhat inclined to agree with them, although Benjamin has great principles and valid points), you have three choices:</p>
<ol>
<li>Refactor further, hoping to arrive at something more satisfactory.</li>
<li>Undo the change and try something else.</li>
<li>Undo the change and keep the original version if you think that&#8217;s the best you can do.</li>
</ol>
<p>These are the normal choices for those of us who refactor routinely. It happens often enough. Even if you undo the change, it doesn&#8217;t necessarily mean you&#8217;ve wasted your time. You&#8217;ve probably learned something.</p>
<p>In this case, too, there is a chance to learn something worthwhile if you can distance yourself from the noisy confrontation. The most obvious thing to observe is that trying to extract methods from a 6-7 line method is a suicide mission in the circumstances. It&#8217;s bound to increase the volume of code <em>a lot</em>, and it&#8217;s only natural that the result gets labeled &#8220;bloated&#8221;. If you do something similar with a longer method, the percentage increase is much less, and you have a chance of not drowning in irrelevant criticism.</p>
<p class="addtoany_share_save_container">
    <a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save?sitename=PHP%20in%20Action&amp;siteurl=http%3A%2F%2Fblog.agilephp.com%2F&amp;linkname=Most%20confused%20discussion%20in%20the%20known%20universe&amp;linkurl=http%3A%2F%2Fblog.agilephp.com%2F2009%2F05%2F02%2Fmost-confused-discussion-in-the-known-universe%2F"><img src="http://blog.agilephp.com/wp-content/plugins/add-to-any/share_save_256_24.png" width="256" height="24" alt="Share/Save/Bookmark"/></a>

	</p>]]></content:encoded>
			<wfw:commentRss>http://blog.agilephp.com/2009/05/02/most-confused-discussion-in-the-known-universe/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>Show me your code comments and I&#8217;ll show why you don&#8217;t need them</title>
		<link>http://blog.agilephp.com/2009/04/30/show-me-your-code-comments-and-ill-show-why-you-dont-need-them/</link>
		<comments>http://blog.agilephp.com/2009/04/30/show-me-your-code-comments-and-ill-show-why-you-dont-need-them/#comments</comments>
		<pubDate>Thu, 30 Apr 2009 20:52:45 +0000</pubDate>
		<dc:creator>dagfinn</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Refactoring]]></category>
		<category><![CDATA[Martin Fowler]]></category>
		<category><![CDATA[Technical debt]]></category>
		<category><![CDATA[Ward Cunningham]]></category>

		<guid isPermaLink="false">http://blog.agilephp.com/?p=1567</guid>
		<description><![CDATA[Brandon Savage has written a blog post On Code Commenting And Technical Debt. He believes that code comments are a good way to minimize technical debt.

I&#8217;m surprised to find the term technical debt mentioned without being accompanied by the term refactoring. Refactoring is generally recognized (outside the PHP world) as the way to pay down [...]]]></description>
			<content:encoded><![CDATA[<p>Brandon Savage has written a blog post <a href="http://www.brandonsavage.net/on-code-commenting-and-technical-debt/">On Code Commenting And Technical Debt</a>. He believes that code comments are a good way to minimize <a class="zem_slink" title="Technical debt" rel="wikipedia" href="http://en.wikipedia.org/wiki/Technical_debt">technical debt</a>.<br />
<a href="http://www.brandonsavage.net/on-code-commenting-and-technical-debt/"></a><br />
I&#8217;m surprised to find the term technical debt mentioned without being accompanied by the term <a class="zem_slink" title="Code refactoring" rel="wikipedia" href="http://en.wikipedia.org/wiki/Code_refactoring">refactoring</a>. Refactoring is generally recognized (outside the PHP world) as <em>the</em> way to pay down technical debt. Commenting may help, but is clearly the second-best practice.</p>
<p><a href="http://martinfowler.com/bliki/TechnicalDebt.html">Martin Fowler</a> puts it this way:</p>
<blockquote><p>Technical Debt is a wonderful metaphor developed by <a class="zem_slink" title="Ward Cunningham" rel="wikipedia" href="http://en.wikipedia.org/wiki/Ward_Cunningham">Ward Cunningham</a> to help us think about this problem. In this metaphor, doing things the quick and dirty way sets us up with a technical debt, which is similar to a financial debt. Like a financial debt, the technical debt incurs interest payments, which come in the form of the extra effort that we have to do in future development because of the quick and dirty design choice. We can choose to continue paying the interest, or we can pay down the principal by refactoring the quick and dirty design into the better design. Although it costs to pay down the principal, we gain by reduced interest payments in the future.</p></blockquote>
<p>Brandon&#8217;s argument in favor of commenting is perfectly valid, but misses the crux of the matter, since he ignores the option of actually improving the code itself rather than just adding comments.</p>
<p>Let me also comment briefly on <a href="http://mtabini.blogspot.com/2009/04/myth-of-myth-of-self-commenting-code.html">Marco Tabini&#8217;s reponse</a>:</p>
<blockquote><p>What I suspect Brandon really means is that the comments are there to illustrate the intentions of the author <span style="font-style: italic;">when those intentions are not immediately made obvious by the code itself</span>.</p></blockquote>
<p>Yes. And no. There is no absolute boundary, no limit in principle, to how <a href="http://c2.com/cgi/wiki/wiki?IntentionRevealingNames">intention-revealing</a> code can be. It&#8217;s not necessarily easy in practice, though. As I&#8217;ve said before, it&#8217;s primarily inline comments that I&#8217;m objecting to. The comments I feel a need to write are often at the class level and address the interaction between different classes.</p>
<p>Anyway, arguing about it theoretically is not the way to resolve the issue. Show me some good examples of comments that serve to make code clearer and that supposedly can&#8217;t be usefully eliminated by refactoring the code into something more readable. I&#8217;ll either admit that you&#8217;re right or show you (or at least outline) how to do it differently. I do recognize that even inline comments are useful&#8230;<em>occasionally</em>.<a href="http://mtabini.blogspot.com/2009/04/myth-of-myth-of-self-commenting-code.html"></a></p>
<p>(By the way, I seem to have missed Brandon&#8217;s comment (<a href="http://www.brandonsavage.net/where-comments-are-useful/">Where Comments Are Useful</a>) to my <a href="http://blog.agilephp.com/2008/12/23/comments-considered-harmful/">comments considered harmful</a> post last December.)</p>
<p class="addtoany_share_save_container">
    <a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save?sitename=PHP%20in%20Action&amp;siteurl=http%3A%2F%2Fblog.agilephp.com%2F&amp;linkname=Show%20me%20your%20code%20comments%20and%20I%26%238217%3Bll%20show%20why%20you%20don%26%238217%3Bt%20need%20them&amp;linkurl=http%3A%2F%2Fblog.agilephp.com%2F2009%2F04%2F30%2Fshow-me-your-code-comments-and-ill-show-why-you-dont-need-them%2F"><img src="http://blog.agilephp.com/wp-content/plugins/add-to-any/share_save_256_24.png" width="256" height="24" alt="Share/Save/Bookmark"/></a>

	</p>]]></content:encoded>
			<wfw:commentRss>http://blog.agilephp.com/2009/04/30/show-me-your-code-comments-and-ill-show-why-you-dont-need-them/feed/</wfw:commentRss>
		<slash:comments>20</slash:comments>
		</item>
		<item>
		<title>10 ways to improve your code</title>
		<link>http://blog.agilephp.com/2009/04/21/10-ways-to-improve-your-code/</link>
		<comments>http://blog.agilephp.com/2009/04/21/10-ways-to-improve-your-code/#comments</comments>
		<pubDate>Tue, 21 Apr 2009 13:55:44 +0000</pubDate>
		<dc:creator>dagfinn</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Neal Ford]]></category>

		<guid isPermaLink="false">http://blog.agilephp.com/?p=1554</guid>
		<description><![CDATA[



Image by Jared Richardson via Flickr



I discovered a video presentation available from QCon SF 2008 by Neal Ford called 10 Ways to Improve Your Code. Although the examples are in Java, most of the presentation is relevant to PHP. There are some ideas here that I&#8217;ve never heard of myself, such as &#8220;anti-objects&#8221;.
Some of the [...]]]></description>
			<content:encoded><![CDATA[<div class="zemanta-img" style="margin: 1em; display: block;">
<div>
<dl class="wp-caption alignright" style="width: 250px;">
<dt class="wp-caption-dt"><a href="http://www.flickr.com/photos/38701974@N00/3296805817"><img title="Neal's Drink of Choice" src="http://farm4.static.flickr.com/3408/3296805817_651ae870f2_m.jpg" alt="Neal's Drink of Choice" width="240" height="160" /></a></dt>
<dd class="wp-caption-dd zemanta-img-attribution" style="font-size: 0.8em;">Image by <a href="http://www.flickr.com/photos/38701974@N00/3296805817">Jared Richardson</a> via Flickr</dd>
</dl>
</div>
</div>
<p>I discovered a video presentation available from QCon SF 2008 by Neal Ford called <a href="http://www.infoq.com/presentations/10-Ways-to-Better-Code-Neal-Ford">10 Ways to Improve Your Code</a>. Although the examples are in Java, most of the presentation is relevant to PHP. There are some ideas here that I&#8217;ve never heard of myself, such as &#8220;anti-objects&#8221;.</p>
<p>Some of the main headings are a bit cryptic, so you may have to see the video itself to have them explained.</p>
<p>Here are the 10 ways:</p>
<ol>
<li>Composed method</li>
<li>TDD (test-driven development/design)</li>
<li>Static analysis</li>
<li>Good citizenship</li>
<li>YAGNI (you ain&#8217;t gonna need it)</li>
<li>Question authority</li>
<li>SLAP (single level of abstraction principle)</li>
<li>Polyglot programming</li>
<li>Every nuance (=learn every nuance of your programming language)</li>
<li>Anti-objects</li>
</ol>
<p>I recommend this presentation. It&#8217;s about the things that really matter if you want to be productive.</p>
<div class="zemanta-pixie" style="margin-top: 10px; height: 15px;"><a class="zemanta-pixie-a" title="Reblog this post [with Zemanta]" href="http://reblog.zemanta.com/zemified/62d5831b-11bf-4961-b232-771ffbf9ca7e/"><img class="zemanta-pixie-img" style="border: medium none; float: right;" src="http://img.zemanta.com/reblog_a.png?x-id=62d5831b-11bf-4961-b232-771ffbf9ca7e" alt="Reblog this post [with Zemanta]" /></a><span class="zem-script more-related pretty-attribution"><script src="http://static.zemanta.com/readside/loader.js" type="text/javascript"></script></span></div>
<p class="addtoany_share_save_container">
    <a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save?sitename=PHP%20in%20Action&amp;siteurl=http%3A%2F%2Fblog.agilephp.com%2F&amp;linkname=10%20ways%20to%20improve%20your%20code&amp;linkurl=http%3A%2F%2Fblog.agilephp.com%2F2009%2F04%2F21%2F10-ways-to-improve-your-code%2F"><img src="http://blog.agilephp.com/wp-content/plugins/add-to-any/share_save_256_24.png" width="256" height="24" alt="Share/Save/Bookmark"/></a>

	</p>]]></content:encoded>
			<wfw:commentRss>http://blog.agilephp.com/2009/04/21/10-ways-to-improve-your-code/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Real programming with PHP 5.3 (part 3): Links</title>
		<link>http://blog.agilephp.com/2009/04/12/real-programming-with-php-53-part-3-links/</link>
		<comments>http://blog.agilephp.com/2009/04/12/real-programming-with-php-53-part-3-links/#comments</comments>
		<pubDate>Sun, 12 Apr 2009 21:14:54 +0000</pubDate>
		<dc:creator>dagfinn</dc:creator>
				<category><![CDATA[Application design]]></category>
		<category><![CDATA[Clean code]]></category>
		<category><![CDATA[JavaScript/Ajax]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[PHP 5.3]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Links]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://blog.agilephp.com/?p=1547</guid>
		<description><![CDATA[



Image via Wikipedia



After the previous post in this series, additional independent implementations of the idea of JavaScript-style classes have turned up. So I&#8217;m going to list them and comment briefly on the differences. I hope this will be helpful to anyone who actually wants to use this in practice and needs to decide on the [...]]]></description>
			<content:encoded><![CDATA[<div class="zemanta-img" style="margin: 1em; display: block;">
<div>
<dl class="wp-caption alignright" style="width: 210px;">
<dt class="wp-caption-dt"><a href="http://commons.wikipedia.org/wiki/Image:Linking_Number_2.svg"><img title="Two curves with linking number 2." src="http://upload.wikimedia.org/wikipedia/commons/thumb/0/0e/Linking_Number_2.svg/200px-Linking_Number_2.svg.png" alt="Two curves with linking number 2." height="121" width="200"></a></dt>
<dd class="wp-caption-dd zemanta-img-attribution" style="font-size: 0.8em;">Image via <a href="http://commons.wikipedia.org/wiki/Image:Linking_Number_2.svg">Wikipedia</a></dd>
</dl>
</div>
</div>
<p>After the previous post in this series, additional independent implementations of the idea of JavaScript-style classes have turned up. So I&#8217;m going to list them and comment briefly on the differences. I hope this will be helpful to anyone who actually wants to use this in practice and needs to decide on the details of the implementation. Here are the links in chronological order:</p>
<ul>
<li><a href="http://www.sitepoint.com/forums/showthread.php?t=565576">Ionut G. Stan:Javascript style PHP with PHP 5.3.0 (forum posting).</a></li>
<li><a href="http://loveandtheft.org/2008/09/20/javascript-oo-python-ducktyping-in-php53/">Fredrik Holmström: Javascript-OO &amp; Python-DuckTyping in PHP5.3.</a></li>
<li><a href="http://www.ibm.com/developerworks/opensource/library/os-php-5.3new2/index.html">John Mertic: What&#8217;s new in PHP V5.3, Part 2: Closures and lambda functions.</a></li>
<li><a href="http://blog.agilephp.com/2009/03/31/real-programming-with-php-53-part-2-javascript-style-classes/">My own previous article.</a></li>
<li><a href="http://webreflection.blogspot.com/2009/03/jsphp-javascript-object-like-php-class.html">Andrea Giammarchi: A JavaScript Object Like PHP Class.</a></li>
</ul>
<p>One difference is how JavaScript-like the implementations are. Some of them implement a syntax that is deliberately made to resemble JavaScript.  Andrea Giammarchi&#8217;s version even uses ArrayAccess to make it possible to access object properties using both object and array syntax, as in JavaScript. At the other extreme is my implementation. I&#8217;ve tried to make it as similar to a regular PHP class as possible. You can instantiate an object in the same way as with an ordinary PHP class. This comes from defining the methods inside the class constructor.</p>
<p>After seeing all of these, I prefer my own way of doing it, except that it lacks what I mentioned in the previous article: an exception when you try to call an unrecognized method. But I&#8217;m obviously not objective, and I may have have missed something.</p>
<p class="addtoany_share_save_container">
    <a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save?sitename=PHP%20in%20Action&amp;siteurl=http%3A%2F%2Fblog.agilephp.com%2F&amp;linkname=Real%20programming%20with%20PHP%205.3%20%28part%203%29%3A%20Links&amp;linkurl=http%3A%2F%2Fblog.agilephp.com%2F2009%2F04%2F12%2Freal-programming-with-php-53-part-3-links%2F"><img src="http://blog.agilephp.com/wp-content/plugins/add-to-any/share_save_256_24.png" width="256" height="24" alt="Share/Save/Bookmark"/></a>

	</p>]]></content:encoded>
			<wfw:commentRss>http://blog.agilephp.com/2009/04/12/real-programming-with-php-53-part-3-links/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Real programming with PHP 5.3 (part 2): JavaScript-style classes</title>
		<link>http://blog.agilephp.com/2009/03/31/real-programming-with-php-53-part-2-javascript-style-classes/</link>
		<comments>http://blog.agilephp.com/2009/03/31/real-programming-with-php-53-part-2-javascript-style-classes/#comments</comments>
		<pubDate>Tue, 31 Mar 2009 11:45:10 +0000</pubDate>
		<dc:creator>dagfinn</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[PHP 5.3]]></category>
		<category><![CDATA[Hello world program]]></category>
		<category><![CDATA[JavaScript]]></category>

		<guid isPermaLink="false">http://blog.agilephp.com/?p=1535</guid>
		<description><![CDATA[
In part one of this series, we looked at the ability to use lambda functions or closures to process arrays. In this part, we will see how closures can be used to build classes in a completely new way.


After I did my own research, I discovered that someone had beat me to it. As early [...]]]></description>
			<content:encoded><![CDATA[<p>
In <a href="http://blog.agilephp.com/2009/03/19/real-programming-with-php-53-part-1-array-processing/">part one of this series</a>, we looked at the ability to use lambda functions or closures to process arrays. In this part, we will see how closures can be used to build classes in a completely new way.
</p>
<p>
After I did my own research, I discovered that someone had beat me to it. As early as September last year Fredrik Holmström wrote about <a href="http://loveandtheft.org/2008/09/20/javascript-oo-python-ducktyping-in-php53/">Javascript-OO &#038; Python-DuckTyping in PHP5.3</a>.
</p>
<p>
I&#8217;ve done the same thing independently and somewhat differently, so it&#8217;s interesting to compare. Unlike Holmström, I&#8217;m defining the closures inside the constructor for the class that&#8217;s using them. That makes the code that uses the class a little more similar to what we&#8217;re used to.
</p>
<p>
Let&#8217;s start with a &#8220;Hello world&#8221; example.
</p>
<pre class="brush: php">
class HelloWorldWithClosures {
    private $hello;
    private $goodbye;

    public function __construct() {
        // If we try using $this inside the closure, we get a syntax error.
        // So we need another variable name, which is basically arbitrary.
        $self = $this;

        // $self is not actually used inside this method/closure, but we want to be consistent.
        $this-&gt;hello = function() use ($self) {
            echo &quot;hello world...\n&quot;;
        };

        $this-&gt;goodbye = function() use ($self) {
            $self-&gt;hello();
            echo &quot;...and goodbye for now\n&quot;;
        };
    }

    public function __call($method,$args) {
        return call_user_func_array($this-&gt;$method,$args);
    }
}
</pre>
<p>
The closures are instance variables in the class, and the __call() method is set up to call the correct closure when calling the method in the usual way in PHP.
</p>
<p>
Now we can call a plain method that uses nothing else from the class:
</p>
<pre class="brush: php">
$obj = new HelloWorldWithClosures;
$obj-&gt;hello(); // prints &quot;hello world...&quot;
</pre>
<p>And we can call the goodbye() method that starts by calling hello():</p>
<pre class="brush: php">
$obj = new HelloWorldWithClosures;
$obj-&gt;goodbye();
// prints &quot;hello world...
//...and goodbye for now&quot;
</pre>
<p>We can also add new methods to object that&#8217;s already instantiated without changing the class:</p>
<pre class="brush: php">
$obj-&gt;helloAgain = function() use($obj) {
    $obj-&gt;goodbye();
    echo &quot;...and hello again\n&quot;;
};
</pre>
<p>
This last example exploits the somewhat vulgar fact that you can still add public instance variables on the fly to an object, as in PHP 4.
</p>
<p>
A different approach that avoids this, but is a bit more verbose, would be to use an array to store the closures in the object:
</p>
<pre class="brush: php">
class HelloWorldWithClosures2 {
    public $methods = array();

    public function __construct() {
        $self = $this;

        $this-&gt;methods[&#039;hello&#039;] = function() use ($self) {
            echo &quot;hello world...\n&quot;;
        };

        $this-&gt;methods[&#039;goodbye&#039;] = function() use ($self) {
            $self-&gt;hello();
            echo &quot;...and goodbye for now\n&quot;;
        };
    }

    public function __call($method,$args) {
        return call_user_func_array($this-&gt;methods[$method],$args);
    }
}
</pre>
<p>
In addition, we would normally need to throw an execption when a method does not exist. The blog post I linked to at the beginning has this feature.
</p>
<p>
Those are the basics of how to write JavaScript-classes in PHP 5.3. Whether you actually want do it this way depends on your needs.  There&#8217;s no point unless you actually want to use the flexibility this style of programmer affords.</p>
<p class="addtoany_share_save_container">
    <a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save?sitename=PHP%20in%20Action&amp;siteurl=http%3A%2F%2Fblog.agilephp.com%2F&amp;linkname=Real%20programming%20with%20PHP%205.3%20%28part%202%29%3A%20JavaScript-style%20classes&amp;linkurl=http%3A%2F%2Fblog.agilephp.com%2F2009%2F03%2F31%2Freal-programming-with-php-53-part-2-javascript-style-classes%2F"><img src="http://blog.agilephp.com/wp-content/plugins/add-to-any/share_save_256_24.png" width="256" height="24" alt="Share/Save/Bookmark"/></a>

	</p>]]></content:encoded>
			<wfw:commentRss>http://blog.agilephp.com/2009/03/31/real-programming-with-php-53-part-2-javascript-style-classes/feed/</wfw:commentRss>
		<slash:comments>15</slash:comments>
		</item>
		<item>
		<title>Ada versus Mars and Venus</title>
		<link>http://blog.agilephp.com/2009/03/24/ada-versus-mars-and-venus/</link>
		<comments>http://blog.agilephp.com/2009/03/24/ada-versus-mars-and-venus/#comments</comments>
		<pubDate>Tue, 24 Mar 2009 22:37:11 +0000</pubDate>
		<dc:creator>dagfinn</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Ada Lovelace]]></category>
		<category><![CDATA[Women]]></category>

		<guid isPermaLink="false">http://blog.agilephp.com/?p=1531</guid>
		<description><![CDATA[



Image via Wikipedia



On the carafe belonging to our coffee maker, there is a barely discernible spot that tells you how far to unscrew the lid in order to open it so that you can pour coffee from it without getting a flood of it in your lap.  I never found this spot until it [...]]]></description>
			<content:encoded><![CDATA[<div class="zemanta-img" style="margin: 1em; display: block;">
<div>
<dl class="wp-caption alignleft" style="width: 212px;">
<dt class="wp-caption-dt"><a href="http://commons.wikipedia.org/wiki/Image:Ada_Lovelace_1838.jpg"><img title="Augusta Ada King, Countess of Lovelace." src="http://upload.wikimedia.org/wikipedia/commons/thumb/2/2e/Ada_Lovelace_1838.jpg/202px-Ada_Lovelace_1838.jpg" alt="Augusta Ada King, Countess of Lovelace." width="202" height="252" /></a></dt>
<dd class="wp-caption-dd zemanta-img-attribution" style="font-size: 0.8em;">Image via <a href="http://commons.wikipedia.org/wiki/Image:Ada_Lovelace_1838.jpg">Wikipedia</a></dd>
</dl>
</div>
</div>
<p>On the carafe belonging to our coffee maker, there is a barely discernible spot that tells you how far to unscrew the lid in order to open it so that you can pour coffee from it without getting a flood of it in your lap.  I never found this spot until it was pointed out to me. For years I overlooked it.  Fortunately, along with the helpful hint as to its location, came the explanation: I&#8217;m a man, so I don&#8217;t understand coffee makers.</p>
<p>I get it.  Men are genetically programmed to understand power drills, women are programmed to understand coffee makers.  They&#8217;re both electrical, relatively low-tech tools, but our chromosomes know the difference. There is that particular base pair sequence in women&#8217;s DNA that encodes the unique neurotransmitter that binds to the receptors on the coffee maker lid scanning neurons. (They&#8217;re in the occipital lobe.) And if women make coffee, it&#8217;s a feminine activity. And if it&#8217;s a feminine activity, women should do it, right?  And if only men write computer programs, then of course it&#8217;s masculine. And if it&#8217;s masculine, then men should be doing it.</p>
<p>It&#8217;s called circular logic. It&#8217;s almost, but not quite, entirely unlike regular logic.</p>
<p>Marching on: As you may have noticed, today is <a href="http://findingada.com/">Ada Lovelace Day</a>. I didn&#8217;t sign <a href="http://www.pledgebank.com/AdaLovelaceDay">the pledge</a>. I read about it yesterday, but like a few others I&#8217;ve seen on Planet PHP, I&#8217;m uncomfortable with singling out one person.  So, instead, I would like to perform a bit of mythbusting.</p>
<p>As I tried to hint in the beginning paragraph, gender sterotypes are not terribly logical. Nor are they supported by hard facts and scientific evidence.</p>
<p>So here is a fact that&#8217;s not much appreciated, but still a fact: men and women are more similar than people tend to believe. This has been known for decades, but is not universally recognized.</p>
<p><a href="http://www.sciam.com/article.cfm?id=not-mars-or-venus">This snippet from Scientific American</a> expresses the essence of it. (Unfortunately, the whole item is not freely available. It&#8217;s good, but short.)</p>
<blockquote><p>Men and women are not nearly as different as the media and pop psychologists would lead us to believe, according to a new metastudy of gender research.</p>
<p>Girls don&#8217;t have the same mathematical proclivity as boys? Not true. Men can&#8217;t communicate as well as women can in relationships? Not so either. And it turns out that the self-esteem problems usually associated with teenage girls are just as pronounced in teenage boys.</p></blockquote>
<p><a href="http://www.psychologymatters.org/nodifference.html">Here is some more information</a> on the same metastudy.</p>
<p>Another excellent source of information is <a href="http://www.guardian.co.uk/world/2007/oct/01/gender.books">this book extract</a>.</p>
<blockquote><p>In The Essential Difference [Simon Baron-Cohen] offers the following &#8220;scientific&#8221; careers advice: &#8220;People with the female brain make the most wonderful counsellors, primary school teachers, nurses, carers, therapists, social workers, mediators, group facilitators or personnel staff &#8230; People with the male brain make the most wonderful scientists, engineers, mechanics, technicians, musicians, architects, electricians, plumbers, taxonomists, catalogists, bankers, toolmakers, programmers or even lawyers.&#8221;</p>
<p>&#8230;</p>
<p>Baron-Cohen classifies nursing as a female-brain, empathy-based job (though if a caring and empathetic nurse cannot measure dosages accurately and make systematic clinical observations she or he risks doing serious harm) and law as a male-brain, system-analysing job (though a lawyer, however well versed in the law, will not get far without communication and people-reading skills). These categorisations are not based on a dispassionate analysis of the demands made by the two jobs. They are based on the everyday common-sense knowledge that most nurses are women and most lawyers are men.</p></blockquote>
<p>Yes, it&#8217;s the coffee maker thing again, and it&#8217;s ridiculous.</p>
<p>The comment about nurses is particularly interesting to me. I&#8217;ve witnessed nurses at an intensive-care unit talking to each other, and I remember thinking &#8220;wow, these ladies know some heavy technical stuff&#8221;. They were not discussing feelings and people, they were talking about the apparatus. And not in a way that I could understand.</p>
<p>On the other side of the coin, even getting up at night to feed a baby doesn&#8217;t take a &#8220;maternal instinct&#8221;. I&#8217;ve done it, and I&#8217;m pretty sure I know what required: you have to understand that it&#8217;s necessary, and stop feeling sorry for yourself. Without the self-pity, the discomfort of interrupted sleep is tolerable. It&#8217;s a relatively mild physical hardship, certainly one that should be within the capacity of &#8220;real men&#8221;.</p>
<p>Gender discrimination and segregation in the workplace is harmful and irrational. But it&#8217;s not easy to abolish, partly because gender stereotypes and mythical differences seem to be considered much more interesting and edible to the media than gender similarities.</p>
<p class="addtoany_share_save_container">
    <a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save?sitename=PHP%20in%20Action&amp;siteurl=http%3A%2F%2Fblog.agilephp.com%2F&amp;linkname=Ada%20versus%20Mars%20and%20Venus&amp;linkurl=http%3A%2F%2Fblog.agilephp.com%2F2009%2F03%2F24%2Fada-versus-mars-and-venus%2F"><img src="http://blog.agilephp.com/wp-content/plugins/add-to-any/share_save_256_24.png" width="256" height="24" alt="Share/Save/Bookmark"/></a>

	</p>]]></content:encoded>
			<wfw:commentRss>http://blog.agilephp.com/2009/03/24/ada-versus-mars-and-venus/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
