<?xml version="1.0" encoding="utf-8" ?>
<?xml-stylesheet href="/templates/default/atom.css" type="text/css" ?>

<feed 
   xmlns="http://www.w3.org/2005/Atom"
   xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
   xmlns:dc="http://purl.org/dc/elements/1.1/"
   xmlns:admin="http://webns.net/mvcb/"
   xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
   xmlns:wfw="http://wellformedweb.org/CommentAPI/">
    <link href="http://codeinthehole.com/feeds/atom.xml" rel="self" title="Code in the hole" type="application/atom+xml" />
    <link href="http://codeinthehole.com/"                        rel="alternate"    title="Code in the hole" type="text/html" />
    <link href="http://codeinthehole.com/rss.php?version=2.0"     rel="alternate"    title="Code in the hole" type="application/rss+xml" />
    <title type="html">Code in the hole</title>
    <subtitle type="html">David Winterbottom</subtitle>
    
    <id>http://codeinthehole.com/</id>
    <updated>2010-08-27T13:52:36Z</updated>
    <generator uri="http://www.s9y.org/" version="1.3.1">Serendipity 1.3.1 - http://www.s9y.org/</generator>
    <dc:language>en</dc:language>

    <entry>
        <link href="http://codeinthehole.com/archives/34-Phing-trick-for-avoiding-deploying-debug-code.html" rel="alternate" title="Phing trick for avoiding deploying debug code" />
        <author>
            <name>David Winterbottom</name>
                    </author>
    
        <published>2010-08-22T15:41:54Z</published>
        <updated>2010-08-27T13:52:36Z</updated>
        <wfw:comment>http://codeinthehole.com/wfwcomment.php?cid=34</wfw:comment>
    
        <slash:comments>1</slash:comments>
        <wfw:commentRss>http://codeinthehole.com/rss.php?version=atom1.0&amp;type=comments&amp;cid=34</wfw:commentRss>
    
            <category scheme="http://codeinthehole.com/categories/6-Deployment" label="Deployment" term="Deployment" />
    
        <id>http://codeinthehole.com/archives/34-guid.html</id>
        <title type="html">Phing trick for avoiding deploying debug code</title>
        <content type="xhtml" xml:base="http://codeinthehole.com/">
            <div xmlns="http://www.w3.org/1999/xhtml">
                <blockquote>Fool me once, shame on you; fool me twice, shame on me</blockquote>

<p>Ensuring mistakes aren't repeated is a commonplace activity for any development team.  This can manifest itself in many ways such as writing regression tests, stepping up your code reviews, adding stories to a testing plan or humiliating the developer in question through use of an unusual (dunce's) hat.</p>

<p>We had an issue recently where some debugging code got committed and wasn't picked up during testing.  Naturally, this code was picked up once it hit the production environment, we put rapidly put a patch in place.  An embarrassing moment but the kind of thing that happens from time to time down in the trenches.</p>

<p>One possible remedy for this would be to add a new sniff to the in-house coding standard (which is tested using the <a onclick="javascript: pageTracker._trackPageview('/extlink/pear.php.net/package/PHP_CodeSniffer/redirected');"  href="http://pear.php.net/package/PHP_CodeSniffer/redirected">PEAR code sniffer</a> on a SVN pre-commit hook) to look for debugging code and block the commit if any is found.  However, a quicker solution was to modify our deployment scripts to search the codebase and bail out if any debug code was found.  We use <a onclick="javascript: pageTracker._trackPageview('/extlink/phing.info/trac/');"  href="http://phing.info/trac/">phing</a> as our deployment tool - here's the appropriate section from our build file:</p>

<pre class="prettyprint">&lt;echo msg="Checking codebase for use of var_dump()" /&gt;
&lt;exec command="[ `find ${folder.app.export}/classes -name '*.php' | xargs grep -nr '\(^\s*|\s\+\)var_dump(.*\?);' | wc -l` -eq 0 ]" dir="." checkreturn="true" /&gt;
</pre>

<p>The command here is grepping all PHP files within the SVN export for occurrences of <code>var_dump</code>.  If any such matching lines are found then a non-zero exit will be returned and the build will fail.   We haven't had such an issue since.</p> 
            </div>
        </content>
        <dc:subject>deployment</dc:subject>
<dc:subject>phing</dc:subject>
<dc:subject>php</dc:subject>

    </entry>
    <entry>
        <link href="http://codeinthehole.com/archives/33-Return-false-with-prudence.html" rel="alternate" title="Return false with prudence" />
        <author>
            <name>David Winterbottom</name>
                    </author>
    
        <published>2010-01-28T22:00:00Z</published>
        <updated>2010-01-29T09:32:42Z</updated>
        <wfw:comment>http://codeinthehole.com/wfwcomment.php?cid=33</wfw:comment>
    
        <slash:comments>2</slash:comments>
        <wfw:commentRss>http://codeinthehole.com/rss.php?version=atom1.0&amp;type=comments&amp;cid=33</wfw:commentRss>
    
            <category scheme="http://codeinthehole.com/categories/1-Development" label="Development" term="Development" />
    
        <id>http://codeinthehole.com/archives/33-guid.html</id>
        <title type="html">Return false with prudence</title>
        <content type="xhtml" xml:base="http://codeinthehole.com/">
            <div xmlns="http://www.w3.org/1999/xhtml">
                <p>From "Javascript: the good parts":</p>
<blockquote>
It is rarely possible for standards comittees to remove imperfections from a language because doing so would cause the breakdage of all of the bad programs that depend on those bad parts.  They are usually powerless to do anything except heap more features on top of the existing pile of imperfections.
</blockquote>
<p>Douglas Crockford's terse yet lucid javascript primer makes some excellent points on writing in a language with more than its fair of share of shortcomings.  The advice is manyfold: constituting functionality or design decisions to avoid (the "bad" and "awful" parts) as well as patterns and practices making use of the strongest parts of the language.  Essentially,  one is guided to programming within a subset of the language, avoiding the poor quality and outright dangerous components.  This chimes in well with the notation of "programming <em>into</em> a language" rather than within in it - stressed by the seminal "Code Complete" by Steve McConnell.</p>
<blockquote>
Don't limit your programming thinking only to the concepts that are supported automatically by your
language. The best programmers think of what they want to do, and then they assess how to accomplish their objectives with the programming tools at their disposal.
</blockquote>

<p>Both these concepts are relevant to programmers of PHP - a language carrying just as much baggage as javascript.  In my experience, developers who have only known PHP are prone to employing of a variety of bad practices and anti-patterns.  Such things are fostered by several influences, including the forgiving nature of the language, the veritable wealth of bad advice within the comments on the PHP manual, and a general lack of understanding of the art of object-oriented programming.  Indeed, I think it's essential that PHP developers learn to program (and hence <em>think</em>) in other languages: python and java in particular.  Reading the work of Martin Fowler is a good place to start but that's a topic for another time.</p>  <br /><a href="http://codeinthehole.com/archives/33-Return-false-with-prudence.html#extended">Continue reading "Return false with prudence"</a>
            </div>
        </content>
        <dc:subject>php</dc:subject>
<dc:subject>readability</dc:subject>

    </entry>

</feed>