<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Sam Turner on Medium]]></title>
        <description><![CDATA[Stories by Sam Turner on Medium]]></description>
        <link>https://medium.com/@samturner_23372?source=rss-40589915df5b------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*TKot413feM8aTBnwgpHC-A.png</url>
            <title>Stories by Sam Turner on Medium</title>
            <link>https://medium.com/@samturner_23372?source=rss-40589915df5b------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 24 Nov 2026 10:28:32 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@samturner_23372/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Clutter to Clarity: Turning User Research Into an Actionable Map]]></title>
            <link>https://medium.com/@samturner_23372/clutter-to-clarity-turning-user-research-into-an-actionable-map-eced26798de1?source=rss-40589915df5b------2</link>
            <guid isPermaLink="false">https://medium.com/p/eced26798de1</guid>
            <category><![CDATA[user-research]]></category>
            <category><![CDATA[ux-design]]></category>
            <category><![CDATA[startupş]]></category>
            <category><![CDATA[human-centered-design]]></category>
            <category><![CDATA[lean-startup]]></category>
            <dc:creator><![CDATA[Sam Turner]]></dc:creator>
            <pubDate>Sun, 10 Mar 2024 21:15:54 GMT</pubDate>
            <atom:updated>2024-03-10T22:08:31.719Z</atom:updated>
            <content:encoded><![CDATA[<h3>Problem</h3><p>Our path to clarity began with a maze of unstructured notes. My co-founder, <a href="https://twitter.com/whenyouzhang">Wenyu</a>, and I were sitting on pages of raw data from customer interviews, but we needed a better way to synthesize it.</p><p>We are exploring the business problem of training internal employees such as account managers, sales people, customer success, and operations. We had read <a href="https://www.momtestbook.com/">The Mom Test</a>, which taught us how to ask the right questions to get quality data. However, we were missing the right process to refine that data into valuable insights. It was as if we had struck gold, but we didn’t have the right tool to pan for it.</p><p>We had been capturing important insights in a google doc which had grown into an incomprehensible Frankenstein of notes. The below image shows the outline of that google doc.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*IorTumvXS-yp4ERE" /></figure><p>The problem was that this format lumped together insights from different customer interviews. It abstracted away the context of the insight. For example, a bullet point in the section <em>“What are the pain points and opportunities?”</em> read:</p><blockquote>“Getting information from subject matter experts while taking minimum bandwidth from them”</blockquote><p>We wrote this down when debriefing on one user interview. It made sense to us at the time, but when we re-read it several days later, it was missing context such as:</p><ol><li><strong>Job to be done. </strong>What job is this point related to? Is this part of a sales process? Are we designing a new product feature? Raising money? That’s crucial context. There’s nothing wrong with the sentence, but it wasn’t helpful by itself</li><li><strong>Why does it matter?</strong> Once we know the job, we need to know why it matters. Understanding the problem in the larger context helps us understand how much businesses will pay to solve it. What do you imagine a business will pay more for? A solution that unblocks a mission critical enterprise sales deal or a solution that improves the company picnic.</li><li><strong>Customer segment.</strong> Who did this insight pertain to or come from? It might have come from a freelancer, a CEO of a scaling SaaS business, an HR director of a large enterprise, or someone else.</li><li><strong>Stakeholders and motivations.</strong> In a B2B context, multiple people are often involved in the purchase of a new product. Who else is involved or impacted by this subject matter expert’s work? It’s important to understand who they are and their motivations to successfully close deals.</li></ol><h3>Solution</h3><p>We needed a framework that let us capture key insights from user interviews without losing the context. Humans are naturally wired to remember stories better than abstract concepts. So we used Miro to define a framework that captured each interviewee’s story.</p><p>Below is a simplified, contrived example of what this story might look like for one interview. It’s much shorter than what we actually created.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*M-UbAW3fLEiIrWXp" /></figure><p>Notice this one row tells the person’s story — <em>from the perspective of the job to be done</em>. It is complete with a protagonist, beginning, middle, end, and even conflict. Other information is context that sets the scene for the story.</p><p>Let’s walk through each column.</p><ol><li><strong>Interviewee</strong>: This is the protagonist of the story. It tells you whose point of view the story is being told from.</li><li><strong>Customer segment</strong>: Relevant user segmentation data here such as company size and industry will help provide the setting for the story. Later, we can compare stories that have similar settings to think about aggregates of people and stories.</li><li><strong>Stakeholders &amp; motivations</strong>: In B2B sales, you need to get multiple stakeholders aligned before making a sale. So it’s important to understand who these stakeholders are and what they care about. What is the answer to “so why do I care?” for each person?</li><li><strong>Job To Be Done</strong>: This column is the centerpiece of the research. It’s a place to break down one of the interviewee’s jobs step-by-step. We had two important learnings while working on this column. (a) Tagging each job with “why it matters” forces us to consider whether the job is important enough to invest in a solution that improves it. (b) Tagging the pain points in a different color allowed us to quickly see at a glance opportunities for improvement.</li><li><strong>Gotchas</strong>: These are the potential reasons why building a product around this job might fail.</li><li><strong>Crazy Ideas</strong>: While we reviewed notes together, we thought of different product ideas. So we captured these ideas to refer back to them later in the design process. Calling it “Crazy Ideas” gave us a license to go wild.</li><li><strong>Follow Up Questions</strong>: Capture additional questions you have for the interviewee here. Sometimes we’ll email 2–6 questions to the interviewee as a follow up.</li></ol><h3>Key Takeaways</h3><p>Framing each user interview as a story allowed us to turn pages of user interview notes into clear, concise, actionable insights. It allowed us to better understand the lives of these users and to build empathy with them.</p><p>This process did add time to our user interview debriefs. However, this extra time was well worth it because we found ourselves learning faster. The goal is to truly understand a job to be done, and going deep was more helpful than churning through as many interviews as possible. In addition, after our first few debriefs, we developed a foundation of knowledge and each additional debrief took less time.</p><p>Now that my co-founder and I have a solid understanding of the lives of these users, we are one step closer to building a product that will make their lives better. Our next step is to review these insights and select the right pain point to solve.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=eced26798de1" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[All About Service Objects: Part 2 — Method Object Pattern]]></title>
            <link>https://medium.com/@samturner_23372/all-about-service-objects-part-2-method-object-pattern-fc2b4fb90b20?source=rss-40589915df5b------2</link>
            <guid isPermaLink="false">https://medium.com/p/fc2b4fb90b20</guid>
            <category><![CDATA[design-patterns]]></category>
            <category><![CDATA[method-object]]></category>
            <category><![CDATA[ruby]]></category>
            <category><![CDATA[refactoring]]></category>
            <category><![CDATA[rails]]></category>
            <dc:creator><![CDATA[Sam Turner]]></dc:creator>
            <pubDate>Sun, 27 Mar 2022 15:19:19 GMT</pubDate>
            <atom:updated>2022-03-27T15:19:19.828Z</atom:updated>
            <content:encoded><![CDATA[<h3>All About Service Objects: Part 2 — Method Object Pattern</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VFDpE4MtugJZO4qNWhkpUQ.jpeg" /><figcaption>Photo by <a href="https://unsplash.com/@jontyson?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Jon Tyson</a> on <a href="https://unsplash.com/s/photos/productive?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Unsplash</a></figcaption></figure><p>Part 1 of this series outlined the benefits of <a href="https://medium.com/@samturner_23372/all-about-service-objects-part-1-rails-controllers-63a7184d217a">service objects in Rails controllers</a>. This post describes a cousin of service objects called method objects.</p><p>A method object looks just like a service object. It is a Ruby object that performs a single action.</p><pre>class Payment<br>  def charge_for_brunch(<br>    split_line_items:,<br>    not_split_line_items:,<br>    guests:,<br>    sales_tax_rate:,<br>    tip_rate:<br>  )<br>    guest_totals = BrunchSplitter.call(<br>      split_line_items: split_line_items,<br>      not_split_line_items: not_split_line_items,<br>      guests: guests,<br>      sales_tax_rate: sales_tax_rate,<br>      tip_rate: tip_rate<br>    )<br><br>    guest_totals.each do |guest, total|<br>      charge(guest, total)<br>    end<br>  end<br><br>  def charge(guest, total)<br>    ...<br>  end<br>end</pre><p>The method object in the above example is “BrunchSplitter”. This class has a single method. In this example, the single method is “.call”, but it might also be named “.compute”.</p><p>Method objects and service objects are so similar that in practice, the terms are used interchangeably. The difference is that a method object implies a specific purpose. In Kent Beck’s book Smalltalk Best Practices, he describes method objects as a tool to implement the Replace Method with Method Object.</p><p>Method objects allow developers to apply the Extract Method refactoring pattern when entangling local variables make it difficult. Probably none of that made sense, but we’ll break it down step-by-step by discussing:</p><ol><li>Why extract a long method into smaller methods?</li><li>How do local variables make it difficult to extract methods?</li><li>How do method objects help?</li><li>What are the disadvantages of method objects?</li></ol><h3>Problems with long methods</h3><p>Software design principles emphasize breaking up long methods into smaller ones. This is called the Extract Method refactoring pattern, and it has several benefits:</p><ol><li>Promotes code reuse</li><li>Improves clarity by allowing higher-level methods to read like a series of steps</li></ol><p>Let’s walk through a non-code example together. Imagine you are hired as an assistant baker. Your first task is to buy eggs, so your boss hands you these instruction:</p><pre>1. Head out the front door<br>2. Walk 5 blocks north to 8th ave<br>3. Walk 3 blocks east to 57th street<br>4. Locate the main entrance to the Columbus Circle center<br>5. Go down the escalator to the whole foods<br>6. Turn left<br>7. Walk to aisle 8<br>8. Locate any organic eggs<br>9. Add 2 dozen eggs to your shopping cart<br>10. Walk back towards the escalator<br>11. Locate the checkout<br>12. Get in line to checkout<br>13. Wait to get to the front of the line<br>14. Hand the eggs to the cashier<br>15. Wait for the cashier to scan the eggs<br>16. Take out the provided company credit card<br>17. Tap to pay<br>18. If prompted, enter the passcode provided<br>19. Wait for the payment to complete</pre><p>These instructions might be correct, but how comprehensible are they? Not very. There are a few problems:</p><ul><li>Takes too long to read from beginning to end.</li><li>Important points are overshadowed by the details.</li><li>All 19 steps won’t fit in most people’s short-term memories. As you are following the instructions, you will constantly be referring back to the list for the next step.</li></ul><p>In short, these instructions are incomprehensibly precise.</p><p>Let’s take a look at a different set of instructions.</p><pre>1. Go to the whole foods at the columbus shopping center<br>2. Pick up 2 dozen organic eggs<br>3. Pay using the company credit card</pre><p>Compared to the first set, these instructions:</p><ul><li>Can be read quickly</li><li>Only include the important details</li><li>Can fit in short-term memory</li></ul><p>These are human readable instructions. Rather than listing every step precisely, it focuses on three simple objectives. It allows you to fill in the details of how to complete each.</p><p>It works because people are familiar with concepts like “going to the grocery store” or “paying using the company credit card”. These tasks don’t require further explanation. Further detail is not only unnecessary, it’s overwhelming.</p><p>Computers, on the other hand, don’t understand these concepts. Computers need precise instructions like the first list. So software applications inevitably contain incomprehensibly precise instructions.</p><p>But as developers, we aren’t just writing software that needs to be understandable computers. It also need to be understandable by the humans who will read, maintain, and change the instructions in the future.</p><h3>Breaking up a long method</h3><p>The Extract Method pattern makes code more readable by taking precise instructions that a computer understands and grouping them into human understandable concepts.</p><p>Let’s imagine we are building an app that makes it easy to split the cost of brunch with your friends. Glance at the below code and then ask yourself:</p><ol><li>How does it split the cost of brunch?</li></ol><pre>class Payments<br>  def split_brunch(<br>    split_line_items:, <br>    not_split_line_items:, <br>    guests:, <br>    sales_tax_rate:, <br>    tip_rate:<br>  )<br>    guest_totals = {}<br>    guests.each { |guest| guest_totals[guest] = 0 }<br>    guest_totals<br><br>    pretax_total = split_line_items.sum { |line_item| line_item[:pretax_amount] }<br>    pretax_total_per_guest = (pretax_total / guests.length).round(2)<br><br>    guests.each do |guest|<br>      guest_totals[guest] = pretax_total_per_guest<br>    end<br><br>    not_split_line_items.each do |line_item|<br>      pretax_amount = line_item[:pretax_amount]<br>      guest = line_item[:assigned_to]<br><br>      guest_totals[guest] = guest_totals[guest] + pretax_amount<br>    end<br><br>    guest_totals.map do |guest, pretax_amount|<br>      total_after_tax_and_tip = pretax_amount +<br>        (pretax_amount * sales_tax_rate) +<br>        (pretax_amount * tip_rate)<br><br>      [guest, total_after_tax_and_tip.round(2)]<br>    end.to_h<br>  end<br>end</pre><p>This code looks more like the incomprehensibly precise list. A computer will have no problem interpreting these instructions, but it’s an overwhelming level of detail for a human.</p><ol><li><strong>How does it split the cost of brunch?</strong> Not clear.</li></ol><p>Now let’s apply the Extract Method pattern to make the code more human readable.</p><pre>class Payments<br>  def split_brunch(<br>    split_line_items:, <br>    not_split_line_items:, <br>    guests:, <br>    sales_tax_rate:, <br>    tip_rate:<br>  )<br>    guest_totals = empty_amounts_for(guests)<br>    assign_split_items_to_guests(<br>      split_line_items, <br>      guest_totals, <br>      guests<br>    )<br>    assign_not_split_items_to_guests(<br>      not_split_line_items, <br>      guest_totals<br>    )<br>    add_tax_and_tip(<br>      guest_totals, <br>      sales_tax_rate, <br>      tip_rate<br>    )<br>  end<br><br>  private<br><br>  def empty_amounts_for(<em>guests</em>)<br>    ...<br>  end</pre><pre>  def assign_split_items_to_guests(line_items, guest_totals, guests)<br>    ...<br>  end</pre><pre>  def assign_not_split_items_to_guests(line_items, guest_totals)<br>    ...<br>  end<br><br>  def add_tax_and_tip(guest_totals, sales_tax_rate, tip_rate)<br>    ...<br>  end<br>end</pre><ol><li><strong>How does it split the cost of brunch?</strong> The top level method lists the high level steps: (i) handling the items that are not split; (ii) handling the split items; (iii) adding tax &amp; tip.</li></ol><p>We started with code that resembled the incomprehensibly precise instructions. This new iteration still includes those precise steps, but they are summarized into human understandable instructions in the top-level method.</p><h3>Problem with local variables</h3><p>It can be difficult to apply the Extract Method pattern when there is an entangled mess of local variables that are hard to isolate from each other. These local variables need to be passed from method to method. As the parameter list grows, the code becomes more difficult to reason about. It’s a code smell called Long Parameter List.</p><p>This is where method objects finally come into play.</p><p>Let’s apply the method object pattern to our own code. Start by turning the method into its own object. The parameters are passed in as instance variables so they don’t need to be passed around between local method calls.</p><pre>class BrunchSplitter<br>  def self.call(*args)<br>    new(*args).call<br>  end<br><br>  def initialize(<br>    split_line_items, <br>    not_split_line_items, <br>    guests, <br>    sales_tax_rate, <br>    tip_rate<br>  )<br>    @split_line_items = split_line_items<br>    @not_split_line_items = not_split_line_items<br>    @guests = guests<br>    @sales_tax_rate = sales_tax_rate<br>    @tip_rate = tip_rate<br>  end<br><br>  def call<br>    assign_split_items_to_guests<br>    assign_not_split_items_to_guests<br>    add_tax_and_tip<br>  end<br><br>  private<br><br>  def assign_split_items_to_guests<br>    ...<br>  end<br><br>  def assign_not_split_items_to_guests<br>    ...<br>  end<br><br>  def add_tax_and_tip<br>    ...<br>  end<br><br>  def guest_totals<br>    ...<br>  end<br>end</pre><p>BrunchSplitter#call no longer needs to pass around local variables. This makes the high level steps even more clear because they aren’t obfuscated by the arguments.</p><p>If you are looking for a Ruby gem to implement the method object pattern, I recommend <a href="https://github.com/ClayShentrup/method_man">method_man</a> written by <a href="https://clayshentrup.medium.com/">Clay Shentrup</a>.</p><h3>Costs of breaking up a long method</h3><p>As with most design choices, extracting methods is not free. Creating a new method or method object comes with a cost. Both add another level of indirection.</p><p>If the developer wants to learn how the method or method object was implemented, they need to jump to a different location in the app.</p><p>Think of the method object as another tool in your software engineering toolbelt. Apply it only when the benefits outweigh the costs.</p><h3>Next steps</h3><p>Method objects are like service objects that serve a specific purpose. They allow us to extract a long method into smaller ones even when entangling local variables make it difficult.</p><p>Part 1 and 2 of this series focussed on the benefits of service &amp; method objects. But they are only tools, and like any tool, they can be overused. In the final part of this series, we’ll look at an alternative to service &amp; method objects — domain objects.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=fc2b4fb90b20" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Verify Your Partial Doubles in RSpec]]></title>
            <link>https://medium.com/@samturner_23372/verify-your-partial-doubles-in-rspec-5c4e9b3a86d5?source=rss-40589915df5b------2</link>
            <guid isPermaLink="false">https://medium.com/p/5c4e9b3a86d5</guid>
            <category><![CDATA[rspec]]></category>
            <category><![CDATA[ruby]]></category>
            <category><![CDATA[rails]]></category>
            <category><![CDATA[software-development]]></category>
            <dc:creator><![CDATA[Sam Turner]]></dc:creator>
            <pubDate>Sun, 06 Mar 2022 21:26:25 GMT</pubDate>
            <atom:updated>2022-03-06T21:26:25.496Z</atom:updated>
            <content:encoded><![CDATA[<p><strong>Verifying Partial Doubles in RSpec</strong></p><p>When writing isolated unit tests, we often stub methods on classes which are not under test. Take the following snippet of code for example.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4bd7dc29464e81c621e95efa7c4116cd/href">https://medium.com/media/4bd7dc29464e81c621e95efa7c4116cd/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/07a7fc13398e18aa7b506f8cf4785aa7/href">https://medium.com/media/07a7fc13398e18aa7b506f8cf4785aa7/href</a></iframe><p>Suppose we want to write an isolated unit test for Owner.tell_dog_to_sit which depends on Dog.sit to implement its behavior. We may decide to stub Dog.sit for the sake of isolating the class under test.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b599f08568d00c1d9330d74352627caf/href">https://medium.com/media/b599f08568d00c1d9330d74352627caf/href</a></iframe><pre><strong>Owner</strong><br>  <strong>PASS</strong>: tells the dog to sit</pre><pre>2.4.2 :001 &gt; <strong>Owner.tell_dog_to_sit</strong><br> =&gt; true</pre><p>As we expect, this spec passes without issue. However, we’ve introduced a subtle risk.</p><h3>Problem with partial doubles</h3><p>Imagine that in the future, we change the interface of Dog.sit to Dog.stay.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/43c82d849c2da7d5779b4bf0ade3bdb2/href">https://medium.com/media/43c82d849c2da7d5779b4bf0ade3bdb2/href</a></iframe><p>The problem is that if we neglect to update Owner to depend on the new interface, our test still passes. Since we are stubbingDog.sit (the old interface) in our test, the stub masks the error in Owner.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b599f08568d00c1d9330d74352627caf/href">https://medium.com/media/b599f08568d00c1d9330d74352627caf/href</a></iframe><pre><strong>Owner</strong><br>  <strong>PASS</strong>: tells the dog to sit</pre><pre>2.4.2 :001 &gt; <strong>Owner.tell_dog_to_sit</strong><br> =&gt; NoMethodError: undefined method `sit&#39; for Dog:Class</pre><p>Our test is no longer an accurate reflection of our code’s runtime behavior. It only serves to give us a false sense of assurance.</p><p>Stubbed methods mask a number of inconsistencies between the stub and method being stubbed.</p><ol><li>Incorrect method name</li><li>Wrong number of arguments</li><li>Missing keyword arguments</li></ol><p>Suppose we extend our Dog class to perform the following tricks.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6039e22acba5fdd46856dc8544d11832/href">https://medium.com/media/6039e22acba5fdd46856dc8544d11832/href</a></iframe><p>Obviously, we want the owner to be able to tell the Dog to perform those tricks. But in our haste to implement this highly demanded feature, we make a couple of silly mistakes.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1241c5badcb790751f7d5ab3e6f6194f/href">https://medium.com/media/1241c5badcb790751f7d5ab3e6f6194f/href</a></iframe><pre><strong>Owner</strong><br>  <strong>PASS:</strong> tells the dog to sit<br>  <strong>PASS:</strong> tells the dog to roll over<br>  <strong>PASS:</strong> tells the dog to retrieve an item</pre><pre>2.4.2 :001 &gt; <strong>Owner.tell_dog_to_sit</strong><br> =&gt; NoMethodError: undefined method `sit&#39; for Dog:Class</pre><pre>2.4.2 :002 &gt; <strong>Owner.tell_dog_to_roll_over</strong><br> =&gt; ArgumentError: wrong number of arguments (given 0, expected 1)</pre><pre>2.4.2 :003 &gt; <strong>Owner.tell_dog_to_retrieve_item</strong><br> =&gt; ArgumentError: missing keyword: item</pre><p>We are left in a state where our tests pass, but our code fails miserably at runtime. In order to solve this problem, we need a way to verify that our stubs are consistent with the methods implemented on the stubbed class.</p><h3>Solution: Partial doubles verification</h3><p>RSpec 3+ gives us a solution to this problem. We can enable verification of test doubles to ensure that any stubbed methods exist on the stubbed class.</p><p>For backwards compatibility reasons, RSpec disables this feature by default. You should enable it unless you have a good reason not to.</p><p>To enable partial doubles verification, add this code to spec_helper.rb .</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/cb6eddbd343af493a4f825f3eb409268/href">https://medium.com/media/cb6eddbd343af493a4f825f3eb409268/href</a></iframe><p>Verifying partial doubles exposes stubs that are inconsistent with the method being stubbed. This includes the three different types of inconsistencies we described.</p><ol><li>Incorrect method name</li><li>Wrong number of arguments</li><li>Missing keyword arguments</li></ol><p>After enabling partial doubles verification, the results of our tests match the results of our code at runtime.</p><pre><strong>Owner</strong><br>  <strong>ERROR: </strong>tells the dog to sit<br>    Failure/Error: Dog does not implement: sit<br>  <strong>ERROR: </strong>tells the dog to roll over<br>    ArgumentError: Wrong number of arguments. Expected 1, got 0.<br>  <strong>ERROR:</strong> tells the dog to retrieve an item<br>    ArgumentError: Missing required keyword arguments: item</pre><pre>2.4.2 :001 &gt; <strong>Owner.tell_dog_to_sit</strong><br> =&gt; NoMethodError: undefined method `sit&#39; for Dog:Class</pre><pre>2.4.2 :002 &gt; <strong>Owner.tell_dog_to_roll_over</strong><br> =&gt; ArgumentError: wrong number of arguments (given 0, expected 1)</pre><pre>2.4.2 :003 &gt; <strong>Owner.tell_dog_to_retrieve_item</strong><br> =&gt; ArgumentError: missing keyword: item</pre><p>The tests once again serve the purpose for which they were written. They call attention to errors in our application code, and we have a chance to fix them before the code goes to production.</p><p>When you enable partial doubles verification, some of your existing tests may start failing. Don’t be surprised. That is normal.</p><p>If your application is large, you may be surprised by just how many tests fail after enabling partial doubles verification. In fact, the number may be so large, that it will be impractical to fix all bugs in a single sitting.</p><h3><strong>Implementing partial doubles verification the agile way</strong></h3><p>One approach is to correct these failing specs gradually. RSpec allows you to disable partial doubles verification for specific tests.</p><p><strong>RSpec &gt;= 3.6</strong></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b77b37b09f2bf3ba4762cc2db47d18f6/href">https://medium.com/media/b77b37b09f2bf3ba4762cc2db47d18f6/href</a></iframe><p><strong>RSpec &lt; 3.6</strong></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c0647b7d1184a542da5f6c68571ec9d5/href">https://medium.com/media/c0647b7d1184a542da5f6c68571ec9d5/href</a></iframe><p>The benefit of this approach is that it will prevent additional bugs from slipping past your newly written tests. You can gradually fix old specs when you have a spare moment here or there. (I personally prefer to do it when I’m waiting for approval on an outstanding PR.)</p><p>Whatever approach you choose, enabling partial doubles verification will put you on a path to improved confidence in your test suite.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5c4e9b3a86d5" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[All About Service Objects: Part 1 - Rails Controllers]]></title>
            <link>https://medium.com/@samturner_23372/all-about-service-objects-part-1-rails-controllers-63a7184d217a?source=rss-40589915df5b------2</link>
            <guid isPermaLink="false">https://medium.com/p/63a7184d217a</guid>
            <category><![CDATA[design-patterns]]></category>
            <category><![CDATA[refactoring]]></category>
            <category><![CDATA[clean-code]]></category>
            <category><![CDATA[agile]]></category>
            <category><![CDATA[rails]]></category>
            <dc:creator><![CDATA[Sam Turner]]></dc:creator>
            <pubDate>Sun, 23 Jan 2022 18:30:54 GMT</pubDate>
            <atom:updated>2022-02-20T18:42:52.173Z</atom:updated>
            <content:encoded><![CDATA[<p>A service object is simply a Ruby object that performs a single action. It encapsulates some business logic, and they are often found in controllers like this one.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fcarbon.now.sh%2Fembed%2FAspMAh8j8sKf6b8EgTOU%3F&amp;display_name=Carbon&amp;url=https%3A%2F%2Fcarbon.now.sh%2FAspMAh8j8sKf6b8EgTOU&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=carbon" width="1024" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/26cb222ea1fe4ad8c01bb5d462d1d438/href">https://medium.com/media/26cb222ea1fe4ad8c01bb5d462d1d438/href</a></iframe><p>The service object is called on line 4. Notice the class name is the action performed— “ValidateDiscountCode”. The class has a single method “.call”.</p><p>A service object is just another tool in your software engineering tool belt. To use it effectively, it’s important to understand its purpose, advantages, disadvantages, and alternatives. It’s similar to the way an electrician must decide between using a screwdriver or a power drill.</p><p>This is the first of a three part series that will answer these questions about service objects:</p><ol><li>What is its purpose?</li><li>What are the advantages?</li><li>What are the disadvantages?</li><li>What are the alternatives?</li></ol><p>This first post describes the benefits of using service objects in Rails controllers. Part two describes a separate purpose for service objects: applying the method object pattern. The final post discusses the disadvantages and alternatives to service objects.</p><h3>Problem</h3><p>As an application grows, it’s common for business logic to start creeping into controllers. Let’s walk through an example by rewinding the clock to a time when our discount controller did not use a service object.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fcarbon.now.sh%2Fembed%2Fq6T4KQefKuzOQcq0qOD2%3F&amp;display_name=Carbon&amp;url=https%3A%2F%2Fcarbon.now.sh%2Fq6T4KQefKuzOQcq0qOD2&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=carbon" width="1024" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/bb269731dee2b43405fd1e347f7739c0/href">https://medium.com/media/bb269731dee2b43405fd1e347f7739c0/href</a></iframe><p>It’s only 16 lines of code, but already, we find business logic in the controller. It knows that a valid discount code must meet two conditions:</p><ol><li>Must exist in the database.</li><li>Expiration date must be in the past.</li></ol><p>Business logic in controllers is a problem for several reasons.</p><h4>Problem #1: Violates single responsibility principle</h4><p>The single responsibility principle means each class should have one single purpose. The controller’s purpose is to handle requests. It knows how to understand requests and respond appropriately.</p><p>Understanding discount code validation rules is outside the scope of the controller.</p><h4>Problem #2: Not reusable</h4><p>Business logic in the controller is not reusable. As the application grows, more things will need to know how to validate a discount code. Without a centralized class that defines these conditions, they will be scattered over the codebase.</p><p>Now imagine we need to change the conditions. Perhaps we must add a rule that a discount code can only be used once. This new rule will need to be added to everything that knows about the existing rules — making this change more difficult.</p><p>This is called shotgun surgery. It’s a code smell in which a single conceptual change requires many small changes across the codebase.</p><h4>Problem #3: Slows test performance</h4><p>These are our tests for the discount controller.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fcarbon.now.sh%2Fembed%2Fi5hSUVRcGdmoDL7v3qMC%3F&amp;display_name=Carbon&amp;url=https%3A%2F%2Fcarbon.now.sh%2Fi5hSUVRcGdmoDL7v3qMC&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=carbon" width="1024" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/a89e181f2c603eeb2184baaaa5038ecb/href">https://medium.com/media/a89e181f2c603eeb2184baaaa5038ecb/href</a></iframe><p>Notice line #1 “require ‘rails_helper’”. In order to run these specs, Rails must be loaded into memory. This slows down test performance. This performance hit can be mitigated by using a pre-loader like <a href="https://github.com/rails/spring">spring</a>, but it’s still going to be slower than running the specs without Rails.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fcarbon.now.sh%2Fembed%2FC13WwYVxMgw1H8QR6igL%3F&amp;display_name=Carbon&amp;url=https%3A%2F%2Fcarbon.now.sh%2FC13WwYVxMgw1H8QR6igL&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=carbon" width="1024" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/aa0cdb714946970b4e112cc2487bccc9/href">https://medium.com/media/aa0cdb714946970b4e112cc2487bccc9/href</a></iframe><p>Even with spring, it takes almost two seconds to run these tests (1.2 seconds to load + 0.69 seconds to run). That might not seem like a long time, but if you are running your tests constantly, it noticeably slows down development. When tests become exceedingly slow, developers may decide it’s not worth it to run them often.</p><h3>Solution</h3><p>One way to extract the business logic out of the controller is to move it into a new class.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fcarbon.now.sh%2Fembed%2FP8Fw7ueOUddD5oAJRCQx%3F&amp;display_name=Carbon&amp;url=https%3A%2F%2Fcarbon.now.sh%2FP8Fw7ueOUddD5oAJRCQx&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=carbon" width="1024" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/3661b7f9a98668dbac30c31b03730521/href">https://medium.com/media/3661b7f9a98668dbac30c31b03730521/href</a></iframe><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fcarbon.now.sh%2Fembed%2FnTEeTZlZCwbWdHGCCbQw%3F&amp;display_name=Carbon&amp;url=https%3A%2F%2Fcarbon.now.sh%2FnTEeTZlZCwbWdHGCCbQw&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=carbon" width="1024" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/c58dadb755dd49c268cfdf33561edd8e/href">https://medium.com/media/c58dadb755dd49c268cfdf33561edd8e/href</a></iframe><p>Let’s walkthrough how this new code solves the three problems presented by version 1.</p><h4>Problem #1: Violates single responsibility principle</h4><p>Solved.</p><p>The controller no longer knows about discount validation rules. It can simply call the new class and render the appropriate response.</p><h4>Problem #2: Business logic not reusable</h4><p>Solved.</p><p>The discount code validation rules now live in a single class. If any other class needs to know if a discount code is valid, it can simply call the new class.</p><h4>Problem #3: Slow test performance</h4><p>Improved.</p><p>Let’s take a look at our new specs after introducing the service object.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fcarbon.now.sh%2Fembed%2FC957cIjbU8HgA6pgUOjk%3F&amp;display_name=Carbon&amp;url=https%3A%2F%2Fcarbon.now.sh%2FC957cIjbU8HgA6pgUOjk&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=carbon" width="1024" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/3cc7b4ac88d3ce12f45879a27569dac5/href">https://medium.com/media/3cc7b4ac88d3ce12f45879a27569dac5/href</a></iframe><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fcarbon.now.sh%2Fembed%2F4VKAWQHVY4HC0sA5Ulcg%3F&amp;display_name=Carbon&amp;url=https%3A%2F%2Fcarbon.now.sh%2F4VKAWQHVY4HC0sA5Ulcg&amp;key=d04bfffea46d4aeda930ec88cc64b87c&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=carbon" width="1024" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/3ca17830dbb38b3e426251ec62026d38/href">https://medium.com/media/3ca17830dbb38b3e426251ec62026d38/href</a></iframe><p>The number of specs in the controller has dropped from three to two because there are now only two codepaths in the controller — one for valid and one for invalid. The controller no longer knows about the ways in which a discount code can be valid or invalid. This logic moved to ValidateDiscountCode.</p><p>The big win here is when the discount code validation rules change, only the ValidateDiscountCode specs need to be run, and these specs run faster than the controller specs.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fcarbon.now.sh%2Fembed%2F1Du1XBRmCj6HQp8rc3MY%3F&amp;display_name=Carbon&amp;url=https%3A%2F%2Fcarbon.now.sh%2F1Du1XBRmCj6HQp8rc3MY&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=carbon" width="1024" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/1c4e65f57755296206bb783afb147189/href">https://medium.com/media/1c4e65f57755296206bb783afb147189/href</a></iframe><p>The ValidateDiscountCode specs run one second faster (using spring) than the old controller specs. Faster tests provide faster feedback.</p><p>The test performance can be improved even further. The ValidateDiscountCode specs are slowed down significantly by the dependency on Rails. If we can remove this dependency, these tests become lightning fast.</p><p>The challenge is removing the internal references to Rails methods. In this case, ValidateDiscountCode references the active record method “.find_by”. There are a number of ways to remove this dependency. Each approach has pros &amp; cons, but describing them all is beyond the scope of this article.</p><p>Just to see how much faster these specs run without Rails, let’s remove it using dependency injection.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fcarbon.now.sh%2Fembed%2FbVUPdTgV5Qo2I2NNX8nC%3F&amp;display_name=Carbon&amp;url=https%3A%2F%2Fcarbon.now.sh%2FbVUPdTgV5Qo2I2NNX8nC&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=carbon" width="1024" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/78a79a722638a4b9d95cbf413b9ba7d2/href">https://medium.com/media/78a79a722638a4b9d95cbf413b9ba7d2/href</a></iframe><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fcarbon.now.sh%2Fembed%2FrwPqIVtxRskRSiokiV2V%3F&amp;display_name=Carbon&amp;url=https%3A%2F%2Fcarbon.now.sh%2FrwPqIVtxRskRSiokiV2V&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=carbon" width="1024" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/9945759b057002b3e2523d9551c28e1d/href">https://medium.com/media/9945759b057002b3e2523d9551c28e1d/href</a></iframe><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fcarbon.now.sh%2Fembed%2FxJeBjCNVgbUGUHNWHaDX%3F&amp;display_name=Carbon&amp;url=https%3A%2F%2Fcarbon.now.sh%2FxJeBjCNVgbUGUHNWHaDX&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=carbon" width="1024" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/436e6d4fdef534b3ede9a4fc63556195/href">https://medium.com/media/436e6d4fdef534b3ede9a4fc63556195/href</a></iframe><p>Decoupling ValidateDiscountCode from Rails improves test performance by 5X without the need for spring.</p><p>One caveat to this approach is that it can be difficult to maintain this decoupling. Rails provides a lot of useful functionality. So you might decide the functionality offered by Rails is worth slower test performance. Treat this pattern like any other tool in your toolbox, and use it when it makes sense for your situation.</p><h3>Final Improvements</h3><p>You might have noticed that ValidateDiscountCode doesn’t look exactly like a service object yet. It creates an instance by call “.new”, and then it calls “#call” on that instance. When using a service object, typically “.call” is called directly.</p><p>You will also notice the instance of ValidateDiscountCode is never actually used again. So creating an instance within the controller adds no value, and instead, we can just call “.call” directly.</p><p>This new approach has the advantage of narrowing the interface. The controller now knows even less about ValidateDiscountCode which promotes decoupling.</p><p>It also improves the testability of this code. In the previous version, both “.new” and “#call” needed to be stubbed in the controller specs.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fcarbon.now.sh%2Fembed%2F4VKAWQHVY4HC0sA5Ulcg%3F&amp;display_name=Carbon&amp;url=https%3A%2F%2Fcarbon.now.sh%2F4VKAWQHVY4HC0sA5Ulcg&amp;key=d04bfffea46d4aeda930ec88cc64b87c&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=carbon" width="1024" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/3ca17830dbb38b3e426251ec62026d38/href">https://medium.com/media/3ca17830dbb38b3e426251ec62026d38/href</a></iframe><p>By creating a class method “.call” and calling it directly, we can eliminate the stub on “.new”, and we now have a fully featured service object.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fcarbon.now.sh%2Fembed%2FAspMAh8j8sKf6b8EgTOU%3F&amp;display_name=Carbon&amp;url=https%3A%2F%2Fcarbon.now.sh%2FAspMAh8j8sKf6b8EgTOU&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=carbon" width="1024" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/26cb222ea1fe4ad8c01bb5d462d1d438/href">https://medium.com/media/26cb222ea1fe4ad8c01bb5d462d1d438/href</a></iframe><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fcarbon.now.sh%2Fembed%2Fydu460zBZ3llckKeaXKs%3F&amp;display_name=Carbon&amp;url=https%3A%2F%2Fcarbon.now.sh%2Fydu460zBZ3llckKeaXKs&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=carbon" width="1024" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/be031afafd8bfa37f382b1bd8d087dbf/href">https://medium.com/media/be031afafd8bfa37f382b1bd8d087dbf/href</a></iframe><h3>Summary</h3><p>Let’s recap the iterations of this code and the wins we achieved along the way.</p><ol><li>Started with a controller entangled with business logic</li><li>Extracted business logic into a new class — ValidateDiscountCode</li></ol><ul><li>WIN: Respects single responsibility principle</li><li>WIN: Promotes code reuse</li></ul><p>3. Decoupled new classes from Rails</p><ul><li>WIN: Improved test performance</li></ul><p>4. Narrowed the interface for the new class (making it a true service object)</p><ul><li>WIN: Improved testability</li></ul><h3>Next Steps</h3><p>Using services objects in controllers can make our code more readable, reusable, and testable. You may have already guessed that this pattern doesn’t only apply to controllers. It can be used to pulled business logic out of any class where it doesn’t belong.</p><p>In the second part of this series, we’ll discuss a different use case for service objects — implementing the method object pattern.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=63a7184d217a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[A Nontechnical Explanation of Technical Debt]]></title>
            <link>https://medium.com/@samturner_23372/a-nontechnical-explanation-of-technical-debt-1505b40b0401?source=rss-40589915df5b------2</link>
            <guid isPermaLink="false">https://medium.com/p/1505b40b0401</guid>
            <category><![CDATA[user-experience-design]]></category>
            <category><![CDATA[indiehackers]]></category>
            <category><![CDATA[entrepreneurship]]></category>
            <category><![CDATA[product-management]]></category>
            <category><![CDATA[software-development]]></category>
            <dc:creator><![CDATA[Sam Turner]]></dc:creator>
            <pubDate>Mon, 01 Apr 2019 00:56:56 GMT</pubDate>
            <atom:updated>2019-04-02T03:26:41.040Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*H6jFRkONOq4a_MrKYsiOVg.png" /></figure><p>You are a product manager at your morning stand-up meeting waiting for one of your developers to give you an estimate on how long a new feature will take to ship. It is a relatively simple feature compared to the features your team has shipped in the past. So it should not take more than a day or two. Three tops.</p><p>When you ask the developer for an estimate, you see her take a deep breath and cringe slightly.</p><p>“2–3 weeks. That area of the code has a lot of technical debt, so we’ll have to do some refactoring.”</p><p>Oh no. The dreaded “r” word. For nontechnical team members, I assume refactoring translates roughly to “I’m going to spend a lot of time making the code look nice and not ship any features.”</p><p>This interpretation is totally understandable. After all, customers don’t care about the code quality. They care that it improves the quality of their lives. Why should we spend two weeks refactoring now when we could be working on features that customers will pay for?</p><p>I’ve personally experienced both perspectives. I’ve been the developer cringing while giving this estimate, and years ago, I was the sales guy waiting for the developers to ship the next feature that we could sell for real cash.</p><p>Now that I have a little more wisdom, I want to breakdown technical debt in a nontechnical way. More importantly, I want to give you the chance to feel the same pain that technical debt causes developers to feel.</p><p><strong>What is technical debt?</strong></p><p>The name of the game in software development is managing complexity. As products become feature rich, the tendency is for the software to become more and more complex. Eventually, this complexity slows down development cycles because software developers need to spend more time reasoning about the existing code to make the next change.</p><p>Let’s walk through an analogy together to illustrate what technical debt looks and feels like to software developers.</p><p>Imagine we are running an online delivery service. Since the product is new, its features are currently limited. Customers can simply click on a button and have pizza delivered.</p><p>Think of the code that powers this delivery application like a maze. There is a path that leads from input (“customer clicks button”) to output (“deliver pizza”). Since we only have one feature (ie. one path), the maze is simple to reason about. However, like all software projects we’ll see how the complexity of the maze will grow as we add more features.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LsQv935clIWvEveI9n29dA.jpeg" /><figcaption>Iteration #1</figcaption></figure><p>Now let’s say that we want to add a prime service. Customers can pay extra money for a prime membership to have their pizzas delivered fast. Otherwise, we will deliver their pizzas at the normal rate. Implementing this new feature in the maze might look like this.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qwJzfjAJVOjtDTkeMZOwUA.jpeg" /><figcaption>Iteration #2</figcaption></figure><p>The important thing to notice about making this change is that it was fast. Iteration #1 was simple to reason about, so adding the path to support the prime feature was straightforward.</p><p>Now we discover that there is high demand for pizza delivery from corporate customers. These customers require fast delivery, so we create a separate button for them that leads directly to delivering the pizza fast. Let’s make the change to our maze.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dPu4vNUDBoTt55WT1FnOEA.jpeg" /><figcaption>Iteration #3</figcaption></figure><p>Notice iteration #3 is not quite as simple to reason about as iteration #1 and #2. If someone new were to look at this maze, they would need to spend a few moments inspecting its implementation to understand its behavior. This means it will take incrementally more time to make the next change.</p><p>Now we want to add chicken wings to the product mix. Initially, we won’t have the capacity to deliver wings fast, so we’ll only offer them to our non-corporate customers.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xPJTXpdM7lvfUCrDYT_qEQ.jpeg" /><figcaption>Iteration #4</figcaption></figure><p>When we made this change, we had an important choice to make. We could have started by cleaning up the internal structure of the maze to make it simpler to reason about. We instead decided to add the feature immediately without any cleanup. We accrued technical debt. The advantage of accruing this debt is that the change was faster to implement.</p><p>So why would we take the time to clean up the maze? As far as our users are concerned, the feature works. No one will know about the internal shortcomings except a few developers. The real disadvantage of accruing this debt will come when we add the next feature. The structure is beginning to make it difficult to build on.</p><p>Now we want to add a fast chicken wings delivery service for both corporate and non-corporate customers. Take a moment to examine the current maze and decide how to implement this new path. It is not trivial. Notice that the “wings” decision node is positioned immediately after “customer clicks button”. This close proximity makes it difficult to add the wings delivery service for corporate customers without duplicating functionality. This maze was not built with the intention of supporting wings delivery to corporate customers.</p><p>There are numerous ways to implement this new feature, but they aren’t pretty. Here is one implementation.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3TCJ4nJrLI7wURkdOzj21g.jpeg" /><figcaption>Iteration #5</figcaption></figure><p>Now we are in technical debt territory. Notice that there are two “prime” decision nodes and two “wings” decision nodes. We also had to duplicate the “deliver wings FAST” exit.</p><p>This is how technical debt builds up over time. Notice that at each step, we accrued a little bit of technical debt in order to ship the feature quickly. But also notice that the difficulty to reason about the maze grew at each step. So each change becomes more time consuming to make. When code is implemented like this, feature development estimates grow higher than expected. If we continue down this path, eventually development will come to a standstill.</p><p>So now let’s invest some time in refactoring to payoff this technical debt. We will cleanup the internal structure of the maze while preserving its behavior. It will continue to function exactly the same for users. The only difference is that the code will become more changeable.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*o2dZ0ydWiI3QwwgceLC-Lw.jpeg" /><figcaption>Iteration #6</figcaption></figure><p>Iteration #6 implements the exact same behavior as the previous one, but this one has a much clearer implementation. For example, it is clear that all corporate customers are treated as “prime” member with fast delivery service. This behavior was not immediately obvious when technical debt was high. Also notice that we eliminate the duplicate “deliver wings FAST” exit. Even though we paid a price to refactor the maze, that investment will pay off as future features are implemented faster and with greater confidence that they work correctly.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1505b40b0401" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>