<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/css" href="/stylesheets/rss.css"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/">
  <channel>
    <title>Object Mentor Blog: Refactoring Exercise</title>
    <link>http://blog.objectmentor.com/articles/2009/06/04/refactoring-exercise</link>
    <language>en-us</language>
    <ttl>40</ttl>
    <description></description>
    <item>
      <title>Refactoring Exercise</title>
      <description>&lt;p&gt;So I&amp;#8217;ve written a somewhat ugly method with the intent of having people clean it up. Want to give it a try? Post your results and then I&amp;#8217;ll show what I ended up doing in a few days (or after the activity dies down).&lt;/p&gt;


	&lt;p&gt;It&amp;#8217;s in Java, but feel free to post in other languages. I&amp;#8217;d be interested in seeing something in whatever language Michael Feathers happens to be deeply studying right now!-)&lt;/p&gt;


	&lt;p&gt;Oh, and if you feel like going &amp;#8220;overboard&amp;#8221; and using a few design patterns just because you can, I&amp;#8217;d like to see that as well.&lt;/p&gt;


	&lt;p&gt;Here it is:&lt;/p&gt;


&lt;div class="typocode"&gt;&lt;pre&gt;&lt;code class="typocode_java "&gt;  public void take(int v) {
    if (currentMode == Mode.accumulating) {
      int digits = (int)Math.pow(10, (int)Math.log10(v) + 1);
      int x = stack.pop();
      x *= digits;
      x += v;
      stack.push(x);
    }

    if (currentMode == Mode.replacing) {
      stack.pop();
      stack.push(v);
      currentMode = Mode.accumulating;
    }

    if (currentMode == Mode.inserting) {
      int top = stack.peek();
      stack.push(top);
      stack.push(v);
      currentMode = Mode.accumulating;
    }
  }&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;</description>
      <pubDate>Thu, 04 Jun 2009 21:23:00 -0500</pubDate>
      <guid isPermaLink="false">urn:uuid:ce8dfe6e-cd31-4b42-acee-f98327c0bd2a</guid>
      <author>Brett Schuchert</author>
      <link>http://blog.objectmentor.com/articles/2009/06/04/refactoring-exercise</link>
      <category>Schuchert's Scattered Synapses </category>
      <category>refactoring</category>
      <category>exercise</category>
    </item>
    <item>
      <title>"Refactoring Exercise" by alwadifa</title>
      <description>&lt;p&gt;I liked you blog so im going bookmark it with my prefered websites, you have posted an amazing posts so thank you I liked you blog so im going bookmark it with my prefered websites,&lt;/p&gt;</description>
      <pubDate>Sat, 05 Nov 2011 18:00:53 -0500</pubDate>
      <guid isPermaLink="false">urn:uuid:e98815bd-9860-4009-8f69-2da9bde68d68</guid>
      <link>http://blog.objectmentor.com/articles/2009/06/04/refactoring-exercise#comment-168775</link>
    </item>
    <item>
      <title>"Refactoring Exercise" by Tips For Bowling</title>
      <description>&lt;p&gt;The results of ethnic psychology constitute, at the same time, our chief source of information regarding the general psychology of the complex mental processes.
