<?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; Refactoring</title>
	<atom:link href="http://blog.agilephp.com/category/refactoring/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>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>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>How code comments deteriorate</title>
		<link>http://blog.agilephp.com/2009/01/04/how-code-comments-deteriorate/</link>
		<comments>http://blog.agilephp.com/2009/01/04/how-code-comments-deteriorate/#comments</comments>
		<pubDate>Sun, 04 Jan 2009 12:24:45 +0000</pubDate>
		<dc:creator>dagfinn</dc:creator>
				<category><![CDATA[Application design]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Refactoring]]></category>

		<guid isPermaLink="false">http://localhost/wordpress/?p=1403</guid>
		<description><![CDATA[ There was a lot of disagreement on the value of code comments after my earlier post Comments considered harmful. Perhaps the most important objection that was raised was the idea that it&#8217;s OK to improve the code, but it&#8217;s even better to keep the comments in addition to the improved code. 
 As one [...]]]></description>
			<content:encoded><![CDATA[<p> There was a lot of disagreement on the value of code comments after my earlier post <a href="http://www.reiersol.com/blog/1_php_in_action/archive/174_comments_considered_harmful.html">Comments considered harmful</a>. Perhaps the most important objection that was raised was the idea that it&#8217;s OK to improve the code, but it&#8217;s even better to keep the comments in addition to the improved code. </p>
<p> As one of the critics expressed it: </p>
<blockquote><p>   No, comments are there to comment. Period.<br />   That has nothing to do with how good is your code.<br />   You can write perfectly clean code and add good comments to it. Nothing wrong with that. </p></blockquote>
<p> This is one of those ideas that seem obviously true in theory, but fail to work in practice. The reason is that comments get out of sync with the code. The comments rot, or rather, their meaning does. They become more and more misleading as the code gets changed and the comments are not adequately updated.
<p> Let me give you an example. But first, I want to make it clear that I don&#8217;t think code comments are always a bad thing. Sometimes, they are necessary. But much less often than people think. </p>
<p> API documentation is often indispensible, but that&#8217;s really a different matter. When API documentation is generated from comments in front of each method, the primary purpose is to explain how the code can be used, not how it works. In fact, you might say they are code comments only in a syntactical sense. </p>
<p> On to the example. One of the comments to my blog post presented a code snippet that illustrates my point well. It&#8217;s supposed to be a example of a useful inline comment in code. </p>
<pre class="brush: php">
// first handle the case where no records were found
if ($records == 0) {
    return false;
}
</pre>
<p> Is this really an case of good commenting? I don&#8217;t think so.  If it&#8217;s hard to understand that $records == 0 means that no records were found, we can change the code to make it easier.  The simplest way to do it is to rename the variable to something like $numberOfRecordsFound or $numRecordsFound. Or extract a method. But typically, it&#8217;s possible and preferable to avoid this kind of check altogether. </p>
<p> Anyway, the comment is unnecessary. But as I only realized a while later, it&#8217;s also misleading. Does the code &#8220;handle the case where no records were found&#8221;? No, it leaves it to the calling function to handle the case. The one line that returns <tt>false</tt> is not handling anything, it&#8217;s just passing a message. </p>
<p> So the comment is already misleading, never mind what will happen when someone changes the code and neglects to update the comment. For example, let&#8217;s say the next programmer to work on this code is in hurry to fix a bug. Now maybe the code will look like this: </p>
<pre class="brush: php">
// first handle the case where no records were found
if ($records == 0 &amp;&amp; $state == ACTIVE) {
    return false;
}
</pre>
<p> The programmer wonders briefly whether the comment is still fully appropriate, is unsure, and decides to do nothing about it (or postpones the decision and forgets about it). Now, perhaps (we can&#8217;t quite tell without the full context), the comment is even more misleading.  </p>
<p> In the next round, yet another programmer comes along, makes some more code changes and wonders: &#8220;Should I update the comment? It looks all wrong to me, but it was probably written by someone with deeper insignt into the code. Better leave it alone.&#8221; </p>
<p> The code would have been better off without the comment, but no one wants to delete it, especially since they have been told that comments are so important. It&#8217;s a downward spiral: the code changes make the comments misleading less chance that they will  </p>
<p> Comments that lie are worse than no comments, and in practice they tend to big liars. </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=How%20code%20comments%20deteriorate&amp;linkurl=http%3A%2F%2Fblog.agilephp.com%2F2009%2F01%2F04%2Fhow-code-comments-deteriorate%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/01/04/how-code-comments-deteriorate/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
		<item>
		<title>Beautiful code</title>
		<link>http://blog.agilephp.com/2008/11/03/beautiful-code/</link>
		<comments>http://blog.agilephp.com/2008/11/03/beautiful-code/#comments</comments>
		<pubDate>Mon, 03 Nov 2008 13:36:56 +0000</pubDate>
		<dc:creator>dagfinn</dc:creator>
				<category><![CDATA[Application design]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Refactoring]]></category>
		<category><![CDATA[Testing]]></category>

		<guid isPermaLink="false">http://localhost/wordpress/?p=1398</guid>
		<description><![CDATA[     Max Horwath has published his slides on Making       Selenium Test Writing easier using a DSL onlinefrom IPC 2008. Let me     quote the whole short description:     
 Implementing automated tests by using Seleniums API methods has several [...]]]></description>
			<content:encoded><![CDATA[<p>     Max Horwath has published his slides on <a href="http://www.maxhorvath.com/2008/10/slide-for-ipc-session-on-making-selenium-test-writing-easier-using-a-dsl-online.html">Making       Selenium Test Writing easier using a DSL online</a>from <a href="http://it-republik.de/php/phpconference/">IPC 2008</a>. Let me     quote the whole short description:     </p>
<blockquote><p> Implementing automated tests by using Seleniums API methods has several drawbacks. Selenium is great for what it does, providing a generic framework for testing a generic application. Using the Testing_SeleniumDSL framework, I will show you how to create your own Domain Specific Language (DSL), which would allow you to write tests in the language of your business rather than in Seleniums language.  </p></blockquote>
<p> I&#8217;m quite impressed by the examples he presents, such as: </p>
<pre class="brush: php">
$this-&gt;assertThat($form-&gt;hasSelect(withName(&#039;statusConfirm&#039;))-&gt;hasValues(),
    array(&#039;Yes&#039;,&#039;No&#039;));
</pre>
<p> This is truly expressive, readable code. I&#8217;ve refactored web test code in this direction many times, but I admit I  never got quite this far. </p>
<p>  The DSL is planned as an open source release. It would be interesting to try something  similar for the SimpleTest web tester, which is my favorite for testing web interfaces without too much JavaScript. (Based on <a href="http://www.reiersol.com/blog/1_php_in_action/archive/25_paparrazzi_testing.html">the paparrazzi principle</a>.) </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=Beautiful%20code&amp;linkurl=http%3A%2F%2Fblog.agilephp.com%2F2008%2F11%2F03%2Fbeautiful-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/2008/11/03/beautiful-code/feed/</wfw:commentRss>
		<slash:comments>11</slash:comments>
		</item>
		<item>
		<title>Refactoring is design</title>
		<link>http://blog.agilephp.com/2008/10/11/refactoring-is-design/</link>
		<comments>http://blog.agilephp.com/2008/10/11/refactoring-is-design/#comments</comments>
		<pubDate>Sat, 11 Oct 2008 23:41:24 +0000</pubDate>
		<dc:creator>dagfinn</dc:creator>
				<category><![CDATA[Application design]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Refactoring]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[Smidig2008]]></category>

		<guid isPermaLink="false">http://localhost/wordpress/?p=1406</guid>
		<description><![CDATA[ Refactoring is by definition a design actitivity, since the definition of refactoring is &#8220;improving the design of existing code&#8221;. But is this generally and fully recognized? After attending my friendly local agile conference (Smidig2008&#8212;sorry, it&#8217;s in Norwegian), I&#8217;m getting more of a feel for how different people think about it. And I&#8217;m wondering whether [...]]]></description>
			<content:encoded><![CDATA[<p> Refactoring is by definition a design actitivity, since the definition of refactoring is &#8220;improving the design of existing code&#8221;. But is this generally and fully recognized? After attending my friendly local agile conference (<a href="http://smidig.no/smidig2008/">Smidig2008</a>&mdash;sorry, it&#8217;s in Norwegian), I&#8217;m getting more of a feel for how different people think about it. And I&#8217;m wondering whether the use of metaphors such as &#8220;cleaning&#8221; makes refactoring seem too much like unskilled labor.  After all, physical cleaning jobs are seen that way. </p>
<p> The analogy between cleaning and refactoring is useful for making the non-developers understand that refactoring is absolutely necessary. But beyond this pragmatic similarity, are the two really similar in deep and meaningful ways? I don&#8217;t think so. Refactoring is not unskilled labor. It&#8217;s a task that both requires and builds design skill and experience.  While anyone can see that a floor is dirty, identifying <a href="http://en.wikipedia.org/wiki/Code_smell">code smells</a> is non-obvious, tricky and demanding.  This is true even of the simplest code smell, duplicated code. Although spotting code duplication is sometimes easy, at other times, the duplication is too subtle to be easily identifable.  When you clean a floor, the goal is well-defined and easy to visualize. When refactoring, you may know what you&#8217;re aiming for at each small step, but just a few moves further ahead you may end up with a structure you hadn&#8217;t imagined. </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=Refactoring%20is%20design&amp;linkurl=http%3A%2F%2Fblog.agilephp.com%2F2008%2F10%2F11%2Frefactoring-is-design%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/2008/10/11/refactoring-is-design/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>
