<?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; maintainability</title>
	<atom:link href="http://www.procata.com/blog/archives/tag/maintainability/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>Fri, 10 Dec 2010 17:23:30 +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>Why is PHP Code Considered Hard to Maintain?</title>
		<link>http://www.procata.com/blog/archives/2006/11/09/why-is-php-code-considered-hard-to-maintain/</link>
		<comments>http://www.procata.com/blog/archives/2006/11/09/why-is-php-code-considered-hard-to-maintain/#comments</comments>
		<pubDate>Fri, 10 Nov 2006 06:37:21 +0000</pubDate>
		<dc:creator>Jeff</dc:creator>
				<category><![CDATA[Open Source]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Software Design]]></category>
		<category><![CDATA[maintainability]]></category>
		<category><![CDATA[namespaces]]></category>
		<category><![CDATA[scaleability]]></category>

		<guid isPermaLink="false">http://www.procata.com/blog/archives/2006/11/09/why-is-php-code-considered-hard-to-maintain/</guid>
		<description><![CDATA[Tobias Schlitt describes Tim Bray&#8217;s talk at the International PHP Conference.  (PDF slides)   Tim compares PHP, Java, and Rails along several dimensions.  One of those dimensions is maintainability.  Tim ranks PHP as least maintainable, Rails in the middle, and Java as most maintainable.  
This is not a surprising ranking. [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://schlitt.info/applications/blog/index.php?/archives/508-Tim-Bray-compared-Java,-Ruby-and-PHP.html">Tobias Schlitt</a> describes <a href="http://www.tbray.org/ongoing/">Tim Bray&#8217;s</a> talk at the International PHP Conference.  (<a href="http://www.tbray.org/talks/php.de.pdf">PDF slides</a>)   Tim compares PHP, Java, and Rails along several dimensions.  One of those dimensions is maintainability.  Tim ranks PHP as least maintainable, Rails in the middle, and Java as most maintainable.  </p>
<p>This is not a surprising ranking.  After all, Tim is from Sun, and the maintainability complaint is common in Anti-PHP rants.  I&#8217;m not trying to suggest that Tim is anti-PHP, far from it, it seems.  I&#8217;m just using his ranking as a spring board to ask questions.</p>
<p>Chances are that your average Java jockey or C scientist&#8217;s first exposure to PHP is to download one of the popular PHP applications.  These are usually the product of some open source mega-project with developers of varying degrees of skill.  Our engineer-by-day spends a few evenings with the program.  The code is not technically outstanding. </p>
<p>How can something like this be so popular he asks?  Yet, the software is successful by definition.  Nobody downloads unsuccessful open source applications.  The technocrat, heavily invested in his own technical prowess, faced with successful yet technically inferior code experiences cognitive dissonance.  The only thing to do is to belittle the successful, but surely offensive code.  &#8220;I could write better code than this,&#8221; he says, or &#8220;this code sucks,&#8221; or &#8220;this is unmaintainable.&#8221;</p>
<p>It is easy to dismiss these gripes inside the PHP community.  After all, those of us using PHP professionally can write maintainable code in PHP.  Ask any programmer and they will tell you, &#8220;My code is maintainable.&#8221;  Who writes all of this unmaintainable code, anyway?</p>
<p>Lets take this gripe at face value for a moment.  Why is PHP code considered hard to maintain?  Is it the language that produces code that is hard to maintain, or is it that the popular ambassadors of the language happen to be programs that are hard to maintain?</p>
<p>Another common PHP sucks complaint is that PHP doesn&#8217;t scale.  When you are talking about traffic, there are all sorts of counter examples for this.  Personally, I&#8217;m dying to learn the story behind those .php extensions on YouTube.  But, this post is not about requests per second.</p>
<p>Another kind of scalability is team size.  I think that when some people complain that PHP doesn&#8217;t scale, what they mean is that PHP doesn&#8217;t scale to large development teams or large projects.  Now we are back to the maintainability issue.</p>
<p>What is it about PHP that makes people think that it is not suitable for larger development teams?</p>
<p>The criticisms of maintainability and scalability generally come from outside the PHP community.  But, there is a common complaint from within the PHP community.  </p>
<p>It is hard to find a PHP wish list that doesn&#8217;t include namespaces.  It comes up again and again.</p>
<p>Sometimes users request a feature without explicitly making their true desires and intentions known.  They say &#8220;I want feature X,&#8221; but what they really mean is &#8220;solve problem Y.&#8221;  Good programmers can hear the request for X, but make the jump to solving Y.  </p>
<p>When people ask for the namespace feature, the problem they want to solve is integrating code from multiple parties.  I wonder if the frequency of this request is a signal of a problem in this department?   Perhaps one that requires more than just namespaces to solve?  Is the namespace request a proxy for a larger problem?</p>
<p>What is it about PHP that makes it hard to integrate code written by multiple parties, whether they be different developers or different organizations?</p>
]]></content:encoded>
			<wfw:commentRss>http://www.procata.com/blog/archives/2006/11/09/why-is-php-code-considered-hard-to-maintain/feed/</wfw:commentRss>
		<slash:comments>48</slash:comments>
		</item>
		<item>
		<title>goto in PHP</title>
		<link>http://www.procata.com/blog/archives/2004/07/29/goto-in-php/</link>
		<comments>http://www.procata.com/blog/archives/2004/07/29/goto-in-php/#comments</comments>
		<pubDate>Thu, 29 Jul 2004 19:07:54 +0000</pubDate>
		<dc:creator>Jeff</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[maintainability]]></category>

		<guid isPermaLink="false">http://www.procata.com/blog/archives/2004/07/29/goto-in-php/</guid>
		<description><![CDATA[There is a discussion on the PHP Internals list about adding a GOTO statement to PHP (via NuCleuZ).
A little History &#8230; (lest we forget)
Gotos have had a long and sordid history in computer science.  In the early days, before languages had a rich set of control structures, goto&#8217;s were it.  It turned out [...]]]></description>
			<content:encoded><![CDATA[<p>There is a discussion on the PHP Internals list about <a href="http://marc.theaimsgroup.com/?t=109106735500003&#038;r=1&#038;w=2">adding a GOTO statement to PHP</a> (<a href="http://phpvolcano.com/wp/index.php?p=138">via NuCleuZ</a>).</p>
<p><strong>A little History</strong> &#8230; (lest we forget)</p>
<p>Gotos have had a long and sordid history in computer science.  In the early days, before languages had a rich set of control structures, goto&#8217;s were it.  It turned out that overusing GOTOs made the control flow of programs hard to follow and thus programs difficult to maintain.  Dijkstra&#8217;s 1968 paper <a href="http://www.acm.org/classics/oct95/">Go To Statement Considered Harmful</a> is considered a classic for recognizing this fact.  GOTO enriched programs are sometimes called <a href="http://en.wikipedia.org/wiki/Spaghetti_code">Spaghetti Code</a></p>
<p>A movement was spawned to eschew the GOTO with as much zealotry as todays modern Object Oriented fanatic uses to eschew &#8220;procedural code.&#8221;  This movement was called <a href="http://en.wikipedia.org/wiki/Structured_programming">Structured Programming</a>.  The central premise being that any given block of code should have one entry point and one exit point.  Presto &#8230; control flow is now easy to understand.</p>
<p>And so the structured programmers waged war on low level control structures in favor of high level control structures. And you know what?  They won.  Languages were constructed without GOTO statements.  Computer science degrees became harder to get for those with an affinity to goto.  <a href="http://www.php.net/manual/en/control-structures.foreach.php">Higher level control structures flourished</a>.</p>
<p>As some of the zealotry faded, it turned out that sometimes <a href="http://www.sitepoint.com/forums/showthread.php?t=152887">multiple exit points can be useful for clarifying code</a>.  Continue, return, and break and later throw all provide ways to provide multiple exit points to a block of code.</p>
<p>Multiple entry points remain blissfully rare except for the occasional confusing fall-through case in a switch statement.</p>
<p>Early in my career, I had the (mis)fortune to be a maintenance programmer on some older programs written in the unstructured style with gotos.  This is where I learned debugging, code smells and refactoring.  Not having a source code control system, the programmer before me was loathe to actually remove unused code from a program, so he would simply GOTO around it.  After years of this, a program might be 50% dead code.  Goto &#8220;patches&#8221; were used instead of subroutines.  A goto would jump to a distant location, perform some operations, and then jump back.  FOR loops were simulated with gotos.   Living with wholesale GOTO abuse, like some sort of war atrocity is not easily forgotten.</p>
<p><strong>GOTOs in PHP</strong></p>
<p>What surprised me most about the <a href="http://marc.theaimsgroup.com/?l=php-dev&#038;m=109106722016891&#038;w=2">GOTO patch</a> for PHP is the positive reception that it has received.  There seem to be three arguemnts in favor of it:</p>
<ol>
<li>it is useful for error handling.</li>
<li>it is useful for writing parsers</li>
<li>it can be faster than other control structures</li>
</ol>
<p>Regarding error handling, I think that using GOTO for error handling is like simulating for loops with GOTO.  Why use the low level concept, when the higher level concept works better?  try..catch and try..finally are designed for error handling.  Use them.</p>
<p>Would people try to simulate gotos with exceptions?  Perhaps.  While that might be bad, gotos might be worse.  The big difference is that exceptions can only provide multiple points of exit from a block of code.  Gotos can provide multiple points of entry.  Goto is far easier to abuse than exceptions.</p>
<p>Another difference between gotos and exceptions is that gotos in PHP are limited to a single scope, while exceptions can cross scope.  This is important when a low level function may know that an error has occurred, but not what to do about it.</p>
<p>Using gotos for error handling increases the active area of variables involved in the error from the point of error occurrence to the point of error handling.  This is bad and not just for compiler register allocation algorithms.</p>
<p>I think that people who want to use goto for error handling probably don&#8217;t understand how to use <a href="http://www.procata.com/blog/archives/2004/05/24/exceptional-php/">exceptions properly yet</a>.  (Thinking in C?)</p>
<p>Gotos are handy for parsing?  Yes, but they are usually used in generated code built by lex or yacc.  This is code not meant to be maintained by humans.  If you are hand constructing a parser, you probably aren&#8217;t going to use tight state transition loops as generated by these programs.  It is possible to write a <a href="http://www.sitepoint.com/forums/showthread.php?t=121246">reasonably fast parser</a> in PHP without goto.</p>
<p>Goto is faster?  This is related to parsing.  The cost of parsing in PHP is allocating memory for substrings, anyway.  This will probably dwarf any gains in control flow.  If you sacrifice maintainability for speed at the micro level, you obfuscate opportunities for real performance gains, which almost always occur at the macro level.  Don&#8217;t sacrifice speed for maintainability.</p>
<p>Having a goto statement makes control flow analysis more difficult for any current or future optimizing compilers.  What is confusing for people turns out to be confusing for computers as well.</p>
<p>Java provides a little used <a href="http://java.sun.com/docs/books/jls/second_edition/html/statements.doc.html#78993">labeled statement</a> which can be the target of a <a href="http://java.sun.com/docs/books/jls/second_edition/html/statements.doc.html#6842">break</a> or <a href="http://java.sun.com/docs/books/jls/second_edition/html/statements.doc.html#6122">continue</a> statement.  This allows escaping deep nesting (a bad code smell on its own) without introducing the problems of multiple points of entry.  This might be a better alternative.</p>
<p>Not once in four years of programming in PHP have I thought to myself &#8220;I wish PHP had a goto statement.&#8221;</p>
<p>Perhaps worst of all, I think having goto will cause serious programmers to take PHP less seriously as a language.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.procata.com/blog/archives/2004/07/29/goto-in-php/feed/</wfw:commentRss>
		<slash:comments>68</slash:comments>
		</item>
	</channel>
</rss>