Wilhelm Wundt&lt;/p&gt;</description>
      <pubDate>Thu, 20 Oct 2011 13:22:48 -0500</pubDate>
      <guid isPermaLink="false">urn:uuid:c70741a1-61c6-4e70-b5d8-2b685e449485</guid>
      <link>http://blog.objectmentor.com/articles/2009/06/04/refactoring-exercise#comment-160234</link>
    </item>
    <item>
      <title>"Refactoring Exercise" by ysbearing</title>
      <description>&lt;p&gt;Slewing bearing called slewing ring bearings, is a comprehensive load to bear a large bearing, can bear large axial, radial load and overturning moment.&lt;/p&gt;</description>
      <pubDate>Wed, 19 Oct 2011 02:27:29 -0500</pubDate>
      <guid isPermaLink="false">urn:uuid:64cbe22e-9778-4437-a65b-dcbfca33bb38</guid>
      <link>http://blog.objectmentor.com/articles/2009/06/04/refactoring-exercise#comment-159380</link>
    </item>
    <item>
      <title>"Refactoring Exercise" by herren winterjacken</title>
      <description>&lt;p&gt;I am carrying this bag myself,&lt;a href="http://www.herrenwinterjacken.com/" rel="nofollow"&gt;&lt;strong&gt;Herren Winterjacken&lt;/strong&gt;&lt;/a&gt; when I wear very girly stuff, mine is   smaller than large,&lt;a href="http://www.herrenwinterjacken.com/" rel="nofollow"&gt;&lt;strong&gt;herren winter&lt;/strong&gt;&lt;/a&gt; still can fit lap top and all I need&#8230;I had been    looking for it for several years until I found it 3 years ago in UK.&lt;a href="http://www.herrenwinterjacken.com/belstaff-herren-jacken-c-2.html" rel="nofollow"&gt;&lt;strong&gt;Belstaff Jacken&lt;/strong&gt;&lt;/a&gt; I   saw it for the first time in the movie &#8220;Interpreter&#8221;, carried by Nicole   Kidmann, and then in &#8220;I, Legend&#8221; carried by Will Smith.&lt;a href="http://www.herrenwinterjacken.com/" rel="nofollow"&gt;http://www.herrenwinterjacken.com/&lt;/a&gt;&lt;/p&gt;</description>
      <pubDate>Thu, 29 Sep 2011 11:55:51 -0500</pubDate>
      <guid isPermaLink="false">urn:uuid:638c2114-7f56-4951-9d9b-6833706bf7f1</guid>
      <link>http://blog.objectmentor.com/articles/2009/06/04/refactoring-exercise#comment-148047</link>
    </item>
    <item>
      <title>"Refactoring Exercise" by swarovskicry crystals</title>
      <description>&lt;p&gt;&lt;a href="http://www.swarovskicrystalsuk.co.uk/" rel="nofollow"&gt;&lt;strong&gt;Swarovski&lt;/strong&gt;&lt;/a&gt; crystal jewelry, on top of that also known as these Austrian   &lt;a href="http://www.swarovskicrystalsuk.co.uk/" rel="nofollow"&gt;&lt;strong&gt;Swarovski Crystals&lt;/strong&gt;&lt;/a&gt;, is definitely the most beneficial many costly type of &lt;a href="http://www.swarovskicrystalsuk.co.uk/" rel="nofollow"&gt;&lt;strong&gt;Crystals Swarovski uk &lt;/strong&gt;&lt;/a&gt;. As a result, a majority of these &lt;strong&gt;Swarovski Uk&lt;/strong&gt; items need be adopted special   care involving to allow them to last perpetually.&lt;/p&gt;</description>
      <pubDate>Thu, 29 Sep 2011 11:55:04 -0500</pubDate>
      <guid isPermaLink="false">urn:uuid:75cf859c-aeac-4f95-b8f9-257842453faa</guid>
      <link>http://blog.objectmentor.com/articles/2009/06/04/refactoring-exercise#comment-148041</link>
    </item>
    <item>
      <title>"Refactoring Exercise" by beats by dre store</title>
      <description>&lt;p&gt;other content is so deficient that I move on without delay. That is not the case here.&lt;a href="http://www.drdrebeatsheadphones-australia.com" rel="nofollow"&gt;beats by dre sale&lt;/a&gt;
