<?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>Jesus Blog &#187; coding standards</title>
	<atom:link href="http://jesus-blog.com/tag/coding-standards/feed" rel="self" type="application/rss+xml" />
	<link>http://jesus-blog.com</link>
	<description>Jesus-blog.com</description>
	<lastBuildDate>Thu, 13 Jan 2011 19:07:47 +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>Wordpress is shit</title>
		<link>http://jesus-blog.com/coding-tips-and-tutorials/wordpress-is.html</link>
		<comments>http://jesus-blog.com/coding-tips-and-tutorials/wordpress-is.html#comments</comments>
		<pubDate>Wed, 30 Sep 2009 17:20:24 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Coding Tips and Tutorials]]></category>
		<category><![CDATA[Opinions]]></category>
		<category><![CDATA[bad php code]]></category>
		<category><![CDATA[coding standards]]></category>
		<category><![CDATA[Wordpress]]></category>

		<guid isPermaLink="false">http://blog.nathanwhitworth.co.uk/?p=106</guid>
		<description><![CDATA[This post goes beyond my opinion of Wordpress though, I want it to highlight a more fundimental problem with PHP development. People just don't seem to be very good at it, and it's giving PHP a bad name.]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve finally cracked, I can take it no more. I&#8217;m just going to have to blog about it.</p>
<p>Before I quit the world and disappeared sailing for 4 months this summer, I wrote a post titled &#8220;<a title="Drupal is shit" href="/opinions/drupal-is-shit.html">Drupal is shit</a>&#8220;, in it a ranted about how I couldn&#8217;t stand Drupal, and that I use either Wordpress or an MVC framework in its place. That post drew quite a bit of attention this summer after <a title="Webschuur" href="http://www.webschuur.com/publications/blogs/2009-08-04-reply_on_quotdrupal_is_shitquot_by">Webschuur</a> blogged a reply to my original post.</p>
<p>The time has now come for me to bitch about the very product I defended in that post; Wordpress.</p>
<p>Here, are you ready for it, I&#8217;m going to say it. Wordpress is shit!</p>
<p>Ok, it&#8217;s not on the face of things, I happen to love Wordpress, but I&#8217;ve been working on a contract rececntly which involves some fairly in depth Wordpress development. I&#8217;ve had to peer under its skirt and what I&#8217;ve found was not something you&#8217;d want to tell your friends about.</p>
<p>This post goes beyond my opinion of Wordpress though, I want it to highlight a more fundamental problem with PHP development. People just don&#8217;t seem to be very good at it, and it&#8217;s giving PHP a bad name.</p>
<p>I got a bit of a telling off in the Drupal thread for not giving examples of what I considered to be poor code, so I&#8217;m not going to allow that to happen again. Let&#8217;s take a look at a random snippet of Wordpress code.<br />
<code> </code></p>
<p>Can anybody tell me what that does? I doubt it, and that makes for bad code from the off. Thankfully, despite the atrocious function naming and cringe inducing syntax, it is doc tagged, so a mouse over in eclipse tell me that the_post() &#8220;iterates the post index in the loop&#8221;. I&#8217;m still not entirely sure what&#8217;s going on here, but I&#8217;ve got a better idea.</p>
<p><!--adsense--></p>
<p>Let&#8217;s dig a bit deeper, F3 in Eclipse open the declaration.<br />
<code><br />
/**<br />
* Iterate the post index in the loop.<br />
*<br />
* @see WP_Query::the_post()<br />
* @since 1.5.0<br />
* @uses $wp_query<br />
*/<br />
function the_post() {<br />
global $wp_query;</code></p>
<p>$wp_query-&gt;the_post();<br />
}</p>
<p>This hasn&#8217;t helped much, I still have no idea what&#8217;s going on, but it has invoked a sub rant about Globals.</p>
<p>Why do people use them? It&#8217;s such a dumb idea. You have no control over that variable, no idea where it comes from, and no idea who has fettled with it before it&#8217;s used in this function.</p>
<p>Now, at this point, I&#8217;d open declaration on the the_post() method, but I can&#8217;t since Eclipse has no idea what $wp_query is. I can&#8217;t even find it without a search through the code because Wordpress doesn&#8217;t do, is put classes in individual files. They are just mixed up where ever in an orgy of mouldy spaghetti code. Again, this is bad because it makes a developers life hard for no benefit.</p>
<p>Searching for &#8220;WP_Query&#8221; was of little benefit since it&#8217;s littered throughout the code. I had to try another tactic, let&#8217;s find the function itself with a search for &#8220;n the_post&#8221;.</p>
<p>Aha, found it in wp-includes/query.php which isn&#8217;t too bad I suppose, although I would have preferred the file be called the same as the class within it. wp_query.php. Makes it nice and obvious then doesn&#8217;t it.</p>
<p>Opening the file shows another horror story; a huge mix of procedural and OO code. I can understand why this may have happened, it was probably because they are trying to port it to OO yet retain backwards compatibility, at least I hope that was the reason, but this is just a bloody confusing mess.</p>
<p>Anyway, onward we go. Let&#8217;s open up the code for the_post() and see what&#8217;s going on.<br />
<code><br />
/**<br />
* Sets up the current post.<br />
*<br />
* Retrieves the next post, sets up the post, sets the 'in the loop'<br />
* property to true.<br />
*<br />
* @since 1.5.0<br />
* @access public<br />
* @uses $post<br />
* @uses do_action() Calls 'loop_start' if loop has just started<br />
*/<br />
function the_post() {<br />
global $post;<br />
$this-&gt;in_the_loop = true;<br />
$post = $this-&gt;next_post();<br />
setup_postdata($post);</code></p>
<p>if ( $this-&gt;current_post == 0 ) // loop has just started<br />
do_action(&#8216;loop_start&#8217;);<br />
}</p>
<p>I think this can be summarised with a simple, yet effective <strong>WTF</strong>!!!!???!!!</p>
<p>I don&#8217;t think I can bear to dig any deeper. What is wrong with using an iterator? There are well established design patterns for this sort of thing.</p>
<p>The bottom line is, Wordpress is like so many projects out there, a complete kludge of crap code. I will still defend Wordpress for being a good product, I can make it do things quickly (mostly) and for standard use it&#8217;s nice and easy to use, but my god do I pity you if you have to go beyond that.</p>
<p>HTML is also well and truly mixed in with the core code, which means to apply a specific design, you may well have to start hacking around within the functions of a plugin. This means that what should be a modular website with themes, quickly turns into a customised hunk of code that you can&#8217;t upgrade any more through fear of braking it all.</p>
<p>The above example reflects the vast majority of PHP code I&#8217;ve worked with, and it&#8217;s sadly a rare thing to stumble across well written and designed PHP software. The unshakable attachment to it&#8217;s roots as a hobiest language are all too apparent.</p>
<p>Come on folks, we can do better than this. When you turn up for work tomorrow, have a think about replacing those globals in your code with a static class or two, but more importantly, find out why you should. The PHP world will thank you for it, I promise.</p>
<p><!--adsense--></p>
]]></content:encoded>
			<wfw:commentRss>http://jesus-blog.com/coding-tips-and-tutorials/wordpress-is.html/feed</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
	</channel>
</rss>

