<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	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/"
		>
<channel>
	<title>Comments on: Refactoring 2: Extract Method</title>
	<atom:link href="http://www.codediesel.com/refactoring/refactoring-2-extract-method/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.codediesel.com/software/refactoring-2-extract-method/</link>
	<description>/* PHP &#38; MySQL Journal */</description>
	<lastBuildDate>Fri, 27 Jan 2012 16:39:42 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
<xhtml:meta xmlns:xhtml="http://www.w3.org/1999/xhtml" name="robots" content="noindex" />
	<item>
		<title>By: sameer</title>
		<link>http://www.codediesel.com/software/refactoring-2-extract-method/comment-page-1/#comment-1243</link>
		<dc:creator>sameer</dc:creator>
		<pubDate>Tue, 09 Jun 2009 03:57:16 +0000</pubDate>
		<guid isPermaLink="false">http://www.codediesel.com/?p=168#comment-1243</guid>
		<description>We can make the code as terse as we like, but as I had created the code for one of my clients (they are developers) I choose clear expression over brevity.</description>
		<content:encoded><![CDATA[<p>We can make the code as terse as we like, but as I had created the code for one of my clients (they are developers) I choose clear expression over brevity.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Arne</title>
		<link>http://www.codediesel.com/software/refactoring-2-extract-method/comment-page-1/#comment-1242</link>
		<dc:creator>Arne</dc:creator>
		<pubDate>Mon, 08 Jun 2009 20:01:39 +0000</pubDate>
		<guid isPermaLink="false">http://www.codediesel.com/?p=168#comment-1242</guid>
		<description>I don&#039;t really understand why you use a switch in this example, I wouldn&#039;t use it in this case.
In my opinion this is more dynamic:

if (isset($forex[strtolower($currency_code)])) {
	$_factor = 1 / $forex[strtolower($currency_code)];
}
else {
	$_factor = 1;
}

return $_factor;


Or just in 1 line:


return isset($forex[strtolower($currency_code)]) ? 1 / $forex[strtolower($currency_code)] : 1;


You can even drop the strtolower() if you change the keys in $forex to capitals.</description>
		<content:encoded><![CDATA[<p>I don&#8217;t really understand why you use a switch in this example, I wouldn&#8217;t use it in this case.<br />
In my opinion this is more dynamic:</p>
<p>if (isset($forex[strtolower($currency_code)])) {<br />
	$_factor = 1 / $forex[strtolower($currency_code)];<br />
}<br />
else {<br />
	$_factor = 1;<br />
}</p>
<p>return $_factor;</p>
<p>Or just in 1 line:</p>
<p>return isset($forex[strtolower($currency_code)]) ? 1 / $forex[strtolower($currency_code)] : 1;</p>
<p>You can even drop the strtolower() if you change the keys in $forex to capitals.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Sameer Borate&#8217;s Blog: Refactoring 3: Replace Temp with Query &#124; Webs Developer</title>
		<link>http://www.codediesel.com/software/refactoring-2-extract-method/comment-page-1/#comment-1241</link>
		<dc:creator>Sameer Borate&#8217;s Blog: Refactoring 3: Replace Temp with Query &#124; Webs Developer</dc:creator>
		<pubDate>Mon, 08 Jun 2009 17:09:20 +0000</pubDate>
		<guid isPermaLink="false">http://www.codediesel.com/?p=168#comment-1241</guid>
		<description>[...] temp variable expressions with methods. This method is often also required before you use the Extract Method [...]</description>
		<content:encoded><![CDATA[<p>[...] temp variable expressions with methods. This method is often also required before you use the Extract Method [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: sameer</title>
		<link>http://www.codediesel.com/software/refactoring-2-extract-method/comment-page-1/#comment-1234</link>
		<dc:creator>sameer</dc:creator>
		<pubDate>Thu, 04 Jun 2009 05:49:51 +0000</pubDate>
		<guid isPermaLink="false">http://www.codediesel.com/?p=168#comment-1234</guid>
		<description>Thanks for the encouraging thought.</description>
		<content:encoded><![CDATA[<p>Thanks for the encouraging thought.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Dave Doolin</title>
		<link>http://www.codediesel.com/software/refactoring-2-extract-method/comment-page-1/#comment-1232</link>
		<dc:creator>Dave Doolin</dc:creator>
		<pubDate>Wed, 03 Jun 2009 19:06:17 +0000</pubDate>
		<guid isPermaLink="false">http://www.codediesel.com/?p=168#comment-1232</guid>
		<description>I went to look for more articles and this was the last one!

Please write some more!</description>
		<content:encoded><![CDATA[<p>I went to look for more articles and this was the last one!</p>
<p>Please write some more!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Dave Doolin</title>
		<link>http://www.codediesel.com/software/refactoring-2-extract-method/comment-page-1/#comment-1231</link>
		<dc:creator>Dave Doolin</dc:creator>
		<pubDate>Wed, 03 Jun 2009 19:04:52 +0000</pubDate>
		<guid isPermaLink="false">http://www.codediesel.com/?p=168#comment-1231</guid>
		<description>Thanks for writing.

I did learn something from Chris&#039;s comment: that&#039;s not really refactoring.  

But it is restructuring, which can really help improve code readability.

Please continue this series, and don&#039;t be afraid to make mistakes.  If you&#039;re lucky, people will actually read your articles and catch your mistakes.  

Given you came up on the first page on Google, you&#039;re doing the php community a valuable service as few others see fit to write about refactoring.  Just make sure you keep it simple enough for non-experts to understand, and as accurate as you know how.  Personally, I almost have to write to learn, and I make mistakes along the way.  Some people harsh me for mistakes, others point them out so I can learn better.</description>
		<content:encoded><![CDATA[<p>Thanks for writing.</p>
<p>I did learn something from Chris&#8217;s comment: that&#8217;s not really refactoring.  </p>
<p>But it is restructuring, which can really help improve code readability.</p>
<p>Please continue this series, and don&#8217;t be afraid to make mistakes.  If you&#8217;re lucky, people will actually read your articles and catch your mistakes.  </p>
<p>Given you came up on the first page on Google, you&#8217;re doing the php community a valuable service as few others see fit to write about refactoring.  Just make sure you keep it simple enough for non-experts to understand, and as accurate as you know how.  Personally, I almost have to write to learn, and I make mistakes along the way.  Some people harsh me for mistakes, others point them out so I can learn better.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Les</title>
		<link>http://www.codediesel.com/software/refactoring-2-extract-method/comment-page-1/#comment-1119</link>
		<dc:creator>Les</dc:creator>
		<pubDate>Mon, 16 Mar 2009 17:55:53 +0000</pubDate>
		<guid isPermaLink="false">http://www.codediesel.com/?p=168#comment-1119</guid>
		<description>When I came across the title of this post, I truly was expecting a post about Refactoring but this isn&#039;t refactory (see M Fowler book), and certainly this can&#039;t be seen as the Extract Method either.

With all the hype going about best practices, etc you&#039;ve jumped on the bandwagon (ie keyword Refactoring) to get a higher page index which isn&#039;t really the case, as advertised is it?

Disappointed :(</description>
		<content:encoded><![CDATA[<p>When I came across the title of this post, I truly was expecting a post about Refactoring but this isn&#8217;t refactory (see M Fowler book), and certainly this can&#8217;t be seen as the Extract Method either.</p>
<p>With all the hype going about best practices, etc you&#8217;ve jumped on the bandwagon (ie keyword Refactoring) to get a higher page index which isn&#8217;t really the case, as advertised is it?</p>
<p>Disappointed <img src='http://www.codediesel.com/wp-includes/images/smilies/icon_sad.gif' alt=':(' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Mark</title>
		<link>http://www.codediesel.com/software/refactoring-2-extract-method/comment-page-1/#comment-1071</link>
		<dc:creator>Mark</dc:creator>
		<pubDate>Tue, 13 Jan 2009 17:25:53 +0000</pubDate>
		<guid isPermaLink="false">http://www.codediesel.com/?p=168#comment-1071</guid>
		<description>Or you could just do this:

function getConversionRateFactor($currency_code)
{
    $forex = array(&quot;gbp&quot;=&gt;1.2, &quot;eur&quot;=&gt;.75, &quot;usd&quot;=&gt;1);
 
    switch($currency_code)
    {
        case &quot;GBP&quot; : return 1/$forex[&#039;gbp&#039;];
        case &quot;USD&quot; : return 1;
        case &quot;EUR&quot; : return 1/$forex[&#039;eur&#039;];
        default       : return 1;
    }
}</description>
		<content:encoded><![CDATA[<p>Or you could just do this:</p>
<p>function getConversionRateFactor($currency_code)<br />
{<br />
    $forex = array(&#8220;gbp&#8221;=&gt;1.2, &#8220;eur&#8221;=&gt;.75, &#8220;usd&#8221;=&gt;1);<br />
 <br />
    switch($currency_code)<br />
    {<br />
        case &#8220;GBP&#8221; : return 1/$forex['gbp'];<br />
        case &#8220;USD&#8221; : return 1;<br />
        case &#8220;EUR&#8221; : return 1/$forex['eur'];<br />
        default       : return 1;<br />
    }<br />
}</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Chris</title>
		<link>http://www.codediesel.com/software/refactoring-2-extract-method/comment-page-1/#comment-1070</link>
		<dc:creator>Chris</dc:creator>
		<pubDate>Tue, 13 Jan 2009 08:43:01 +0000</pubDate>
		<guid isPermaLink="false">http://www.codediesel.com/?p=168#comment-1070</guid>
		<description>In an effort to reduce the code size while being more extensible and - as I think - more readable: http://paste.mootools.net/f8819e01

Just wrapping existing code in a function is not refactoring as this changes the external behaviour (it provides a new function to &quot;the outside&quot; and you have to replace all occurences of currency calculation) - I know it is only an example, but this is not refactoring and more of reworking or so.

Refactoring, or the &quot;Extract Method&quot; you describe would be when you have a method getPrice that retrieves the conversion factor AND calculates the price based on the currency and you want to move the retrieval of the conversion factor to a new function getConversionRateFactor and call it within getPrice. This way you won&#039;t have to change the surrounding code as getPrice still behaves the same. I know your example aims to be basic, but I think it is more clear to what it is about :)</description>
		<content:encoded><![CDATA[<p>In an effort to reduce the code size while being more extensible and &#8211; as I think &#8211; more readable: <a href="http://paste.mootools.net/f8819e01" rel="nofollow">http://paste.mootools.net/f8819e01</a></p>
<p>Just wrapping existing code in a function is not refactoring as this changes the external behaviour (it provides a new function to &#8220;the outside&#8221; and you have to replace all occurences of currency calculation) &#8211; I know it is only an example, but this is not refactoring and more of reworking or so.</p>
<p>Refactoring, or the &#8220;Extract Method&#8221; you describe would be when you have a method getPrice that retrieves the conversion factor AND calculates the price based on the currency and you want to move the retrieval of the conversion factor to a new function getConversionRateFactor and call it within getPrice. This way you won&#8217;t have to change the surrounding code as getPrice still behaves the same. I know your example aims to be basic, but I think it is more clear to what it is about <img src='http://www.codediesel.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
	<item>
		<title>By: BradGman</title>
		<link>http://www.codediesel.com/software/refactoring-2-extract-method/comment-page-1/#comment-1069</link>
		<dc:creator>BradGman</dc:creator>
		<pubDate>Tue, 13 Jan 2009 05:16:51 +0000</pubDate>
		<guid isPermaLink="false">http://www.codediesel.com/?p=168#comment-1069</guid>
		<description>Not to be confused with the &quot;true&quot; extract method:

extract($_POST);

Which is the utmost evil thing to leave behind for fellow developers, be warned.</description>
		<content:encoded><![CDATA[<p>Not to be confused with the &#8220;true&#8221; extract method:</p>
<p>extract($_POST);</p>
<p>Which is the utmost evil thing to leave behind for fellow developers, be warned.</p>
]]></content:encoded>
	</item>
</channel>
</rss>