&lt;a href="http://www.drdrebeatsheadphones-australia.com" rel="nofollow"&gt;cheap beats by dre&lt;/a&gt;&lt;/p&gt;</description>
      <pubDate>Tue, 23 Aug 2011 02:37:15 -0500</pubDate>
      <guid isPermaLink="false">urn:uuid:91eb4656-ab96-4622-99d9-9e4fbed28206</guid>
      <link>http://blog.objectmentor.com/articles/2009/06/04/refactoring-exercise#comment-131612</link>
    </item>
    <item>
      <title>"Refactoring Exercise" by http://www.dunkszone.com/</title>
      <description>&lt;p&gt;Great post. It appears that most of the steps are relying on the creativeness factor&amp;#38;.&lt;/p&gt;</description>
      <pubDate>Tue, 12 Jul 2011 20:13:33 -0500</pubDate>
      <guid isPermaLink="false">urn:uuid:13ce046d-36c8-4301-88a5-511db66ee36e</guid>
      <link>http://blog.objectmentor.com/articles/2009/06/04/refactoring-exercise#comment-118236</link>
    </item>
    <item>
      <title>"Refactoring Exercise" by Cookies Gift</title>
      <description>&lt;p&gt;it needs a bokmark so i can come back to it later ,nice stuff&lt;/p&gt;</description>
      <pubDate>Sun, 19 Jun 2011 11:35:52 -0500</pubDate>
      <guid isPermaLink="false">urn:uuid:84413c27-18fb-4ae5-940d-427fee3cc0c3</guid>
      <link>http://blog.objectmentor.com/articles/2009/06/04/refactoring-exercise#comment-112494</link>
    </item>
    <item>
      <title>"Refactoring Exercise" by okey oyunu oyna</title>
      <description>&lt;p&gt;thank you very much.&lt;/p&gt;


	&lt;p&gt;internette g&#246;r&#252;nt&#252;l&#252; olarak &lt;a href="http://www.okeyoyunu-oyna.com" rel="nofollow"&gt;okey oyunu oyna&lt;/a&gt;, ger&#231;ek kisilerle tanis,
 turnuva heyecanini yasa.&lt;/p&gt;</description>
      <pubDate>Thu, 28 Apr 2011 12:37:37 -0500</pubDate>
      <guid isPermaLink="false">urn:uuid:b84eac7e-fbdf-4f31-aca2-921d710e11ff</guid>
      <link>http://blog.objectmentor.com/articles/2009/06/04/refactoring-exercise#comment-92743</link>
    </item>
    <item>
      <title>"Refactoring Exercise" by clothing manufacturer</title>
      <description>&lt;p&gt;website page the articles and other content is so deficient that I move on without delay. That is not the case here.&lt;/p&gt;</description>
      <pubDate>Sun, 13 Mar 2011 06:44:23 -0500</pubDate>
      <guid isPermaLink="false">urn:uuid:ab00213c-9698-4585-9e46-0ae5a5ae1780</guid>
      <link>http://blog.objectmentor.com/articles/2009/06/04/refactoring-exercise#comment-72270</link>
    </item>
    <item>
      <title>"Refactoring Exercise" by dswehfhh</title>
      <description>&lt;p&gt;We are the professional &lt;a href="http://www.china-clothing-manufacturer.com/dresses.html" rel="nofollow"&gt;dresses manufacturer&lt;/a&gt;, &lt;a href="http://www.china-clothing-manufacturer.com/dresses.html" rel="nofollow"&gt;dresses supplier&lt;/a&gt;, &lt;a href="http://www.china-clothing-manufacturer.com/dresses.html" rel="nofollow"&gt;dresses factory&lt;/a&gt;, &lt;a href="http://www.china-clothing-manufacturer.com/dresses.html" rel="nofollow"&gt;custom dresses&lt;/a&gt;.&lt;/p&gt;</description>
      <pubDate>Wed, 09 Mar 2011 12:39:50 -0600</pubDate>
      <guid isPermaLink="false">urn:uuid:aa9dff73-043f-4e3a-933a-e299382a88e6</guid>
      <link>http://blog.objectmentor.com/articles/2009/06/04/refactoring-exercise#comment-71019</link>
    </item>
    <item>
      <title>"Refactoring Exercise" by Sell Gold for Cash</title>
      <description>&lt;p&gt;Another fantastic posting here at Object Mentor!! Thanks for sharing and keep up the great work.:)&lt;/p&gt;</description>
      <pubDate>Fri, 25 Feb 2011 23:30:00 -0600</pubDate>
      <guid isPermaLink="false">urn:uuid:4ab5ec1c-8d5a-4ad8-bb59-c76e931ac0aa</guid>
      <link>http://blog.objectmentor.com/articles/2009/06/04/refactoring-exercise#comment-66886</link>
    </item>
    <item>
      <title>"Refactoring Exercise" by http://www.whiteiphone4transformer.com</title>
      <description>&lt;p&gt;&lt;a href="http://www.whiteiphone4transformer.com" rel="nofollow"&gt;white iphone 4&lt;/a&gt; is so charming and chic. As the icon of latest fashion, how can you miss it!&lt;/p&gt;</description>
      <pubDate>Thu, 23 Dec 2010 20:38:42 -0600</pubDate>
      <guid isPermaLink="false">urn:uuid:fd28fa7c-8259-4097-92c6-2d8951c31cb7</guid>
      <link>http://blog.objectmentor.com/articles/2009/06/04/refactoring-exercise#comment-51538</link>
    </item>
    <item>
      <title>"Refactoring Exercise" by Pandora </title>
      <description>&lt;p&gt;What does this picture suggest to you or what can you draw from it, if anything?&lt;/p&gt;</description>
      <pubDate>Thu, 02 Dec 2010 01:37:07 -0600</pubDate>
      <guid isPermaLink="false">urn:uuid:c019bafd-dfdc-46fa-b11c-7f5f9dcc744b</guid>
      <link>http://blog.objectmentor.com/articles/2009/06/04/refactoring-exercise#comment-45155</link>
    </item>
    <item>
      <title>"Refactoring Exercise" by moncler</title>
      <description>&lt;p&gt;I find it incredible that more blogs and forums are not as pleasant as this one.&lt;a href="http://www.monclerjacketssaleshop.com/mens-moncler-jackets" rel="nofollow"&gt;moncler down&lt;/a&gt;Often times when I land on a website page the articles and other content is so deficient that I move on without delay. That is not the case here. Thanks so much.&lt;a href="http://www.monclerjacketssaleshop.com/mens-moncler-jackets" rel="nofollow"&gt;moncler men&lt;/a&gt;&lt;/p&gt;</description>
      <pubDate>Thu, 25 Nov 2010 02:31:10 -0600</pubDate>
      <guid isPermaLink="false">urn:uuid:e5ac7425-eb54-4af3-bd9a-22e1bf6195d3</guid>
      <link>http://blog.objectmentor.com/articles/2009/06/04/refactoring-exercise#comment-43030</link>
    </item>
    <item>
      <title>"Refactoring Exercise" by wholeslae shoes</title>
      <description>&lt;p&gt;think you !  &lt;a href="http://www.yourvoguemall.com" rel="nofollow"&gt;http://www.yourvoguemall.com&lt;/a&gt;&lt;/p&gt;</description>
      <pubDate>Mon, 11 Oct 2010 06:59:03 -0500</pubDate>
      <guid isPermaLink="false">urn:uuid:95374878-2082-48c8-a880-7881d111aaba</guid>
      <link>http://blog.objectmentor.com/articles/2009/06/04/refactoring-exercise#comment-32429</link>
    </item>
    <item>
      <title>"Refactoring Exercise" by mlb jerseys sale</title>
      <description>&lt;p&gt;&lt;a href="http://www.superstonejerseys.com" rel="nofollow"&gt;http://www.superstonejerseys.com&lt;/a&gt;&lt;/p&gt;</description>
      <pubDate>Thu, 22 Jul 2010 04:42:53 -0500</pubDate>
      <guid isPermaLink="false">urn:uuid:59a40f37-11ed-4235-a788-b68e902c15c4</guid>
      <link>http://blog.objectmentor.com/articles/2009/06/04/refactoring-exercise#comment-17106</link>
    </item>
    <item>
      <title>"Refactoring Exercise" by Chris</title>
      <description>&lt;p&gt;@Brett&lt;/p&gt;


	&lt;p&gt;I think perhaps we are talking at cross-purposes. I am not objecting to the name &amp;#8220;enter&amp;#8221; in itself, nor to the subtle distinction between &amp;#8220;pressing enter&amp;#8221; and &amp;#8220;completing an input&amp;#8221;. I am objecting to the use of &lt;em&gt;any&lt;/em&gt; interface-level concepts in the domain model.&lt;/p&gt;


	&lt;p&gt;In a RPN calculator, the domain interface requires three basic operations: putting in a number, putting in an operation, and reading out the current value.&lt;/p&gt;


	&lt;p&gt;Internally, of course, it maintains some sort of stack, but the state of that stack is evident only through operations that implicitly change the values at the top of the stack and through reading the current top value.&lt;/p&gt;


	&lt;p&gt;Similarly, there is some logic associated with knowing when a sequence of digits typed by the user is a new number ready to put onto the stack, but this matters only to the UI code. We can see that things like typing an individual digit or pushing an enter button are not in themselves meaningful concepts in the domain, because they make a difference only when they result in pushing a new number onto the stack.&lt;/p&gt;


	&lt;p&gt;This structure would have been immediately obvious had there been separation between the domain model (probably a class with only three public methods plus constructor) and the UI code (with whatever state machine might be appropriate to handle the individual key presses). But because in Uncle Bob&amp;#8217;s version there is just the one huge Register class trying to do everything with many tiny methods, there isn&amp;#8217;t even this basic separation of concerns and the levels of abstraction are all mixed up.&lt;/p&gt;</description>
      <pubDate>Wed, 01 Jul 2009 17:30:10 -0500</pubDate>
      <guid isPermaLink="false">urn:uuid:0f8cd5fb-76cc-4102-8f0c-9be663e6636d</guid>
      <link>http://blog.objectmentor.com/articles/2009/06/04/refactoring-exercise#comment-3643</link>
    </item>
    <item>
      <title>"Refactoring Exercise" by Andrei Vajna</title>
      <description>&lt;p&gt;I took a quick look to the current solutions, and it seems mine is veeery close to Peter Bona&amp;#8217;s.&lt;/p&gt;


