<?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"
	>

<channel>
	<title>Mindblind</title>
	<atom:link href="http://mindblind.net/feed/" rel="self" type="application/rss+xml" />
	<link>http://mindblind.net</link>
	<description>making web development suck less</description>
	<pubDate>Fri, 08 Feb 2008 06:23:39 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.5.1</generator>
	<language>en</language>
			<item>
		<title>Make PHP Suck Less With a Framework</title>
		<link>http://mindblind.net/2008/02/07/make-php-suck-less-with-a-framework/</link>
		<comments>http://mindblind.net/2008/02/07/make-php-suck-less-with-a-framework/#comments</comments>
		<pubDate>Fri, 08 Feb 2008 01:23:11 +0000</pubDate>
		<dc:creator>Jon Canady</dc:creator>
		
		<category><![CDATA[PHP]]></category>

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

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

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

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

		<guid isPermaLink="false">http://mindblind.net/2008/02/08/make-php-suck-less-with-a-framework/</guid>
		<description><![CDATA[We&#8217;ve established already that PHP sucks.  Now, there&#8217;s still lots of reasons you might find yourself developing a web app in PHP: you have a project that needs doing and you know PHP already, or more likely your client or employer demands it.  I know, you&#8217;d probably rather be developing in Python or [...]]]></description>
			<content:encoded><![CDATA[<p>We&#8217;ve established already that <a href="http://mindblind.net/2008/01/24/attacking-php/">PHP sucks</a>.  Now, there&#8217;s still lots of reasons you might find yourself developing a web app in PHP: you have a project that needs doing and you know PHP already, or more likely your client or employer demands it.  I know, you&#8217;d probably rather be developing in Python or Rails or almost anything else, but don&#8217;t worry.  PHP&#8217;s still going to suck, but there&#8217;s plenty you can do to make the suicidal tendencies less intense.</p>

<p>I&#8217;ve mentioned <a href="http://mindblind.net/2008/01/20/how-to-easily-manage-html-output-in-php/">phpSprockets</a> already &#8212; you did read the post and watch the <a href="http://innova-partners.com/blog/2007/10/23/intro-to-phpsprockets/">screencast</a>, right? &#8212; and that&#8217;s an excellent first step.  But that won&#8217;t get you very far.  You&#8217;re still stuck in a land of writing a bunch <code>mysql_connect()</code> and <code>include 'header.php'</code> lines at the top of every file, right?</p>

<p>Hell no, this isn&#8217;t 1997!</p>

<p><span id="more-11"></span></p>

<h2>MVC Makes Everything OK Again</h2>

<p>Everyone loves MVC frameworks nowadays.  Sure, plenty of MVC frameworks existed before <a href="http://www.rubyonrails.org">Rails</a>, but that was the <em>one</em> &#8212; if you were a web developer, and you somehow hadn&#8217;t heard of MVC, Rails made you pay attention.  </p>

<p>If you&#8217;re still not familiar, then you suck.  But for your benefit, MVC basically breaks down your gigantic PHP file into three parts: a Model, which handles database connections and calls; a Controller, which handles requests for pages and any business logic not in your Model; and a View, which actually shows a page to a user.</p>

<p>For PHP there are a few MVC frameworks, and we&#8217;ll be discussing two: <a href="http://www.cakephp.org/">CakePHP</a> and <a href="http://framework.zend.com">Zend Framework</a>.  We won&#8217;t go into a lot of detail, just the quick basics.  And these aren&#8217;t the only two, just the two that I&#8217;m familiar with off the top of my head that I know are full of quality.  I&#8217;ll have links to their websites, and since everyone loves screencasts nowadays, I&#8217;ll link straight to those.  Watching someone who&#8217;s really familiar with a technology really gives you a feel for whether you&#8217;ll like it or not. </p>

<p>Without further ado:</p>

<h2>CakePHP</h2>

<p>Now, I&#8217;ll be honest &#8212; my CakePHP knowledge is several revisions out of date.  Their website has changed, they&#8217;ve added some excellent screencasts, and they seem to be doing very well.  That said&#8230;</p>

<p>If you&#8217;re secretly wishing you could develop against Rails but you can&#8217;t, CakePHP is for you.  It comes with a code generation tool called <code>bake</code> which can generate basic code for you, a scaffolding feature that will get you up and running quickly, and a Rails-inspired API.  </p>

<p>I&#8217;m not certain if you can override this, but Cake&#8217;s code examples and screencasts all show people coding in a PHP4 OO style &#8212; no <code>private $mvar</code>, instead <code>var $mvar</code>, and no <code>public function foo()</code>, just <code>function foo()</code>, things like that.  Personally, I&#8217;m a stickler for PHP5&#8217;s OO system, which isn&#8217;t perfect but is worlds ahead of PHP4, so this threw me off.  In its defense, it is less verbose, and I&#8217;m fairly sure there&#8217;s no functional difference for the end user, so it&#8217;s just a matter of style.  </p>

<ul>
<li><a href="http://cakephp.org">Official site</a></li>
<li><a href="http://cakephp.org/screencasts">Screencasts</a></li>
</ul>

<h2>Zend Framework</h2>

<p>I&#8217;m a little biased towards ZF, not because I think it&#8217;s superior, but because it&#8217;s what we use at <a href="http://innova-partners.com/blog/">Innova</a>.  So if I have more detail here, don&#8217;t take this as a slam towards CakePHP.</p>

<p>Zend Framework is a more traditional PHP framework &#8212; it requires PHP5 for all of the new Object Orientation features (face it, PHP4&#8217;s OO sucked anyway).  You can&#8217;t expect less from Zend, the guys that make PHP.  Zend comes with a slew of library functionality, from <code>Zend_Mail</code> to <code>Zend_Auth</code> and <code>Zend_ACL</code>.  If you&#8217;ve ever thought, &#8220;I wish I had a library for X&#8221;, ZF probably has it.</p>

<p>On the downside, Zend doesn&#8217;t come with a code-generation utility (as of 1.0.3 &#8212; I haven&#8217;t checked out the 1.5 preview yet), and this means that tedious tasks are tedious.  For example, in Cake (and Rails), you can have the autogeneration tool create you a basic Model, View, and Controller based on input you give it.  This may not seem like much, but having the files created, placed in the right place, and named correctly automatically really saves time.  And (again, as of 1.0.3) we don&#8217;t have a nice console we can use to peek in on things.  Rails has that, and it seems CakePHP has a similar feature.</p>

<ul>
<li><a href="http://framework.zend.com">Official Site</a></li>
<li><a href="http://framework.zend.com/manual/videos">Screencasts</a></li>
</ul>

<h2>So, Yeah</h2>

<p>If you aren&#8217;t using a framework then you&#8217;re doing yourself a disservice.  Check out one of the two I&#8217;ve advocated here, or Google around for the handful I didn&#8217;t mention.  If you&#8217;re familiar with one I skipped, please feel free to plug it in the coomments.</p>
<span class="akst_link"><a href="http://mindblind.net/?p=11&amp;akst_action=share-this"  title="E-mail this, post to del.icio.us, etc." id="akst_link_11"  class="akst_share_link">Share This</a>
</span>]]></content:encoded>
			<wfw:commentRss>http://mindblind.net/2008/02/07/make-php-suck-less-with-a-framework/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Why I Avoid .NET/Mono</title>
		<link>http://mindblind.net/2008/02/03/why-i-avoid-net-mono/</link>
		<comments>http://mindblind.net/2008/02/03/why-i-avoid-net-mono/#comments</comments>
		<pubDate>Mon, 04 Feb 2008 03:26:50 +0000</pubDate>
		<dc:creator>Jon Canady</dc:creator>
		
		<category><![CDATA[Industry]]></category>

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

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

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

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

		<guid isPermaLink="false">http://mindblind.net/2008/02/03/why-i-avoid-the-clr/</guid>
		<description><![CDATA[EDIT (5 Feb 2008):  As indicated in the comments below, some of my reasoning here isn&#8217;t completely accurate.  Apparently Windows Forms runs under Mono now, albeit not some of the newest stuff.  A lot of people seem to be angry at the &#8220;Watch your backs, it&#8217;s Microsoft and they might sue&#8221; thing [...]]]></description>
			<content:encoded><![CDATA[<p><b>EDIT (5 Feb 2008): </b> As indicated in the comments below, some of my reasoning here isn&#8217;t completely accurate.  Apparently Windows Forms runs under Mono now, albeit not some of the newest stuff.  A lot of people seem to be angry at the &#8220;Watch your backs, it&#8217;s Microsoft and they might sue&#8221; thing &#8212; I think it&#8217;s definitely something to keep in mind if you&#8217;re making a living doing Mono development but probably not too much to worry about for anything else.  </p>

<p>So, <a href="http://innova-partners.com/blog/author/ebowen">Eddie at Innova</a> has been touting the awesomeness of C# and the Common Language Runtime for a while &#8212; how it&#8217;s so awesome that he can write code under <a href="http://www.mono-project.com/">Mono</a> and run it under Windows using Microsoft&#8217;s .NET runtime.  <em>And</em>, he can take advantage of all of the .NET libraries!  And if C# is the problem (which he explains is a fantastic language) then why not use IronPython or IronRuby or some such?</p>

<p>On the surface, this sounds like the panacea the industry&#8217;s been looking for since Sun adopted the &#8220;Write Once, Run Anywhere&#8221; slogan for Java.  Certainly seems enticing &#8212; writing in whatever language you want from the set of languages that can compile down to IL, running on any platform that&#8217;s got a compatible runtime.</p>

<p>Except I just don&#8217;t like it.</p>

<p><span id="more-10"></span></p>

<p>Before we go further, understand that I&#8217;m not saying .NET isn&#8217;t the best way to go if you&#8217;re writing software that&#8217;s only ever going to run on Windows.  I personally don&#8217;t like Windows, and have no desire to write software for that platform, but that has nothing to do with this debate.  One more time, with emphasis: <em>.NET is an excellent tool for writing Windows-only software.</em></p>

<p>If writing Windows software is a solution best solved by .NET, and if there&#8217;s a free-software implementation of the .NET CLR in Mono, then why doesn&#8217;t it follow that .NET is a fine solution for cross-platform software development?  </p>

<p>I&#8217;ve got several complaints, first being that unless you&#8217;re using the common subset of features between Mono and .NET you can&#8217;t write cross-platform code.  If I write a Windows Forms application, then that&#8217;s the end of it right there.  You absolutely cannot run that under Mono.  Now, if we start with something like GTK#, then we avoid this problem, but there are similar pitfalls for things like ADO.NET and ASP.NET.  </p>

<p>Somewhat related to that is my second worry: Mono is always going to lag behind Microsoft&#8217;s .NET implementation.  Sure, the whole thing is a published standard, but there&#8217;s still going to be a period of &#8220;This works in .NET latest but not Mono.&#8221;  Again, I&#8217;m not too familiar with Mono&#8217;s past, so I can&#8217;t say with absolute certainty that this has happened or will happen, but I&#8217;d be shocked if there wasn&#8217;t a level of disconnect.</p>

<p>Finally, I&#8217;m just not enthused about promoting technology that Microsoft made popular.  Look what happened to the browser market when IE6 was the best browser on the market &#8212; Microsoft disbanded the IE team and failed to keep up with standards.  IE6 is still used by the majority of web surfers and it&#8217;s the bane of every reasonable web developer.  Look at the state of operating systems.  Microsoft made Windows the de-facto PC operating system and through a lack of innovation and anticompetitive business practices has set the mainstream PC OS industry back a decade.  </p>

<p>If any of my reasons are off, feel free to let me know in the comments.</p>
<span class="akst_link"><a href="http://mindblind.net/?p=10&amp;akst_action=share-this"  title="E-mail this, post to del.icio.us, etc." id="akst_link_10"  class="akst_share_link">Share This</a>
</span>]]></content:encoded>
			<wfw:commentRss>http://mindblind.net/2008/02/03/why-i-avoid-net-mono/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Code Commenting Dos and Don&#8217;ts</title>
		<link>http://mindblind.net/2008/01/27/code-commenting-dos-and-donts/</link>
		<comments>http://mindblind.net/2008/01/27/code-commenting-dos-and-donts/#comments</comments>
		<pubDate>Sun, 27 Jan 2008 23:38:49 +0000</pubDate>
		<dc:creator>Jon Canady</dc:creator>
		
		<category><![CDATA[Industry]]></category>

		<guid isPermaLink="false">http://mindblind.net/2008/01/27/code-commenting-dos-and-donts/</guid>
		<description><![CDATA[Kids: there is indeed a reason that people tell you to comment your code:


  &#8230;today I uncovered a long forgotten beloved project of mine, and I dove in to get it into some kind of working shape, now that I had the experience to actually do it right. Of course, there were no comments [...]]]></description>
			<content:encoded><![CDATA[<p>Kids: there is indeed a reason that people tell you to <a href="http://patchwork.jottit.com/">comment your code</a>:</p>

<blockquote>
  <p>&#8230;today I uncovered a long forgotten beloved project of mine, and I dove in to get it into some kind of working shape, now that I had the experience to actually do it right. Of course, there were no comments anywhere, and there were some mysterious things going on, so it took me a while to figure out what it was all about. But this time, every time I figured something out about the old piece of code I put a comment there, explaining what it was all about. By the time I was happily hacking away at it, I realized this was the best documented piece of code I had ever written</p>
</blockquote>

<p>This is an excellent way to get your code documented, and I&#8217;ve had to do this a few times myself.  But imagine if you didn&#8217;t write the code in question, and you had to pick up someone else&#8217;s project from six months ago?  Now the original author&#8217;s forgot all about it, and you have to figure everything out on your own.  </p>

<p>Commenting your code beforehand saves time, energy, and lives.  Leaving it until later is almost a guarantee it won&#8217;t get done.  But poor commenting can make a file unreadable.  Here&#8217;s a few good rules:</p>

<ol>
<li><em>Do</em> comment particularly tricky blocks or lines of code.  Anything that&#8217;s likely to trip up someone reading the code in a few months.  If you&#8217;re having trouble, check for these problem areas:

<ul>
<li>regular expressions</li>
<li>ternary operations (<code>x = (expr) ? true : false</code>)</li>
<li>bit twiddling</li>
<li>global variables</li>
</ul></li>
<li><em>Do</em> comment variables that aren&#8217;t defined in the current scope.  PHP with <code>register_globals</code> on practically demands it.  (Or, y&#8217;know, just <em>turn it off.</em>)  Global variables, or variables that are unexpectedly modified inside subroutines, are also good areas.</li>
<li><em>Do</em> keep the comments short and to the point.  For example, nobody needs an introduction to finite state machines or role-based ACLs in the middle of the code.  </li>
<li><em>Do</em> update the comments when the code changes.  If you&#8217;re following the previous rule and keeping things short and succinct this isn&#8217;t as much of a chore.</li>
<li><em>Don&#8217;t</em> comment the obvious.  Flooding the file with comments like <code># declaring age as an int</code> or <code>// incrementing loop variable</code> actually have the reverse effect and make the code extremely difficult to read.  If the code doesn&#8217;t need commenting don&#8217;t force it.</li>
</ol>

<p>For the sake of your fellow coders, or your sanity when maintenance time comes, take a few seconds to put a quick <code># This regex validates a phone number in the format (xxx) xxx-xxxx, with or without the parenthesis.</code></p>
<span class="akst_link"><a href="http://mindblind.net/?p=9&amp;akst_action=share-this"  title="E-mail this, post to del.icio.us, etc." id="akst_link_9"  class="akst_share_link">Share This</a>
</span>]]></content:encoded>
			<wfw:commentRss>http://mindblind.net/2008/01/27/code-commenting-dos-and-donts/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Attacking PHP</title>
		<link>http://mindblind.net/2008/01/24/attacking-php/</link>
		<comments>http://mindblind.net/2008/01/24/attacking-php/#comments</comments>
		<pubDate>Thu, 24 Jan 2008 16:08:54 +0000</pubDate>
		<dc:creator>Jon Canady</dc:creator>
		
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://mindblind.net/2008/01/24/attacking-php/</guid>
		<description><![CDATA[I am so tired of people defending PHP. 

Note: this is good natured.  The guy that wrote the original article &#8212; why can I never find names on these things? &#8212; makes a few good points.  And, for full disclosure, I work with PHP full-time right now, and it&#8217;s still my go-to language [...]]]></description>
			<content:encoded><![CDATA[<p>I am so tired of people <a href="http://jimbojw.com/wiki/index.php?title=Defending_PHP">defending</a> PHP. </p>

<p>Note: this is good natured.  The guy that wrote the original article &#8212; why can I never find names on these things? &#8212; makes a few good points.  And, for full disclosure, I work with PHP full-time right now, and it&#8217;s still my go-to language for knocking out a web application because I&#8217;m so familiar with it.  (And even then, only with <a href="http://framework.zend.com">Zend Framework</a> and <a href="http://mindblind.net/2008/01/20/how-to-easily-manage-html-output-in-php/">phpSprockets</a>.)</p>

<p>But seriously, PHP is sickening.  I&#8217;ve started using Ruby and Python for any tasks I can get away with and they&#8217;re really worlds apart.  PHP&#8217;s got some good in it but it&#8217;s all buried under deep layers of hate.  That&#8217;s right, PHP hates you.</p>

<h2>PHP is terrible</h2>

<p>Need proof?  Here it is, broken down by category:</p>

<p><em>Language Features</em></p>

<ul>
<li>So many things evaluate to boolean false or boolean true that there had to be a new operator introduced (=== and !==) to do strict comparisons.</li>
<li>You can&#8217;t differentiate between a hash or a list or anything.  They&#8217;re all the same.  Even if you know you&#8217;ll never need a keyed index, you can&#8217;t turn it off.</li>
<li>It&#8217;s Object Orientation is broken in places (late static binding).</li>
<li>It doesn&#8217;t support lambas.  create&#95;function() is <em>not</em> a lambda.</li>
<li>You never know if short&#95;open&#95;tags is on, or if safe&#95;mode is on, or if (ugh) register&#95;globals is on.</li>
</ul>

<p><em>Built-in Functionalty</em></p>

<ul>
<li>It comes with a standard library that has no naming convention.  You never know in what order the words will come in or if they&#8217;re separated by underscores or not:

<ul>
<li>str&#95;replace()</li>
<li>strlen()</li>
<li>parse&#95;str()</li>
</ul></li>
<li>You never know what order the arguments are in:

<ul>
<li>in&#95;array($needle, $haystack)</li>
<li>strpos($haystack, $needle)</li>
<li>You constantly have to check your output thanks to type restrictions: </li>
<li>strpos(&#8217;abcd&#8217;, &#8216;a&#8217;) will return 0.  Don&#8217;t test this with if (strpos(&#8217;abcd&#8217;, &#8216;a&#8217;)) { &#8230; } because 0 is secretly false!  You&#8217;ve got to use if (strpos(&#8217;abcd&#8217;, &#8216;a&#8217;) !== false).  </li>
</ul></li>
</ul>

<p><em>Common use</em></p>

<p>A lot of open source projects are written in it, such as Joomla, Wordpress, and MediaWiki.  All of their code is hideous, and half of the time there&#8217;s random HTML in the middle of their scripts because, of course, we&#8217;re working with webpages and why would you ever want to abstract the output from the logic?</p>

<h2>Irrelevant praise</h2>

<p>Here are some common praises of PHP and why they don&#8217;t matter:</p>

<p><em>PHP is great because it allows the new user to pick it up quickly!</em></p>

<p>Sure.  And if the introductory material available covered good programming style we might not have a problem.  In reality, every example PHP script is riddled with SQL Injection vulnerabilities, XSS vulnerabilities, and terrible programming.  Most newbs never learn a better way of doing things because this gets them results that <em>look</em> good very quickly.</p>

<p><em>PHP has classes, it doesn&#8217;t need namespaces.</em></p>

<p>Fail.  Use a language with namespaces for a few months and come back to PHP.  I did.  It&#8217;s sickening.</p>

<p><em>Globals are okay!</em></p>

<p>Whoever taught you that needs to be shot.  Globals are not okay.  They are tolerable in certain situations, but if you make blanket statements like &#8220;Globals pierce through all the layers of code and get right to the heart of the matter.&#8221; then you&#8217;re clearly using them too much.</p>
<span class="akst_link"><a href="http://mindblind.net/?p=7&amp;akst_action=share-this"  title="E-mail this, post to del.icio.us, etc." id="akst_link_7"  class="akst_share_link">Share This</a>
</span>]]></content:encoded>
			<wfw:commentRss>http://mindblind.net/2008/01/24/attacking-php/feed/</wfw:commentRss>
		</item>
		<item>
		<title>How to Easily Manage HTML Output in PHP</title>
		<link>http://mindblind.net/2008/01/20/how-to-easily-manage-html-output-in-php/</link>
		<comments>http://mindblind.net/2008/01/20/how-to-easily-manage-html-output-in-php/#comments</comments>
		<pubDate>Sun, 20 Jan 2008 14:56:43 +0000</pubDate>
		<dc:creator>Jon Canady</dc:creator>
		
		<category><![CDATA[PHP]]></category>

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

		<guid isPermaLink="false">http://mindblind.net/2008/01/21/how-to-easily-manage-html-output-in-php/</guid>
		<description><![CDATA[

I thought I&#8217;d come out with the big guns for our inaugural post. If you&#8217;ve ever written a PHP-powered site, you&#8217;ll know that the mix of PHP and HTML in the same document can quickly become hideous to read and a nightmare to maintain.  

The usual solution is o use a template engine like [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://warsaw.innova-partners.com/~innova/sprockets.gif" alt="" title="Sprockets Logo" /></p>

<p>I thought I&#8217;d come out with the big guns for our inaugural post. If you&#8217;ve ever written a PHP-powered site, you&#8217;ll know that the mix of PHP and HTML in the same document can quickly become hideous to read and a nightmare to maintain.  </p>

<p>The usual solution is o use a template engine like <a href="http://www.smarty.net">Smarty</a>, but these are hard to learn and are overkill for smaller projects.</p>

<p>What&#8217;s a developer to do?</p>

<p><span id="more-4"></span></p>

<p>Enter <a href="http://phpsprockets.googlecode.com">phpSprockets</a>, a library written at <a href="http://innova-partners.com/blog">Innova Partners</a> in Columbus OH.  Take a normal PHP document that loops over database records and outputs a table:</p>


<div class="wp_syntax"><div class="code"><pre class="php">&lt;table&gt;
	&lt;tr&gt;
		&lt;th&gt;Name&lt;/th&gt;
		&lt;th&gt;Address&lt;/th&gt;
	&lt;/tr&gt;
<span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #808080; font-style: italic;">// assume $rows has been fetched from the database</span>
<span style="color: #0000ff;">$class</span> = <span style="color: #ff0000;">'alt'</span>;
&nbsp;
<span style="color: #b1b100;">foreach</span> <span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$rows</span> <span style="color: #b1b100;">as</span> <span style="color: #0000ff;">$row</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
	<span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$class</span> == <span style="color: #ff0000;">''</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
		<span style="color: #0000ff;">$class</span> = <span style="color: #ff0000;">'alt'</span>;
	<span style="color: #66cc66;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #66cc66;">&#123;</span>
		<span style="color: #0000ff;">$class</span> = <span style="color: #ff0000;">''</span>;
	<span style="color: #66cc66;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">?&gt;</span>
	&lt;tr <span style="color: #000000; font-weight: bold;">class</span>=<span style="color: #ff0000;">&quot;&lt;?php echo $alt ?&gt;&quot;</span>&gt;
	&lt;td&gt;&lt;?php <span style="color: #000066;">echo</span> <span style="color: #000066;">ucwords</span><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$row</span><span style="color: #66cc66;">&#91;</span><span style="color: #ff0000;">'name'</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#41;</span> ?&gt;&lt;/td&gt;
	&lt;td&gt;&lt;?php <span style="color: #000066;">echo</span> <span style="color: #0000ff;">$row</span><span style="color: #66cc66;">&#91;</span><span style="color: #ff0000;">'address'</span><span style="color: #66cc66;">&#93;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span> &lt;/td&gt;
	&lt;/tr&gt;
	<span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #66cc66;">&#125;</span>
&nbsp;
<span style="color: #000066;">echo</span> <span style="color: #ff0000;">&quot;&lt;/table&gt;&quot;</span>;
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>


<p>That&#8217;s a lot of code for a simple task, and it&#8217;s already a mess.  We&#8217;re applying a different class to alternating rows, we&#8217;re jumping into PHP from HTML, and if we need to do anything complex to this or add more rows this will quickly become unmaintainable.  If you had to work with code like this, you&#8217;d hate your job eventually.</p>

<p>Let&#8217;s see the same code in phpSprockets:</p>


<div class="wp_syntax"><div class="code"><pre class="php"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
&nbsp;
<span style="color: #0000ff;">$table</span> = <span style="color: #000000; font-weight: bold;">new</span> Sprocket<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'table'</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
<span style="color: #0000ff;">$headers</span> = <span style="color: #0000ff;">$table</span>-&gt;<span style="color: #006600;">tr</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #0000ff;">$headers</span>-&gt;<span style="color: #006600;">th</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'Name'</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #0000ff;">$headers</span>-&gt;<span style="color: #006600;">th</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'Address'</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
<span style="color: #0000ff;">$class</span> = <span style="color: #ff0000;">'alt'</span>;
&nbsp;
<span style="color: #b1b100;">foreach</span> <span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$rows</span> <span style="color: #b1b100;">as</span> <span style="color: #0000ff;">$row</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
&nbsp;
	<span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$class</span> == <span style="color: #ff0000;">''</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
		<span style="color: #0000ff;">$class</span> = <span style="color: #ff0000;">'alt'</span>;
	<span style="color: #66cc66;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #66cc66;">&#123;</span>
		<span style="color: #0000ff;">$class</span> = <span style="color: #ff0000;">''</span>;
	<span style="color: #66cc66;">&#125;</span>
&nbsp;
	<span style="color: #0000ff;">$tr</span> = <span style="color: #0000ff;">$table</span>-&gt;<span style="color: #006600;">tr</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
	<span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$class</span> != <span style="color: #ff0000;">''</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
		<span style="color: #0000ff;">$tr</span>-&gt;<span style="color: #006600;">class</span> = <span style="color: #0000ff;">$class</span>;
	<span style="color: #66cc66;">&#125;</span>
&nbsp;
	<span style="color: #0000ff;">$tr</span>-&gt;<span style="color: #006600;">td</span><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$row</span><span style="color: #66cc66;">&#91;</span><span style="color: #ff0000;">'name'</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#41;</span>;
	<span style="color: #0000ff;">$tr</span>-&gt;<span style="color: #006600;">td</span><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$row</span><span style="color: #66cc66;">&#91;</span><span style="color: #ff0000;">'address'</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #66cc66;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>


<p>Okay, the phpSprockets code is longer, but you never leave PHP-mode, and everything&#8217;s very readable.  I didn&#8217;t comment either chunk of code, but once you&#8217;ve learned the simple phpSprockets syntax you&#8217;ll find that it&#8217;s much easier to go back in five months and make changes, which isn&#8217;t something you can say about stock PHP without being very rigorous about coding style.  Since starting with Innova Partners I&#8217;ve switched to using phpSprockets for every PHP project I work on, and the benefits are remarkable.</p>

<p>This is an intentionally brief introduction.  For a more in-depth look watch the <a href="http://innova-partners.com/blog/2007/10/23/intro-to-phpsprockets/">introductory screencast</a> (by me!), and for full documentation and to download, visit our <a href="http://phpsprockets.googlecode.com">downloads</a> page.</p>
<span class="akst_link"><a href="http://mindblind.net/?p=4&amp;akst_action=share-this"  title="E-mail this, post to del.icio.us, etc." id="akst_link_4"  class="akst_share_link">Share This</a>
</span>]]></content:encoded>
			<wfw:commentRss>http://mindblind.net/2008/01/20/how-to-easily-manage-html-output-in-php/feed/</wfw:commentRss>
		</item>
	</channel>
</rss>
