<?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 Paolo Venturi on Medium]]></title>
        <description><![CDATA[Stories by Paolo Venturi on Medium]]></description>
        <link>https://medium.com/@paolo.venturi?source=rss-c7163178864e------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*dfi45ZaiiGw9C38jb68zmw.jpeg</url>
            <title>Stories by Paolo Venturi on Medium</title>
            <link>https://medium.com/@paolo.venturi?source=rss-c7163178864e------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 29 Nov 2026 14:40:12 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@paolo.venturi/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[3 types of Tests you need to know for Legacy Code]]></title>
            <link>https://medium.com/cgm-innovation-hub/3-types-of-tests-you-need-to-know-for-legacy-code-22f96bcf5d7b?source=rss-c7163178864e------2</link>
            <guid isPermaLink="false">https://medium.com/p/22f96bcf5d7b</guid>
            <category><![CDATA[legacy-code]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[test]]></category>
            <category><![CDATA[refactoring]]></category>
            <dc:creator><![CDATA[Paolo Venturi]]></dc:creator>
            <pubDate>Mon, 20 Jun 2022 00:00:00 GMT</pubDate>
            <atom:updated>2022-06-22T06:49:15.649Z</atom:updated>
            <content:encoded><![CDATA[<h3>3 types of Tests You Need to Know For Legacy Code</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*z7V8SP9QsYHkKmec" /><figcaption>Photo by <a href="https://unsplash.com/@flowforfrank?utm_source=medium&amp;utm_medium=referral">Ferenc Almasi</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>Automated tests in software development are very important. They provide benefits during and after development.</p><p>There are many different types of tests; today we will look at the most useful when working with legacy code.</p><p>But let’s start with the basics: why do automated tests help us develop software?</p><h3>Correctness</h3><p>Tests by definition establish the correctness of code.</p><p>When we write a test we establish preconditions for the execution of the code to be tested. Through assertions, we go to verify certain conditions that occur at the end of execution.</p><p>Knowing that these preconditions are met gives us greater confidence during development.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/498/0*05rTrC2Su4nCIYlS.jpg" /><figcaption><em>Photo by </em><a href="https://tenor.com/view/rhel1-captain-obvious-thank-you-hero-gif-11964508"><em>Tenor</em></a></figcaption></figure><h3>Understanding</h3><p>When we work with legacy code, tests help us understand the code.</p><p>To define a test we must instantiate classes and call functions that need parameters.</p><p>By analyzing existing tests, we have examples to help us better understand:</p><ul><li>how to instantiate classes</li><li>behaviors and parameters of functions</li><li>desired behaviors.</li></ul><h3>Speed</h3><p>Writing tests takes time so it slows down development.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/400/0*k6Af39ZwKvZExt54.jpg" /><figcaption><em>Photo by </em><a href="https://memegenerator.net/instance/66040229/dwight-k-schrute-false"><em>Meme Generator</em></a></figcaption></figure><p>Tests are a long-term investment but even in the short term they provide a big benefit. They return quick feedback during development and this helps to stay focused.</p><p>An example: we need to test a function that determines whether a web address is correct or not.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/864780da819de1216dce75fe82ff57c3/href">https://medium.com/media/864780da819de1216dce75fe82ff57c3/href</a></iframe><p>Without automated tests, we would have to manually run the function with different inputs and compare the result with the expectations.</p><p>With unit tests instead, we can verify many test cases in less than a second. See the following example.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/496f14e0530a2ce48f072dd2d664eed8/href">https://medium.com/media/496f14e0530a2ce48f072dd2d664eed8/href</a></iframe><p>Also, running the tests while writing the code makes it easier to locate any errors.</p><p>Let’s now consider how different kinds of tests relate to legacy code refactoring.</p><h3>Acceptance tests</h3><p>Acceptance tests define the behaviors that a feature should have from the end user’s point of view. It’s the customers that ask for a change or the Product Owners who define the parameters to be met.</p><p>Acceptance tests are comparable to a contract and place at a medium/high level in the code. Only after successful testing, the change can be “accepted.”</p><p>Examples of acceptance tests are:</p><ul><li>assertions about the behavior of a GUI button</li><li>assertions about the responses of an API given a certain input.</li></ul><p>When we change code that we don’t know, we may feel unconfident. Acceptance tests if presents are very helpful to reduce this discomfort.</p><h3>Unit tests</h3><p>Unit tests are so defined because they go to test a single software unit. A unit can be a class or even a function.</p><p>Having to cover such a small set of code makes these tests the best for locating errors.</p><p>Because they are placed at a low level in the code they are defined in a technical language. So they are of little use to the end-user but very practical for the developer.</p><p>Unit tests must meet one basic condition: they have to run in isolation.</p><p>They are not unit tests:</p><ul><li>if they use Databases</li><li>if they exploit the File System</li><li>if they communicate over the network.</li></ul><p>In a nutshell: tests must not depend on external conditions.</p><p>An example: testing a class that executes calls to an external API. Tests should not call the API but simulate its execution and response. Using the actual API, the outcome of the test will depend on:</p><ul><li>presence and speed of the network connection</li><li>operability and state of the API.</li></ul><p>But the goal of unit tests is to test code defined in a class or method.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/0*u-BOLD7YKaU22c0i.jpg" /><figcaption><em>Photo by </em><a href="https://imgflip.com/memegenerator"><em>imgflip</em></a></figcaption></figure><p>Unit tests <strong>must</strong> be fast! This is another key feature.</p><p>Staying with the previous example: wait times using an external API could be very long. This would lead us to run them less frequently, increasing the probability of inserting bugs.</p><p>Unit tests, like acceptance tests, help us understand the behaviors of the legacy code. Compared to the acceptance, they go one level lower in our codebase.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*tBH4P-1UmgMsUv58.jpg" /><figcaption><em>Levels of Tests</em></figcaption></figure><h3>Characterization tests</h3><p>Characterization tests come into play when unit and acceptance tests do not exist.</p><p>They help in better understanding how an existing program works. They allow us to describe the current behaviors of a program, so they are most useful with legacy code.</p><p>Often legacy code has characteristics that hinder testing:</p><ul><li>it does not provide values to test</li><li>it is difficult to instantiate classes</li><li>methods to be called need complex parameters.</li></ul><p>In these cases the “Legacy Code Dilemma” arises: to change the code we must have tests but to define tests we must change the code.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/480/0*fc57fSvRZ-myc61_.gif" /><figcaption><em>Photo by </em><a href="https://giphy.com/gifs/theoffice-the-office-tv-show-dw60YIVoqu0MZexouY"><em>GIPHY</em></a></figcaption></figure><p>The dilemma is solved by making small “safe” changes useful for defining tests. In this way, the probability of introducing bugs is minimized.</p><p>An example: we need to go test the following program that prints today’s date.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1afd511bb38414ae3ae2da3b25905e0b/href">https://medium.com/media/1afd511bb38414ae3ae2da3b25905e0b/href</a></iframe><p>This code is not easily testable because the result does not depend on any input. Instead, the result changes depending on when the program is executed. To test the logic we need to make a modification that removes this dependency.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/73d36e00c292f8cc47c3c420a1e10656/href">https://medium.com/media/73d36e00c292f8cc47c3c420a1e10656/href</a></iframe><p>Thanks to the FormatDate function we have isolated the logic of formatting the date. With the parameter date we can specify an input of our choice.</p><p>At this point writing a test will be possible.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9ba26e9d5aed39a914bb47343670a1e7/href">https://medium.com/media/9ba26e9d5aed39a914bb47343670a1e7/href</a></iframe><h3>Conclusions</h3><p>Automated tests are very useful in software development and are essential if we have to work with legacy code.</p><p>Acceptance and characterization tests cover code at a higher level than unit tests. Both levels are necessary.</p><p>In the next articles on legacy code, we will go over some useful techniques for arriving at refactoring techniques.</p><p>Questo articolo è disponibile <a href="https://studiofarma.github.io/CGM-Innovation-Hub-Tech-Blog/I-test-ed-il-legacy-code/">anche in italiano</a>.</p><p><em>👈 </em><a href="https://medium.com/cgm-innovation-hub/what-is-legacy-code-101c809aa240">What is legacy code? | by Paolo Venturi | Medium | CGM Innovation Hub</a></p><h3>References</h3><ul><li><strong>Working Effectively with Legacy Code</strong> — Michael C. Feathers, 2004 — <a href="https://www.oreilly.com/library/view/working-effectively-with/0131177052">https://www.oreilly.com/library/view/working-effectively-with/0131177052</a></li><li><strong>Refactoring: Improving the Design of Existing Code</strong> — Martin Fowler, 1999 — <a href="https://martinfowler.com/books/refactoring.html">https://martinfowler.com/books/refactoring.html</a></li></ul><p><em>Originally published at </em><a href="https://studiofarma.github.io/CGM-Innovation-Hub-Tech-Blog/Tests-and-legacy-code/">3 types of Tests you need to know for Legacy Code | CGM Innovation Hub (studiofarma.github.io)</a> <em>on June 20, 2022.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=22f96bcf5d7b" width="1" height="1" alt=""><hr><p><a href="https://medium.com/cgm-innovation-hub/3-types-of-tests-you-need-to-know-for-legacy-code-22f96bcf5d7b">3 types of Tests you need to know for Legacy Code</a> was originally published in <a href="https://medium.com/cgm-innovation-hub">CGM Innovation Hub</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[What is Legacy Code?]]></title>
            <link>https://medium.com/cgm-innovation-hub/what-is-legacy-code-101c809aa240?source=rss-c7163178864e------2</link>
            <guid isPermaLink="false">https://medium.com/p/101c809aa240</guid>
            <category><![CDATA[refactoring]]></category>
            <category><![CDATA[clean-code]]></category>
            <category><![CDATA[legacy-code]]></category>
            <category><![CDATA[testing]]></category>
            <category><![CDATA[software-development]]></category>
            <dc:creator><![CDATA[Paolo Venturi]]></dc:creator>
            <pubDate>Mon, 02 May 2022 10:25:12 GMT</pubDate>
            <atom:updated>2022-05-09T12:49:39.529Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*Ka3sMdciIJKg5jTn.jpg" /><figcaption><em>Photo by </em><a href="https://en.wikipedia.org/wiki/Punched_card#/media/File:Blue-punch-card-front-horiz.png"><em>Wikipedia</em></a></figcaption></figure><p>In software projects, as in other fields, it is important to keep low costs and development time.<br>The time of implementing a new feature or fixing a bug depends on the status of the existing codebase.<br>Estimating the effort of changing simple and clean code is easy. While it’s harder to make predictions with legacy code.<br>This results in inflated estimates and costs that grow exponentially.</p><p><strong>But what is legacy code?</strong><br><strong>How many people can distinguish legacy code, and avoid writing it?</strong></p><h3>Search for a definition</h3><p>To answer these questions, I did what anyone would do: I googled.</p><figure><img alt="Joey approaching search of legacy code in Google" src="https://cdn-images-1.medium.com/max/700/0*BNxNHZgismwk4BLz.jpg" /><figcaption><em>Photo by </em><a href="https://www.meme-arsenal.com/memes/58b301f6612908a498826a64b4937dd6.jpg"><em>Meme-arsenal</em></a></figcaption></figure><p>I found many definitions of “legacy code” on the internet:</p><ul><li>code written by others or inherited (<a href="https://stackoverflow.com/a/4174886">https://stackoverflow.com/a/4174886</a>)</li><li>“old” code (<a href="https://en.wikipedia.org/wiki/Legacy_system">https://en.wikipedia.org/wiki/Legacy_system</a>)</li><li>code that uses unsupported technologies (<a href="https://enkonix.com/blog/legacy-code">https://enkonix.com/blog/legacy-code</a>)</li><li>badly structured code (<a href="https://www.oreilly.com/library/view/working-effectively-with/0131177052">https://www.oreilly.com/library/view/working-effectively-with/0131177052</a>)</li><li>code without tests (<a href="https://understandlegacycode.com/blog/what-is-legacy-code-is-it-code-without-tests">https://understandlegacycode.com/blog/what-is-legacy-code-is-it-code-without-tests</a>)</li></ul><figure><img alt="Joey found legacy code in Google" src="https://cdn-images-1.medium.com/max/700/0*2B-S1m92Xnjnc780.jpg" /><figcaption><em>Photo by </em><a href="https://www.meme-arsenal.com/memes/58b301f6612908a498826a64b4937dd6.jpg"><em>Meme-arsenal</em></a></figcaption></figure><p>These definitions don’t converge on a clear agreement about legacy code, and how it relates to the costs of maintaining a software project.<br> Let’s analyze them one by one.</p><h3>Code written by others or inherited</h3><p>Working on code that we didn’t write ourselves is tricky:</p><ul><li>Variables and classes names may not be evocative or appropriate.</li><li>The structure of the code, files, and classes is not familiar.</li><li>Maybe the author used a design pattern that we don’t know.</li></ul><p>Is this enough to define code written by others as legacy?</p><p><strong>NO!</strong></p><p>If the developer has made it easy to understand, then it cannot be defined as legacy code.</p><h3>“Old” code</h3><p>Does the age of code enough to define it as legacy?</p><p><strong>NO!</strong></p><p>As for code written by others, this is not enough to get a definition.</p><p>Can we establish a period beyond which the code becomes old?<br> It is not possible. A code that was written a month ago may be more confusing than a code written a year ago.<br> It all depends on how we cared for it and made it “simple”.</p><p>Let’s consider a trivial example. A program that calculates the Fibonacci sequence: each number of the sequence is the sum of the previous two numbers.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/900/0*YyUYNM5tUNCaEWJd.jpg" /></figure><p>Let’s see implementations in two different programming languages: the dear old C and the more recent C#.</p><p>Fibonacci sequence in C.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c04bc9e534c5c4ea2b66fc9deada1aa1/href">https://medium.com/media/c04bc9e534c5c4ea2b66fc9deada1aa1/href</a></iframe><p>Fibonacci sequence in C#.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/0ec78fa92f48e18740bc07565ae38948/href">https://medium.com/media/0ec78fa92f48e18740bc07565ae38948/href</a></iframe><p>These two programs do the same thing but the differences are huge.</p><p>The C program takes advantage of recursion, making the main function more readable. Functions and variables have proper names.</p><p>In contrast, the C# program uses an array and a for loop to calculate numbers in the sequence.<br> Variable names are generic and all the logic is in the Main function.</p><p>We can agree that the age of the code and the language, are not enough to define it as legacy.</p><h3>Code that uses unsupported technologies</h3><p>What about code that uses libraries that are out of support? Can it be defined as legacy? <strong>YES AND NO…</strong></p><p>Unsupported libraries expose us to a risk. In case of bugs or missing features, there are only two possible ways:</p><ul><li>If the library is customizable, we can provide missing implementations by ourselves.</li><li>Otherwise, the only solution is to replace it with a library that suits our needs.</li></ul><p>Replacing a library can be very complicated, unless we adopted it in well-isolated locations. In this case, the switch could be almost painless.</p><p>The use of outdated technologies is not enough to define code as legacy.<br> But it can cause a lot of inconveniences.</p><h3>Badly structured code</h3><p>Can we define badly structured code, e.g. a monolith, as legacy? <strong>YES!</strong></p><p>Lack of separation of responsibilities, classes with complicated dependencies, non-evocative names.<br> These and other problems (code smell) make our code “weak”.</p><p>Code smells are definitely one of the reasons we define code as legacy.</p><h3>Code without tests</h3><p>Is the lack of tests enough to define code as legacy? <strong>YES!</strong></p><p>We can write well-structured code, without code smell and with popular and recent libraries.<br> But if our codebase is not covered by a collection of tests we will be exposed to the risk of introducing bugs with every change.<br> Tests are essential to define the required behaviors of our software.<br> They protect us from possible errors and help us to better understand the logic of the code they cover.</p><h3>So?</h3><p>In the end, a short and effective definition might be: <strong>legacy code is untested code that is hard to change.</strong></p><figure><img alt="Joey understood what is Legacy Code" src="https://cdn-images-1.medium.com/max/647/0*bqW-sF01poxjirk5.jpg" /><figcaption><em>Photo by </em><a href="https://www.hallofseries.com/wp-content/uploads/2019/01/Immagine-1.png"><em>Hall of Series</em></a></figcaption></figure><p>In the next articles of the series, we’re going to see how to work with legacy code and how to make it “less legacy” by testing and refactoring.</p><p>And you? Do you have another definition of Legacy Code? Let us know in comments!</p><p>Questo articolo è disponibile <a href="https://studiofarma.github.io/CGM-Innovation-Hub-Tech-Blog/Cos&#39;%C3%A8-il-legacy-code/">anche in italiano</a>.</p><h3>References</h3><ul><li><strong>Working Effectively with Legacy Code</strong> — Michael C. Feathers, 2004 — <a href="https://www.oreilly.com/library/view/working-effectively-with/0131177052">https://www.oreilly.com/library/view/working-effectively-with/0131177052</a></li><li><strong>Refactoring: Improving the Design of Existing Code</strong> — Martin Fowler, 1999 — <a href="https://martinfowler.com/books/refactoring.html">https://martinfowler.com/books/refactoring.html</a></li></ul><p><em>Originally published at </em><a href="https://studiofarma.github.io/CGM-Innovation-Hub-Tech-Blog/What-is-legacy-code/">What is legacy code? | CGM Innovation Hub (studiofarma.github.io)</a> <em>on May 2, 2022.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=101c809aa240" width="1" height="1" alt=""><hr><p><a href="https://medium.com/cgm-innovation-hub/what-is-legacy-code-101c809aa240">What is Legacy Code?</a> was originally published in <a href="https://medium.com/cgm-innovation-hub">CGM Innovation Hub</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>