&lt;pre&gt;
&lt;code&gt;
abstract class Mode {
  public abstract Mode void take(Stack stack, int v);

  public static final Mode accumulating = new Mode() {
    private int calculatePowerOfTen(int v) {
      return (int)Math.pow(10, (int)Math.log10(v) + 1);
    }

    Mode void take(Stack stack, int v) {        
      int top = stack.pop();  
      stack.push(top * calculatePowerOfTen(v) + v);
      // i chose to use the temp because it's more explanatory this way
      // and because pop() has side effects and i don't want to include it
      // in an expression
      // but i could have easily written
      // stack.push(stack.pop() * calculatePowerOfTen(v) + v);
      // it would be the same regarding functionality
      // but i feel it's more readable this way
      return this;
    }
  };

  public static final Mode replacing = new Mode() {
    Mode void take(Stack stack, int v) {
      stack.pop();
      stack.push(v);
      return Mode.accumulating;
    }
  };

  public static final Mode inserting = new Mode() {
    Mode void take(Stack stack, int v) {
      stack.push(stack.peek());
      stack.push(v);
      return Mode.accumulating;
    }
  };
}
&lt;/code&gt; 
&lt;/pre&gt;

	&lt;p&gt;The originial take method becomes:&lt;/p&gt;


&lt;pre&gt;
&lt;code&gt;
public void take(int v) {
  currentMode = currentMode.take(stack, v);
}
&lt;/code&gt;
&lt;/pre&gt;

	&lt;p&gt;Mode is an implementation of the State pattern. I preffered your initial use of constans and also, I used annonymous classes for conciseness. You could as well have used proper classes, subclassed from Mode base class.&lt;/p&gt;


	&lt;p&gt;The difference from Peter&amp;#8217;s solution are little readability refactorings, like eliminating on of the temps in the accumulating mode with a method.&lt;/p&gt;


	&lt;p&gt;Two points I&amp;#8217;d like to make to your problem: you didn&amp;#8217;t specify what the purpose of the refactoring is, so I could well say that the already implemented solution is fine as it is. And second, &amp;#8220;using a few design patterns just because you can&amp;#8221; is bad! :)&lt;/p&gt;</description>
      <pubDate>Tue, 23 Jun 2009 14:02:25 -0500</pubDate>
      <guid isPermaLink="false">urn:uuid:a9ee3d27-d9db-4ef4-a0fd-cf494b354805</guid>
      <link>http://blog.objectmentor.com/articles/2009/06/04/refactoring-exercise#comment-3619</link>
    </item>
    <item>
      <title>"Refactoring Exercise" by Luca Minudel</title>
      <description>&lt;p&gt;public void take(int v) {&lt;/p&gt;
	&lt;pre&gt;&lt;code&gt;currentMode.take(stack, v);
  currentMode = new CurrentModeAccumulating();&lt;/code&gt;&lt;/pre&gt;


	&lt;pre&gt;&lt;code&gt;}&lt;/code&gt;&lt;/pre&gt;


	&lt;p&gt;...&lt;/p&gt;


	&lt;p&gt;class CurrentModeAccumulating : ICurrentMode {...}&lt;/p&gt;


	&lt;p&gt;class CurrentModeReplacing : ICurrentMode {...}&lt;/p&gt;


	&lt;p&gt;class CurrentModeInserting : ICurrentMode {...}&lt;/p&gt;</description>
      <pubDate>Sun, 21 Jun 2009 12:19:41 -0500</pubDate>
      <guid isPermaLink="false">urn:uuid:2e28fab4-1026-4df0-b611-01c8f1d56eea</guid>
      <link>http://blog.objectmentor.com/articles/2009/06/04/refactoring-exercise#comment-3608</link>
    </item>
    <item>
      <title>"Refactoring Exercise" by Brett L. Schuchert</title>
      <description>&lt;p&gt;&lt;b&gt;Chris&lt;/b&gt; wrote:
