<?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 Jia Tse on Medium]]></title>
        <description><![CDATA[Stories by Jia Tse on Medium]]></description>
        <link>https://medium.com/@jiatse?source=rss-37c60e7c0c1d------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*32csYHwKrLBDk8ChThSLDw.jpeg</url>
            <title>Stories by Jia Tse on Medium</title>
            <link>https://medium.com/@jiatse?source=rss-37c60e7c0c1d------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 16 Nov 2026 18:35:27 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@jiatse/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[Debugging Software]]></title>
            <link>https://medium.com/@jiatse/debugging-software-91cc34254f40?source=rss-37c60e7c0c1d------2</link>
            <guid isPermaLink="false">https://medium.com/p/91cc34254f40</guid>
            <dc:creator><![CDATA[Jia Tse]]></dc:creator>
            <pubDate>Fri, 07 Aug 2020 20:27:40 GMT</pubDate>
            <atom:updated>2020-08-10T23:00:06.026Z</atom:updated>
            <content:encoded><![CDATA[<h4>Root cause vs bandages</h4><p>In software engineering, it’s inevitable to run into bugs. Software is usually developed by many people and evolves over time. It is not uncommon to encounter a bug and a <em>simple</em> fix comes to mind. But wait! We must determine whether the fix is addressing the root cause, or is it simply a bandage. Let’s take an example:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/540b7f8857f06f13998227ad5fa43604/href">https://medium.com/media/540b7f8857f06f13998227ad5fa43604/href</a></iframe><p>In a refactoring effort, LegacyCalc was replaced by RefactoredCalc. It passes QA and made it to production. Soon, errors were appearing on the dashboard</p><pre>Exception in thread &quot;main&quot; java.lang.ArithmeticException: / by zero<br> at RefactoredCalc.divide(ClassA.kt:13)<br> at ClassAKt.main(ClassA.kt:18)<br> at ClassAKt.main(ClassA.kt)</pre><p>Looks like ClassA is crashing. Let’s fix it.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ce62a57b4e32666ec45a868101a0a60e/href">https://medium.com/media/ce62a57b4e32666ec45a868101a0a60e/href</a></iframe><p>A “fix” was pushed out and a few days later, a new error came in. Now there is an error in ClassB</p><pre>Exception in thread &quot;main&quot; java.lang.ArithmeticException: / by zero<br> at RefactoredCalc.divide(ClassB.kt:13)<br> at ClassAKt.main(ClassB.kt:18)<br> at ClassAKt.main(ClassB.kt)</pre><h3>Bandages</h3><p>In the illustration above, the fix forClassA is a bandage. It is addressing the symptoms, not the cause. ClassA was crashing, the expected output in such a case is 0, so a fix was applied.</p><p>Why is this bad?</p><p><strong>The underlying issue is still there.</strong> The goal of RefactoredCalc is to maintain equivalent functionality with LegacyCalc. However, it obviously failed to handle division by zero. Applying the bandage in ClassA fixed it only for that one class, but the underlying problem in RefactoredCalc is never addressed.</p><p><strong>The code will increasingly become more brittle — side effects</strong>. Soon after ClassA was addressed, we see similar issues in ClassB, and then ClassC and any class that ever uses RefactoredCalc. Similar “bandages” will be applied and the codebase will appear more brittle. “One change” can trigger so many “side effects”.</p><p><strong>The root cause is now <em>hidden.</em></strong> The more bandages we apply, the harder it is to find the root cause.<strong> </strong>This will become the <em>new normal. </em>It will be increasingly hard to trace back to an issue withRefactoredCalc — it’s “been there for a while”.</p><h3>Identifying Root Cause</h3><p>There is no magic bullet for this, debugging can be extremely hard. However, guidelines exist to help steer in a safer direction and trigger the gut instincts that a <em>fix</em> might just be a bandage.</p><p><strong>The bug is in a place that hasn’t been touched. </strong>ClassA was never touched, yet it’s mysteriously throwing an error we’ve never seen before. This should strongly hint that ClassA is not the place that needs fixing</p><p><strong>The bug is new. </strong>Luckily bugs don’t just appear out of nowhere. It is a reaction to something that changed. A <em>spike</em> in existing bugs is also considered new. New bugs are likely to be introduced by new changes. Try to look at what changed.</p><p><strong>Consult the owner.</strong> In a team environment, it’s not uncommon for one person to write the code, and another person to fix it. The disadvantage of this is the lack of context. If person A wrote RefactoredCalc and Person B saw the error message, it is harder for B to realize theClassA fix is a bandage. If at all possible, discuss with the owner.</p><h3>Taking Action</h3><p>Often times when a bug is identified, we hastily arrive at a conclusion of <em>what should be done.</em> In the above example, it can be argued that throwing an Exception is the right thing to do. Sometimes, addressing the root cause of a bug isn’t about what <em>should</em> be done, it is about what is <em>correct. </em>The correct thing to do is <em>maintain equivalent functionality</em> as before the refactor.</p><p>To apply a <em>correct</em> fix, first understand what the problem is. Reproduce the bug in the refactored version. Then reproduce in the legacy version. If it works in legacy but not refactored, then we know the bug was introduced while refactoring. Track down the root cause. The <em>root cause </em>is not the answer to <em>why it is failing now</em>. It is the answer to <em>why it was working previously and now became faulty. </em>Once we understand the problem in its entirety, we can safely craft a solution. Without this understanding, we may very well be applying a bandage.</p><p>Software engineering is an art. It is not perfect, it will have bugs. There is no one size fits all. Even the best architectures can have bugs. Not all bug fixes are the same. If we can do more <em>root cause </em>fixing rather than <em>bandage</em> fixing, the software will inherently increase stability and reduce side effects.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=91cc34254f40" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>