{"id":1207,"date":"2014-10-07T15:54:52","date_gmt":"2014-10-07T14:54:52","guid":{"rendered":"http:\/\/qualilogy.com\/en\/?p=1207"},"modified":"2014-10-07T17:02:40","modified_gmt":"2014-10-07T16:02:40","slug":"legacy-application-refactoring-sqale-plugin-1","status":"publish","type":"post","link":"http:\/\/qualilogy.com\/en\/legacy-application-refactoring-sqale-plugin-1\/","title":{"rendered":"Legacy Application &#8211; Refactoring with the SQALE plugin (I)"},"content":{"rendered":"<p><a href=\"http:\/\/500px.com\/Vicken\" target=\"_blank\"><img loading=\"lazy\" decoding=\"async\" class=\"alignright size-full wp-image-2095\" src=\"http:\/\/qualilogy.com\/fr\/wp-content\/uploads\/sites\/2\/2014\/10\/LegacyTechDebtRefactoring.jpg\" alt=\"Application Legacy - Refactoring Technical Debt with the plugin SQALE SonarQube\" width=\"288\" height=\"360\" \/><\/a>In order to estimate the cost of refactoring our Legacy application, I will use the plugin SQALE of SonarQube, more usually employed to measure the technical debt.<\/p>\n<p>We have <a title=\"PL\/SQL analysis with SonarQube \u2013 Evaluating the quality (3\/3)\" href=\"http:\/\/qualilogy.com\/en\/plsql-analysis-with-sonarqube-evaluating-the-quality-3\/\" target=\"_blank\">already presented<\/a> this plugin with a PL\/SQL Legacy application. So just remember that the SQALE plugin is based on <a href=\"http:\/\/www.sqale.org\/details\" target=\"_blank\">the SQALE quality model<\/a>, and I will also add, on a method to adapt the model by aligning it with various business objectives, the technology or the contexte of the application. <!--more--><\/p>\n<h2>SQALE and Legacy applications<\/h2>\n<p>Today, any application over 3 years is considered &#8216;Legacy&#8217;, especially if it does not have unit test coverage. In this case, <a title=\"Legacy application \u2013 Refactoring or reengineering? (IV)\" href=\"http:\/\/qualilogy.com\/en\/legacy-application-refactoring-reengineering-4\/\" target=\"_blank\">&#8216;Edit and Pray&#8217;<\/a> or &#8216;Change and run&#8217;, explains Michael Feathers in his book \u00ab Working Effectively with Legacy Code \u00bb.<\/p>\n<p>So you understand that we will not use the SQALE model in the same way for a J2EE application that is three years old, or our Word 1.1a application in C that was developed 20 years ago, or an even older Cobol application that has gone through the hands of several different teams, and some possibly offshoring.<\/p>\n<p>We must also consider the type of application: here we have an office software sold by an editor software, and it&#8217;s not at all the same as a J2EE application developed in-house to meet business needs or based on a software package such as SAP. For example, our application is written in C and uses no database: factors like &#8216;performance&#8217; and &#8216;security&#8217; will not have quite the same weight as a traditional application to manage the business of a company.<\/p>\n<h2>SQALE and the monitoring of technical debt<\/h2>\n<p>Another factor to consider: as explained by Freddy Mallet from SonarQube in <a href=\"https:\/\/www.youtube.com\/watch?v=d3XYhUikeIA\" target=\"_blank\">this video<\/a> (in french) : \u00ab\u00a0Technical debt means to avoid waking up after 5 years with a code with which we can no longer do anything without it costing us an arm and a leg \u00bb.<\/p>\n<p>A common use of the plugin SQALE is to monitor and control the technical debt over the versions, in order to prevent it to go beyong a threshold where it starts to become unbearable and too expensive.\u00a0Or, as explained in <a href=\"http:\/\/www.sonarqube.org\/using-differentials-to-move-the-team-in-the-right-direction\/\" target=\"_blank\">this post<\/a> : \u00ab don&#8217;t start mopping the floor before you\u2019ve plugged the leak \u00bb.<\/p>\n<p>In our case, we only have a single version, so I will again point out that our use of the SQALE plugin is specific to our goal of evaluating a refactoring effort, without a personalized model but proceeding directly with &#8216;out of the box&#8217; results .<\/p>\n<p>In the context of this article, I will present these results in order to illustrate the approach to estimate the cost of refactoring a Legacy application. Estimation done &#8216;a priori&#8217;, even before to consult the project team or the management about this refactoring, but with the intention to list some elements to present during a future meeting.<\/p>\n<h2>SQALE in the SonarQube dashboard<\/h2>\n<p>I configured my own dashboard in SonarQube with a widget to display the following data from the SQALE plugin:<\/p>\n<p style=\"text-align: center\"><strong><em>Figure 1 \u2013 SQALE data on the technical debt of our Legacy application<br \/>\n<\/em><\/strong><\/p>\n<p><a href=\"http:\/\/qualilogy.com\/fr\/wp-content\/uploads\/sites\/2\/2014\/10\/LegacyTechDebtSyntesis.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-2105\" src=\"http:\/\/qualilogy.com\/fr\/wp-content\/uploads\/sites\/2\/2014\/10\/LegacyTechDebtSyntesis.jpg\" alt=\"Donn\u00e9es SQALE sur la Dette Technique de notre application Legacy\" width=\"349\" height=\"168\" \/><\/a><\/p>\n<p>1 238.7 days to reduce the technical debt. With a rate of <a title=\"Legacy application \u2013 Refactoring or reengineering? (VII)\" href=\"http:\/\/qualilogy.com\/en\/legacy-application-refactoring-reengineering-7\/\" target=\"_blank\">18.5 working days per month<\/a>, this represents 69.4 months and, for our team of 5 people, 13.9 men\/months.<\/p>\n<p>So it takes almost 14 months to our project team to overcome this technical debt. Needless to say that this is not acceptable for the management: it means to stop any development, any new release for over a year. No customer, no user would agree to such a decision.<\/p>\n<p>However, our goal is not to eliminate 100% of that debt, but to make an effort to reduce it so that the burden of the debt becomes acceptable, and the corresponding reduction in maintenance costs becomes greater than the cost of refactoring. Indeed, the decision whether to make a refactoring is usually based on a ROI (Return On Investment), and having the gains in maintainability exceed the cost of refactoring.<\/p>\n<p>Is it possible to consider a reasonable effort, with limited but specific actions, and a return on investment? This is what I will look with other data configured in my widget.<\/p>\n<p>First, I see that the &#8216;SQALE Rating&#8217; is equal to &#8216;B&#8217;. This shows the weight of technical debt in relation to the whole application. Another SQALE widget in the SonarQube portal gives me the distribution of the technical debt on different files.<\/p>\n<p style=\"text-align: center\"><strong><em>Figure 2 \u2013 File Distribution by SQALE Rating<\/em><\/strong><\/p>\n<p><a href=\"http:\/\/qualilogy.com\/fr\/wp-content\/uploads\/sites\/2\/2014\/10\/LegacyTechDebtRating.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-2106\" src=\"http:\/\/qualilogy.com\/fr\/wp-content\/uploads\/sites\/2\/2014\/10\/LegacyTechDebtRating.jpg\" alt=\"Distribution du SQALE Rating par fichier\" width=\"458\" height=\"112\" \/><\/a><\/p>\n<p>We have 12 files with a very high technical debt, and if I list these files, I will find some programs <a title=\"Legacy C application \u2013 Refactoring or reengineering? (II)\" href=\"http:\/\/qualilogy.com\/en\/legacy-c-application-refactoring-reengineering-2\/\" target=\"_blank\">previously identified<\/a> as the most complex, the largest in number of lines of code (LOC) and\/or with\u00a0very complex and large functions.<\/p>\n<p style=\"text-align: center\"><strong><em>Figure 3 \u2013 Highest SQALE remediation costs<\/em><\/strong><\/p>\n<p><a href=\"http:\/\/qualilogy.com\/fr\/wp-content\/uploads\/sites\/2\/2014\/10\/LegacyTechDebtFiles.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-2107\" src=\"http:\/\/qualilogy.com\/fr\/wp-content\/uploads\/sites\/2\/2014\/10\/LegacyTechDebtFiles.jpg\" alt=\"Highest SQALE remediation costs\" width=\"350\" height=\"323\" \/><\/a><\/p>\n<p>Another way to check the distribution of technical debt on all application files: the Bubble Chart. I love this one. I can choose any metric I want and cross them:<\/p>\n<ul>\n<li>Technical Debt in days on the Y axis;<\/li>\n<li>\n<ul>Number of lines of code on the X axis;<\/ul>\n<\/li>\n<li>\n<ul>Cyclomatic Complexity for the size of the bubble.<\/ul>\n<\/li>\n<\/ul>\n<p style=\"text-align: center\"><strong><em>Figure 4 \u2013 Technical Debt x Cyclomatic Complexity x Lines of Code<\/em><\/strong><\/p>\n<p><a href=\"http:\/\/qualilogy.com\/fr\/wp-content\/uploads\/sites\/2\/2014\/10\/LegacyTechDebtBubbles.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-2109\" src=\"http:\/\/qualilogy.com\/fr\/wp-content\/uploads\/sites\/2\/2014\/10\/LegacyTechDebtBubbles.jpg\" alt=\"Technical Debt x Cyclomatic Complexity x Lines of Code\" width=\"815\" height=\"517\" \/><\/a><\/p>\n<p>We can see, on this figure, the file &#8216;fltexp.c&#8217; with the highest technical debt for a program\u00a0\u2013 23 days of refactoring \u2013 spread over 2 600 lines of code and 740 points of Cyclomatic Complexity.<\/p>\n<p>Some will say again that the number of lines of code (LOC) is not a reliable measure of the size of an application, but after playing with different combinations of metrics, it is still the most correlated with the technical debt, and therefore a factor to take into account in order to understand it.<\/p>\n<p>For example, in the next Bubble Chart, I chose the Cyclomatic Complexity (CC) by function as a measure of the size of the bubble.<\/p>\n<p style=\"text-align: center\"><strong><em>Figure 5 \u2013 Technical Debt x Cyclomatic Complexity\/Function x Lines of Code<\/em><\/strong> <a href=\"http:\/\/qualilogy.com\/fr\/wp-content\/uploads\/sites\/2\/2014\/10\/LegacyTechDebtBubbles3.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-2111\" src=\"http:\/\/qualilogy.com\/fr\/wp-content\/uploads\/sites\/2\/2014\/10\/LegacyTechDebtBubbles3.jpg\" alt=\"Technical Debt x Cyclomatic Complexity\/Function x Lines of Code\" width=\"833\" height=\"518\" \/><\/a><\/p>\n<p>The file &#8216;RTFOUT.C&#8217; that <a title=\"Legacy application \u2013 Refactoring or reengineering? (V)\" href=\"http:\/\/qualilogy.com\/en\/legacy-application-refactoring-reengineering-5\/\" target=\"_blank\">we have presented previously<\/a>, has the most complex function with 355 points CC, but also another one with only two points of CC. The average complexity of this file will be (355 + 2) \/ 2 = 178.5 points CC, as shown above the graph.<\/p>\n<p>I also displayed in this figure the measures for the file &#8216;fltexp.c&#8217; which we have seen previously (Figure 3 earlier), with the highest technical debt and 740 points of CC, but spread over a larger number of functions, since the average CC by function is about 16 points.<\/p>\n<p>This graph is interesting, but I think that it is less useful than the previous one, which was more meaningful and relevant to the effort of refactoring for each program and the entire application. Anyway, we can see that we have in SonarQube different tools and widgets to imagine and investigate different courses of action.<\/p>\n<p>With these widgets and these data from the SQALE plugin, I know:<\/p>\n<ul>\n<li>Which files have the highest technical debt: no surprise, these are the heaviest and most complex files of our application, as previously identified.<\/li>\n<li>The refactoring effort to remove the technical debt for each of these files.<\/li>\n<\/ul>\n<p>But again, this effort is too important to be considered as such, and not necessarily needed because we do not want the total eradication of the technical debt, but a refactoring based on actions with a cost of reduction of the technical debt as low as possible for the maximum benefits.<\/p>\n<p>Our next post will be devoted to the presentation of these actions and their estimated cost.<br \/>\nSee you soon.<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In order to estimate the cost of refactoring our Legacy application, I will use the plugin SQALE of SonarQube, more usually employed to measure the technical debt. We have already presented this plugin with a PL\/SQL Legacy application. So just remember that the SQALE plugin is based on the SQALE quality model, and I will [&hellip;]<\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[],"class_list":["post-1207","post","type-post","status-publish","format-standard","hentry","category-application-quality"],"_links":{"self":[{"href":"http:\/\/qualilogy.com\/en\/wp-json\/wp\/v2\/posts\/1207"}],"collection":[{"href":"http:\/\/qualilogy.com\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/qualilogy.com\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/qualilogy.com\/en\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"http:\/\/qualilogy.com\/en\/wp-json\/wp\/v2\/comments?post=1207"}],"version-history":[{"count":16,"href":"http:\/\/qualilogy.com\/en\/wp-json\/wp\/v2\/posts\/1207\/revisions"}],"predecessor-version":[{"id":1223,"href":"http:\/\/qualilogy.com\/en\/wp-json\/wp\/v2\/posts\/1207\/revisions\/1223"}],"wp:attachment":[{"href":"http:\/\/qualilogy.com\/en\/wp-json\/wp\/v2\/media?parent=1207"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/qualilogy.com\/en\/wp-json\/wp\/v2\/categories?post=1207"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/qualilogy.com\/en\/wp-json\/wp\/v2\/tags?post=1207"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}