&lt;blockquote&gt;
On the contrary, it is describing not what the function does but when it should be called in terms of specific user actions.
&lt;/blockquote&gt;&lt;/p&gt;


	&lt;p&gt;I think you are a bit off the mark. Ultimately, the underling facade supporting some user interface needs to have the ability to represent logical operations from the perspective of the user.&lt;/p&gt;


	&lt;p&gt;Sure, this is not always a 1-to-1 mapping (and in fact it should&lt;i&gt; &lt;b&gt;not&lt;/b&gt;&lt;/i&gt; be so most of the time). However, there is a difference between &amp;#8220;entering the digits of the number&amp;#8221; and &amp;#8220;starting the next number&amp;#8221;.&lt;/p&gt;


So some questions I might ask:
	&lt;ul&gt;
	&lt;li&gt;What are the logical interactions?&lt;/li&gt;
		&lt;li&gt;How many steps do I want to make explicit in the design of my facade layer?&lt;/li&gt;
		&lt;li&gt;How will one design impact multiple potential user interfaces?&lt;/li&gt;
		&lt;li&gt;Can that one facade server all, or is it easy enough to adapt to make it a reasonable abstraction?&lt;/li&gt;
		&lt;li&gt;Does the facade as designed preclude some kind of interaction?&lt;/li&gt;
		&lt;li&gt; ...&lt;/li&gt;
	&lt;/ul&gt;


	&lt;p&gt;Here is an example I came across on a project in 1997&amp;#8230;&lt;/p&gt;


	&lt;p&gt;The project allowed flight rebookings on Palm 7&amp;#8217;s, the web, WAP enabled phones and smart two-way pagers. It worked well, it was ready for use and it was in production (well it was in a beta sense).&lt;/p&gt;


	&lt;p&gt;Then along came a new 2-way pager that used SMTP as its communication between the pager and the base. The average response time was 1 minute. The minimum was 30 seconds and the max was 3+ minutes.&lt;/p&gt;


We had designed several logical steps to change a flight (end to end):
	&lt;ul&gt;
	&lt;li&gt;Go to a URL/bookmark&lt;/li&gt;
		&lt;li&gt;Log in&lt;/li&gt;
		&lt;li&gt;Review itineraries&lt;/li&gt;
		&lt;li&gt;Select itinerary to change&lt;/li&gt;
		&lt;li&gt;Indicate desired change (earlier/later)&lt;/li&gt;
		&lt;li&gt;Select one from a list of options&lt;/li&gt;
		&lt;li&gt;Accept change fees&lt;/li&gt;
		&lt;li&gt;Log out&lt;/li&gt;
	&lt;/ul&gt;


	&lt;p&gt;Ignoring logout, that&amp;#8217;s 7 steps. On this new device, that would, on average, require 7 minutes.&lt;/p&gt;


	&lt;p&gt;We had a conflicting requirement to make a system that was faster than making a phone call. 7 minutes was off the mark by several minutes.&lt;/p&gt;


	&lt;p&gt;So we had to adapt the underlying interaction. We left the underlying service as is but we developed an application for the two-way pager. This application maintained a cache of itineraries and credentials.&lt;/p&gt;


The new interaction was:
	&lt;ul&gt;
	&lt;li&gt;Start application (no time, no hit)&lt;/li&gt;
		&lt;li&gt;Select itinerary and indicate earlier or later booking (hit one)&lt;/li&gt;
		&lt;li&gt;Select from option&lt;/li&gt;
		&lt;li&gt;Accept change fees&lt;/li&gt;
	&lt;/ul&gt;


This was considered too long (three minutes), so we made it even simpler:
	&lt;ul&gt;
	&lt;li&gt;Select itinerary and provide a window (2 &amp;#8211; 4 hours earlier) &lt;/li&gt;
		&lt;li&gt;Auto select change fees if &amp;lt; $250&lt;/li&gt;
	&lt;/ul&gt;


	&lt;p&gt;So this made it fast enough, but it took away too much from the experience and was rejected. We actually had to bring the manufacturer on site to tell them there really were no other options.&lt;/p&gt;


	&lt;p&gt;Why do I bring all of this up at all?&lt;/p&gt;


	&lt;p&gt;When you are building a system, a part of its design is user interaction. Part of that is designing a system that accommodates all of the points of interaction that make the best possible user experience, removing was is not necessary (or relegating it to an alternative).&lt;/p&gt;


	&lt;p&gt;In this case, enter() is the name given for the logical idea of completing input on one number.&lt;/p&gt;


	&lt;p&gt;Can this be removed? Yes. Can a calculator designed without this interaction work with many different user interfaces? Yes (I&amp;#8217;ve done it). Does it map well to the domain? YES.&lt;/p&gt;


	&lt;p&gt;The HP calculators have been around since the late 60&amp;#8217;s (see &lt;a href="http://www.hpmuseum.org/" rel="nofollow"&gt;http://www.hpmuseum.org/&lt;/a&gt;


	&lt;p&gt;So to take it away in fact could make the underlying solution less close to the domain and in fact result in a worse solution.&lt;/p&gt;


	&lt;p&gt;One person&amp;#8217;s intention is another person&amp;#8217;s &amp;#8220;specific user actions&amp;#8221;.&lt;/p&gt;


	&lt;p&gt;Discussing the &amp;#8220;enter&amp;#8221; function is taking a phenomenological perspective, removing it and discussing &amp;#8220;indication completion&amp;#8221; is moving towards the ontological.&lt;/p&gt;


	&lt;p&gt;Context dictates one approach as &amp;#8220;better&amp;#8221; than another &amp;#8211; at least for now.&lt;/p&gt;&lt;/p&gt;</description>
      <pubDate>Tue, 16 Jun 2009 22:25:01 -0500</pubDate>
      <guid isPermaLink="false">urn:uuid:ec97e996-f61b-4d68-bc70-2d3f46721d49</guid>
      <link>http://blog.objectmentor.com/articles/2009/06/04/refactoring-exercise#comment-3577</link>
    </item>
    <item>
      <title>"Refactoring Exercise" by Chris</title>
      <description>&lt;p&gt;@Philip Schwarz&lt;/p&gt;


	&lt;p&gt;The thing is, calling a function &amp;#8220;enter&amp;#8221; like that &lt;em&gt;isn&amp;#8217;t&lt;/em&gt; intention revealing. On the contrary, it is describing not what the function does but when it should be called in terms of specific user actions. There is a place for event handlers like that, but it&amp;#8217;s in your user interface modules. Why is any code in an internal class like this even aware of what the nature of the user interface is, never mind referring to specific user actions?&lt;/p&gt;


	&lt;p&gt;Again, there is a not-seeing-wood-for-trees problem here. If we were to expand the scope of the problem to include the user interactions - which is far beyond what the original function covered and not a mere refactoring, of course - then we should be creating an internal class to model the stack behaviour with interface methods representing domain concepts such as pushing a number onto the stack, applying an operator and showing the current top of the stack, and we should also have separate code to handle UI quirks like parsing single keystrokes and evaluating when they become triggers for certain meaningful actions in the problem domain.&lt;/p&gt;</description>
      <pubDate>Sun, 14 Jun 2009 17:46:43 -0500</pubDate>
      <guid isPermaLink="false">urn:uuid:41c7d302-bdce-4984-abf4-525800142bc7</guid>
      <link>http://blog.objectmentor.com/articles/2009/06/04/refactoring-exercise#comment-3566</link>
    </item>
    <item>
      <title>"Refactoring Exercise" by Philip Schwarz</title>
      <description>&lt;p&gt;@Chris&lt;/p&gt;


	&lt;p&gt;You said:&lt;/p&gt;


&lt;blockquote&gt;
I could immediately guess what isEmpty would mean from the calling code, and while it is only a single line long, it does represent a useful abstraction.

On the other hand, despite knowing the general problem area we&#8217;re discussing, &lt;b&gt;I still don&#8217;t see why the names take, dup, enter and accumulate are particularly helpful here. take seems rather arbitrary: neither it nor the name Register provide enough context for it to be a meaningful concept without further information&lt;/b&gt;. 
&lt;/blockquote&gt;

	&lt;p&gt;OK..so while you find &amp;#8216;isEmpty&amp;#8217; to be intention-revealing, the same is not true for Uncle Bob&amp;#8217;s one-line methods.&lt;/p&gt;


	&lt;p&gt;If you look back 11 posts from Uncle Bob&amp;#8217;s, you&amp;#8217;ll see Brett&amp;#8217;s firts follow-up post, in which he says:&lt;/p&gt;


	&lt;p&gt;&lt;i&gt;By the way, this is the beginnings of a method to handle input for an RPN calculator. Input is more complex than I first imagined:&lt;/i&gt;
&lt;/p&gt;


	&lt;ul&gt;
	&lt;li&gt;&lt;i&gt;Initially digits are accumulating.&lt;/i&gt;&lt;/li&gt;
		&lt;li&gt;&lt;i&gt;After pressing enter, the next digit will replace the top of the stack (the x register) because pressing enter duplicated the current top.&lt;/i&gt;&lt;/li&gt;
		&lt;li&gt;&lt;i&gt;After executing an operator, e.g., + &amp;#8211; / * !, typing a digit duplicates the top of the stack (while another operator uses what&#8217;s there).&lt;/i&gt;&lt;/li&gt;
	&lt;/ul&gt;


&lt;br&gt;
Based on that, the following is possible:
	&lt;ol&gt;
	&lt;li&gt;The accumulate method is called that way because it tells the Calculator to go into a state in which it accumulates digits.&lt;/li&gt;
		&lt;li&gt;The take method is called that way because it takes the user&amp;#8217;s input to the calculator.&lt;/li&gt;
		&lt;li&gt;The Register class is called that way because the Calculator has a number of register, e.g. x.&lt;/li&gt;
		&lt;li&gt;The dup method maps to the problem domain (or system metaphor) concept of duplicating the top of a stack&lt;/li&gt;
		&lt;li&gt;The enter method maps to the problem domain concept of pressing the calculator&amp;#8217;s enter button.&lt;/li&gt;
	&lt;/ol&gt;


	&lt;p&gt;So Uncle Bob has created methods that map to problem-domain abstractions and are therefore intention-revealing to anyone who knows enough about the problem domain. To make the code readable, he has hidden code that tells us HOW the problem solution is implemented, behind code that models WHAT happens in the problem domain.&lt;/p&gt;


	&lt;p&gt;You seem (to me) to be saying that Uncle Bob&amp;#8217;s one-line methods make the code harder to read because they are not intention-revealing (to you because you don&amp;#8217;t know enough about the problem domain), so the code would be better off (more readable) if instead of telling you about WHAT happens in the problem domain, it just told you HOW the solution to the problem is implemented e.g. using stack operations.&lt;/p&gt;


	&lt;p&gt;I disagree. Uncle Bob has chunked implementation details and hid them behind intention-revealing method names, so that people who know enough about the problem domain (e.g. anyone intending to maintain the code) can read his code more quickly and accurately.&lt;/p&gt;</description>
      <pubDate>Sun, 14 Jun 2009 17:10:09 -0500</pubDate>
      <guid isPermaLink="false">urn:uuid:cba02e13-ee0e-4200-a1fc-52fdb4027ce7</guid>
      <link>http://blog.objectmentor.com/articles/2009/06/04/refactoring-exercise#comment-3565</link>
    </item>
    <item>
      <title>"Refactoring Exercise" by Chris</title>
      <description>&lt;p&gt;@Philip Schwarz&lt;/p&gt;


	&lt;p&gt;I think the code you cited is an excellent example of taking a good rule of thumb to such an absurd extreme that it breaks.&lt;/p&gt;


	&lt;p&gt;I am amused by the fact that the one function in the proposed rewrite that does do something actually does two things; the name even describes (with no useful abstraction whatsoever) what those two things are. If iteration and alternation violate the Sacred Principle of Oneness enough to justify separating everything inside any pair of {} then surely sequencing does as well? I&amp;#8217;m mildly surprised that the person who wrote that originally hasn&amp;#8217;t yet died of old age waiting for an infinite recursion to finish! :-/&lt;/p&gt;


	&lt;p&gt;The tragic thing is that while messing around with dogmatic changes to achieve small functions for no particular benefit, the author has missed the wood for the trees. The first question I would ask about the original function is why this code is messing around so much with the details of another object. Tell, don&amp;#8217;t ask:&lt;/p&gt;


&lt;pre&gt;
public void pay()
{
  for (Employee e : employees)
  {
    e.pay();
  }
}
&lt;/pre&gt;

	&lt;p&gt;and on the Employee class:&lt;/p&gt;


&lt;pre&gt;
public void pay()
{
  if (isPayDay())
  {
    deliverPay(payDue());
  }
}
&lt;/pre&gt;

	&lt;p&gt;Then we might consider further improving the function names, but cleaning those up requires knowledge of the context that hasn&amp;#8217;t been provided in this example, so there&amp;#8217;s not much we can do beyond renaming the calculation function to something more appropriate given that its purpose is defined by the value it returns.&lt;/p&gt;


	&lt;p&gt;Of course, this whole example is very artificial, as it&amp;#8217;s unlikely that in a real system an Employee object would know how to make a payment without depending on other parts of the system anyway&amp;#8230;&lt;/p&gt;</description>
      <pubDate>Sun, 14 Jun 2009 00:56:15 -0500</pubDate>
      <guid isPermaLink="false">urn:uuid:20662a32-8880-4c96-996b-8572a525de8f</guid>
      <link>http://blog.objectmentor.com/articles/2009/06/04/refactoring-exercise#comment-3564</link>
    </item>
    <item>
      <title>"Refactoring Exercise" by Chris</title>
      <description>&lt;p&gt;@Philip Schwarz&lt;/p&gt;


	&lt;p&gt;We seem to be overlapping here because of some funny delays in posting, so I don&amp;#8217;t know if you&amp;#8217;d seen my earlier posts that already addressed some of your points when you wrote your latest contribution. I&amp;#8217;ll just briefly comment on a couple of your other points for now.&lt;/p&gt;


	&lt;p&gt;On the subject of Composed Method:&lt;/p&gt;


	&lt;blockquote&gt;
		&lt;p&gt;Divide your program into methods that perform one identifiable task. Keep all of the operations in a method at the same level of abstraction. This will naturally result in programs with many small methods, each a few lines long.&lt;/p&gt;
	&lt;/blockquote&gt;


	&lt;p&gt;The first two principles I completely agree with. This is basic functional decomposition advice that has been around since the programming stone age (though alas many professional developers seem to have forgotten it shortly afterwards in their quest to objectify this and higher level language that).&lt;/p&gt;


	&lt;p&gt;But I can&amp;#8217;t agree with the conclusion. I&amp;#8217;ve worked on code in several fields, from mathematical modelling to instrument control, where it would be perfectly possible to have a function dozens, perhaps even hundreds, of lines long that &lt;em&gt;did&lt;/em&gt; represent a single task with the implementation at the same level of abstraction throughout. Usually the control flow would be quite linear, but subdividing the logic further would just be an artificial break.&lt;/p&gt;


	&lt;p&gt;In any case, as I mentioned before, my objection is not to small functions as such, just to small functions that don&amp;#8217;t really gain us any useful abstraction. To wit, I see a marked contrast between your comments on the Intention Revealing Message pattern with the isEmpty example and Uncle Bob&amp;#8217;s take function that you quoted. In particular, I could immediately guess what isEmpty would mean from the calling code, and while it is only a single line long, it does represent a useful abstraction.&lt;/p&gt;


	&lt;p&gt;On the other hand, despite knowing the general problem area we&amp;#8217;re discussing, I still don&amp;#8217;t see why the names take, dup, enter and accumulate are particularly helpful here. take seems rather arbitrary: neither it nor the name Register provide enough context for it to be a meaningful concept without further information. dup betrays the underlying implementation, while enter randomly obscures the implementation despite operating at the same level of abstraction. The worst is accumulate, which doesn&amp;#8217;t accumulate anything at all, despite having a common meaning along those lines when applied to a sequence in computer science literature; it actually changes the mode (and apparently in a way that only code related to the Register class is permitted to do, though the analogous functions for setting other modes are public). In fact, looking over the entirety of Uncle Bob&amp;#8217;s code again, it is littered with one-liners that are never actually used, yet betray implementation details or at best rename something without providing any additional abstraction.&lt;/p&gt;


	&lt;p&gt;In short, reading Uncle Bob&amp;#8217;s take function, I would have had to look up every single function it called anyway, to drop to a useful level of abstraction and work out what the underlying logic was, completely defeating the point of factoring out the individual routines. However, to work out what other code interacted with the take function, I would also have to analyse all code with access to the same instance of Register because the numerous small, public functions effectively expose the implementation anyway. Whatever happened to &amp;#8220;Tell, don&amp;#8217;t ask&amp;#8221;?&lt;/p&gt;


	&lt;p&gt;As for the small methods vs. increased interactions issue, I don&amp;#8217;t have much to add there. A few consultants can repeat the mantra as often as they like, but the evidence simply doesn&amp;#8217;t support their conclusion. Increasing &lt;em&gt;complexity&lt;/em&gt; is definitely a causal factor in making code harder to understand; this much is well supported by research. Moreover, it seems likely that there is a positive correlation between function length and function complexity, but it doesn&amp;#8217;t follow that small functions automatically help readability. It &lt;em&gt;does&lt;/em&gt; follow, however, that if the functions get so small that the complexity starts to increase because of all the added interactions, this harms readability.&lt;/p&gt;</description>
      <pubDate>Sat, 13 Jun 2009 22:59:14 -0500</pubDate>
      <guid isPermaLink="false">urn:uuid:6f00ca02-5286-4a9c-a47f-3b2cc274ab0a</guid>
      <link>http://blog.objectmentor.com/articles/2009/06/04/refactoring-exercise#comment-3563</link>
    </item>
  </channel>
</rss>

