{"id":5984,"date":"2015-11-12T06:00:06","date_gmt":"2015-11-12T14:00:06","guid":{"rendered":"http:\/\/thinkapps.com\/blog\/?p=5984"},"modified":"2015-11-11T15:59:35","modified_gmt":"2015-11-11T23:59:35","slug":"technical-debt-calculation","status":"publish","type":"post","link":"https:\/\/thinkapps.com\/blog\/development\/technical-debt-calculation\/","title":{"rendered":"How to Calculate Technical Debt and Express It Clearly"},"content":{"rendered":"<p><em>This is the second post in our\u00a0series on <span style=\"text-decoration: underline;\"><a title=\"Technical Debt blog series\" href=\"http:\/\/thinkapps.com\/blog\/tag\/technical-debt\/\" target=\"_blank\">technical debt<\/a><\/span>. In the first post, we explained <span style=\"text-decoration: underline;\"><a title=\"Technical Debt 101\" href=\"http:\/\/thinkapps.com\/blog\/development\/technical-debt-definition-importance\/\" target=\"_blank\">what technical debt is and why it&#8217;s important<\/a><\/span>. Now we&#8217;re exploring technical debt calculation.<\/em><\/p>\n<p><span style=\"font-weight: 400;\">It\u2019s been several weeks since my &#8220;Technical Debt 101&#8221;\u00a0blog post. As promised, it was the first in\u00a0a series about this silent danger that is eating our software. <\/span><\/p>\n<p><span style=\"font-weight: 400;\">I hope you enjoyed the kitchen metaphor and can now\u00a0clearly identify the different &#8220;flavors&#8221; of technica<\/span><span style=\"font-weight: 400;\">l debt. After reading the first post, you\u00a0should also understand how quality is affected by poor and &#8220;dirty&#8221; code and when is the right time to deal with technical debt. <\/span><\/p>\n<h3>In this second post, I will explain how to calculate\u00a0technical debt and express it in a way that&#8217;s easily understood by both technical and non-technical team members.<\/h3>\n<p><a href=\"http:\/\/d1vqbpto5tbbz0.cloudfront.net\/blog\/wp-content\/uploads\/2015\/10\/14172111\/measuring-metrics.jpg\"><img loading=\"lazy\" decoding=\"async\" width=\"387\" height=\"292\" class=\"small alignnone wp-image-5995 size-full\" src=\"http:\/\/d1vqbpto5tbbz0.cloudfront.net\/blog\/wp-content\/uploads\/2015\/10\/14172111\/measuring-metrics.jpg\" alt=\"Technical Debt Calculation - Measuring Tape\" srcset=\"https:\/\/d1vqbpto5tbbz0.cloudfront.net\/blog\/wp-content\/uploads\/2015\/10\/14172111\/measuring-metrics.jpg 387w, https:\/\/d1vqbpto5tbbz0.cloudfront.net\/blog\/wp-content\/uploads\/2015\/10\/14172111\/measuring-metrics.jpg 300w\" sizes=\"(max-width: 387px) 100vw, 387px\" \/><\/a><\/p>\n<p><em><a title=\"Measuring tape image\" href=\"http:\/\/blog.smartbear.com\/wp-content\/uploads\/imports\/measuring%20metrics.jpg\" target=\"_blank\">Image credit<\/a><\/em><\/p>\n<h2><span style=\"font-weight: 400;\">What Should the Numbers Tell Us?<\/span><\/h2>\n<p><span style=\"font-weight: 400;\">I&#8217;ve given many\u00a0talks at development conferences.\u00a0All of my presentations include at least one slide with numeric data\u00a0based on research, an analysis I conducted, or another reliable source. <\/span><\/p>\n<p><span style=\"font-weight: 400;\">These metrics are simple, easy to understand, and objective. I do this in order\u00a0to explain to the audience\u00a0that realistic and accurate numbers can drive me to the right decisions. On the other hand, numbers that are hard to understand or wrongly computed can lead to\u00a0choices that will cost me time or even money, in some cases. <\/span><\/p>\n<p>Technical debt epitomizes\u00a0my philosophy. It\u2019s a critical factor of code quality measurement (and management). Companies simply can\u2019t afford miscalculations or reports that are hard to interpret.<\/p>\n<p>Moreover, technical debt should be easily communicated to non-technical team members, such as upper management, business people, product owners, and even customer representatives.<\/p>\n<p>It might seem strange\u00a0to share an \u201cinternal\u201d code quality metric with the customer. But let\u2019s remind ourselves that it\u2019s the customers who\u00a0invest in our software, and they deserve to know where exactly they&#8217;re putting their money.<\/p>\n<h3>What is the best way to express technical debt without using <a title=\"Mobile App Development Glossary\" href=\"http:\/\/thinkapps.com\/blog\/development\/mobile-app-development-glossary-for-founders-and-product-managers\/\" target=\"_blank\">technical jargon<\/a>\u00a0so that everyone is able to understand it?<\/h3>\n<p><span style=\"font-weight: 400;\">Developers use a variety\u00a0of terms for code quality metrics, such as <em>cyclomatic complexity<\/em> or <em>branch coverage<\/em> or <em>unwanted dependency cycles<\/em>. <\/span><\/p>\n<p><span style=\"font-weight: 400;\">All of them look like Greek<\/span><span style=\"font-weight: 400;\"> to business and product people.* If we asked them what value they get from such metrics, their answer would probably be\u00a0&#8220;none.&#8221;<\/span><\/p>\n<p><em>*<span style=\"font-weight: 400;\">Since I\u2019m Greek, my sarcasm about my mother-tongue is allowed. \ud83d\ude42<\/span><\/em><\/p>\n<p><strong>In the following paragraphs, I&#8217;ll discuss how to calculate the most important metrics affecting technical debt and will present the debt\u00a0as a single reference number.<\/strong><\/p>\n<p><span style=\"font-weight: 400;\">Before we move forward, however, let me add one more parameter. In my previous post, we discussed\u00a0that there are many types of technical debt (i.e. design, defect, testing, and documentation). We also explained that there are various root causes that increase technical debt. <\/span><\/p>\n<p><span style=\"font-weight: 400;\">Every root cause can be represented by one or more metrics, but ideally we want to express technical debt as a single number that will describe the overall quality of a software system. Moreover, we want to\u00a0<\/span>find a metric that makes sense to both technical and non-technical folks.<\/p>\n<p>Before we do that, however, let\u2019s step back for a minute and think about financial debt.<\/p>\n<p><a href=\"http:\/\/d1vqbpto5tbbz0.cloudfront.net\/blog\/wp-content\/uploads\/2015\/11\/09155354\/17160649951_bfd9f98ec6_k.jpg\"><img loading=\"lazy\" decoding=\"async\" width=\"2048\" height=\"1315\" class=\"alignnone wp-image-6045 size-full\" src=\"http:\/\/d1vqbpto5tbbz0.cloudfront.net\/blog\/wp-content\/uploads\/2015\/11\/09155354\/17160649951_bfd9f98ec6_k.jpg\" alt=\"Technical Debt Calculation - Financial Debt Comparison\" srcset=\"https:\/\/d1vqbpto5tbbz0.cloudfront.net\/blog\/wp-content\/uploads\/2015\/11\/09155354\/17160649951_bfd9f98ec6_k.jpg 2048w, https:\/\/d1vqbpto5tbbz0.cloudfront.net\/blog\/wp-content\/uploads\/2015\/11\/09155354\/17160649951_bfd9f98ec6_k.jpg 300w, https:\/\/d1vqbpto5tbbz0.cloudfront.net\/blog\/wp-content\/uploads\/2015\/11\/09155354\/17160649951_bfd9f98ec6_k.jpg 1024w\" sizes=\"(max-width: 2048px) 100vw, 2048px\" \/><\/a><\/p>\n<p><em><a title=\"Loan image via Flickr\" href=\"https:\/\/www.flickr.com\/photos\/jakerust\/17160649951\/\" target=\"_blank\">Image credit<\/a><\/em><\/p>\n<h3>Comparison to Financial Debt<\/h3>\n<p>If I go to a bank to ask for a loan, I will talk\u00a0with the bank representative about the amount of money that I need and\u00a0how much I can afford to pay back every month.\u00a0I will also sign a loan agreement that clearly states the above details and the number of\u00a0months I have to\u00a0repay\u00a0the loan.<\/p>\n<p>Wouldn\u2019t it\u00a0make sense to\u00a0express technical debt in a similar way? How about telling the business that in order to eliminate all or \u201cX%\u201d of the technical debt, the development team needs to spend \u201cY\u201d man-days working on it?<\/p>\n<p>Wouldn\u2019t that make perfect sense? Isn\u2019t this a number that is easily understood by all stakeholders?\u00a0Yes, of course!<\/p>\n<p>Developers perceive this as the number of days they have to spend in order to write unit tests (increase coverage), remove duplicate code, do refactoring (decrease complexity) or any other activity that will help them eliminate the technical debt.<\/p>\n<p>Meanwhile, this calculation says to non-technical team members:\u00a0&#8220;If you want to improve the quality of your software \u2014 by paying back the technical debt \u2014 you need to ask the development team to spend\u00a0Y man-days on it.\u201d<\/p>\n<p>We can take it one step further:\u00a0If this number is multiplied by the average rate of the development team, then we can easily compute the cost of this effort in any given currency.<\/p>\n<p>This approach is great because management is able to forecast how much money (and time) it will cost to put the software back on track for the desired level of quality.<\/p>\n<p><a href=\"http:\/\/d1vqbpto5tbbz0.cloudfront.net\/blog\/wp-content\/uploads\/2015\/11\/09153600\/6812497415_092496ff3b_b.jpg\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"768\" class=\"alignnone wp-image-6042 size-full\" src=\"http:\/\/d1vqbpto5tbbz0.cloudfront.net\/blog\/wp-content\/uploads\/2015\/11\/09153600\/6812497415_092496ff3b_b.jpg\" alt=\"Technical Debt Calculation - Calculator\" srcset=\"https:\/\/d1vqbpto5tbbz0.cloudfront.net\/blog\/wp-content\/uploads\/2015\/11\/09153600\/6812497415_092496ff3b_b.jpg 1024w, https:\/\/d1vqbpto5tbbz0.cloudfront.net\/blog\/wp-content\/uploads\/2015\/11\/09153600\/6812497415_092496ff3b_b.jpg 300w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/a><\/p>\n<p><em><a title=\"Calculator image via Flickr\" href=\"https:\/\/www.flickr.com\/photos\/42931449@N07\/6812497415\/\" target=\"_blank\">Image credit<\/a><\/em><\/p>\n<h2>What\u2019s Happening Behind the Scenes?<\/h2>\n<p><span style=\"font-weight: 400;\">At this point, you&#8217;re probably wondering how all of these technical metrics can be boiled down to a single number. <\/span><\/p>\n<p><span style=\"font-weight: 400;\">The first step is to measure everything that contributes\u00a0to the technical debt: code duplication, code complexity, test coverage, dependency cycles and coupling, lack of documentation, and\u00a0programming rules violations. <\/span><\/p>\n<p><strong>Let me briefly explain how to calculate each of these technical debt components. <\/strong><\/p>\n<h3>Code Duplication<\/h3>\n<p><span style=\"font-weight: 400;\">Duplicate or copy-pasted code is usually expressed as the ratio of duplicated lines to the total lines of code within a\u00a0range of 0% (no duplications \u2014 perfect score) to 100% (everything has been copied and pasted at least once \u2014 although I doubt you&#8217;d\u00a0ever find such a project!) <\/span><\/p>\n<p><span style=\"font-weight: 400;\">There are many algorithms to detect duplicate code. It seems that the most popular one is to examine the same series of identical tokens with some occasional variation (adding or removing tokens). A token is the simplest programming language element such as an identifier, a keyword, a separator, an operator, a literal, or even a comment. <\/span><\/p>\n<p><span style=\"font-weight: 400;\">What a duplication detection mechanism does is split the lines of code into tokens, set the minimum number of identical tokens that can be considered duplicated code, and then search the code for the same series of tokens. <\/span><\/p>\n<p><span style=\"font-weight: 400;\">By utilizing this process for the complete codebase, it\u2019s easy to compute the number of duplicated lines of code and divide them by the total number of lines of code to get the percentage referenced above. <\/span><\/p>\n<h3><span style=\"font-weight: 400;\">Code Complexity<\/span><\/h3>\n<p><span style=\"font-weight: 400;\">Code complexity<\/span> <span style=\"font-weight: 400;\">can be expressed in many ways. The most widely-known metric is the <em>cyclomatic complexity,<\/em> which in simple words is the total number of different paths in a code unit (method, function, class, etc.). <\/span><\/p>\n<p><span style=\"font-weight: 400;\">Every unit of code by default has a complexity of one. Every branch in the code (if, case, switch statements) adds one to the complexity. Every exit path or exception (valid in some programming languages) also adds one to the overall complexity. <\/span><\/p>\n<p><span style=\"font-weight: 400;\">Although the accepted complexity per programming unit might vary from language to language or system to system, the following rules and ranges have been proven to work in most cases:<\/span><\/p>\n<ul>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">Complexity from 1 to 10: Normal<\/span><\/li>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">Complexity from 11 to 20: Moderate<\/span><\/li>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">Complexity from 21 to 50: Risky<\/span><\/li>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">Complexity over 50: Unstable\/Unmaintainable<\/span><\/li>\n<\/ul>\n<p><span style=\"font-weight: 400;\">To demonstrate this, let\u2019s quickly calculate the cyclomatic complexity of the following method:<\/span><\/p>\n<p style=\"padding-left: 60px;\"><b>public<\/b> <b>String <\/b><span style=\"font-weight: 400;\">getAgeType<\/span><span style=\"font-weight: 400;\">(<\/span> <b>int<\/b><span style=\"font-weight: 400;\"> age <\/span><span style=\"font-weight: 400;\">)<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span> <span style=\"font-weight: 400;\">{<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span> <b>if<\/b><span style=\"font-weight: 400;\">(<\/span><span style=\"font-weight: 400;\"> age &lt; 0 <\/span><span style=\"font-weight: 400;\">)<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span> <b>throw new<\/b> <b>Exception<\/b><span style=\"font-weight: 400;\"> (<\/span><span style=\"font-weight: 400;\">&#8220;Invalid age&#8221;);<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span> <b>if<\/b><span style=\"font-weight: 400;\">(<\/span><span style=\"font-weight: 400;\"> age &gt; 18 <\/span><span style=\"font-weight: 400;\">) {<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span> <b>return <\/b><span style=\"font-weight: 400;\">&#8220;Adult&#8221;;<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span> <span style=\"font-weight: 400;\">} <\/span><b>else {<\/b><b><br \/>\n<\/b> <b>return <\/b><span style=\"font-weight: 400;\">&#8220;Sorry you are not allowed to see the movie&#8221;;<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span> <span style=\"font-weight: 400;\">}<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">}<\/span><\/p>\n<p><span style=\"font-weight: 400;\">There are three conditional decisions, two return statements, and one exception. So,\u00a0the total cyclomatic complexity is\u00a0six.<\/span><\/p>\n<h3><span style=\"font-weight: 400;\">Test Coverage<\/span><\/h3>\n<p><span style=\"font-weight: 400;\">The next component of technical debt we will examine is test coverage, which consists of two metrics: <em>line coverage<\/em> and <em>branch coverage<\/em>. \u00a0<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Line coverage reports the total number of lines that have been hit at least once by a test case. Branch coverage reports the number of conditional branches that have been hit by test cases. <\/span><\/p>\n<p><span style=\"font-weight: 400;\">Take\u00a0the following code snippet as an example. <\/span><\/p>\n<p><span style=\"font-weight: 400;\">If there is only one test that tests the method by passing the value of \u201c15\u201d to the \u201cage\u201d parameter, then the line coverage will be 43% (3\/7 lines covered) and the branch coverage will be 33% (1\/3 branches covered). <\/span><\/p>\n<p style=\"padding-left: 60px;\"><b>public<\/b> <b>String <\/b><span style=\"font-weight: 400;\">getAgeType<\/span><span style=\"font-weight: 400;\">(<\/span> <b>int<\/b><span style=\"font-weight: 400;\"> age <\/span><span style=\"font-weight: 400;\">)<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span> <span style=\"font-weight: 400;\">{<\/span><\/p>\n<p style=\"padding-left: 60px;\"><span style=\"font-weight: 400;\">System.out.println(<\/span><span style=\"font-weight: 400;\">&#8220;Confirming age&#8230;&#8221;);<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span> <b>if<\/b><span style=\"font-weight: 400;\">(<\/span><span style=\"font-weight: 400;\"> age &lt; 0 <\/span><span style=\"font-weight: 400;\">)<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span> <b>throw new<\/b> <b>Exception<\/b><span style=\"font-weight: 400;\"> (<\/span><span style=\"font-weight: 400;\">&#8220;Invalid age&#8221;);<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span> <b>if<\/b><span style=\"font-weight: 400;\">(<\/span><span style=\"font-weight: 400;\"> age &gt; 18 <\/span><span style=\"font-weight: 400;\">) {<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span> <b>return <\/b><span style=\"font-weight: 400;\">&#8220;Adult&#8221;;<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span> <span style=\"font-weight: 400;\">} <\/span><b>else {<\/b><b><br \/>\n<\/b> <b>return <\/b><span style=\"font-weight: 400;\">&#8220;Sorry you are not allowed to see the movie&#8221;;<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span> <span style=\"font-weight: 400;\">}<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">}<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Finally we need to compute the overall test\u00a0coverage, which is a combination of line coverage and branch coverage.<\/span><\/p>\n<h3><span style=\"font-weight: 400;\">Dependency Cycles and Coupling<\/span><\/h3>\n<p><span style=\"font-weight: 400;\">Dependency\u00a0cycles and coupling describe the level of architectural quality and design of the system. An unwanted cycle can be reported between files, packages (namespaces), or even modules. <\/span><\/p>\n<p><span style=\"font-weight: 400;\">The easiest way to explain this is by the following example: Assume that File A is dependent on File B, File B is dependent on File C, and File C is dependent back on\u00a0File A. <\/span><\/p>\n<p><span style=\"font-weight: 400;\">This is a dependency cycle in its simplest form, and in general, those dependencies are unwanted. The more they appear in a system, the harder\u00a0the system is to understand and maintain. <\/span><\/p>\n<p><span style=\"font-weight: 400;\">Coupling describes the number of external files that depend on a particular file. The more dependencies a file has, the more likely it is to break when something is changed on those files. <\/span><\/p>\n<h3>Documentation and Rules<\/h3>\n<p><span style=\"font-weight: 400;\">The lack of documentation can sometimes be omitted from the technical debt calculation. <\/span><\/p>\n<p><span style=\"font-weight: 400;\">But, in cases where we need to ensure that the code is properly documented, a good approach is to measure the undocumented public API and report it as a ratio (how many public methods are undocumented vs\u00a0the total number of public methods). <\/span><\/p>\n<p><span style=\"font-weight: 400;\">Defects and rules violations can be handled using the same method. The usual pattern followed here is to check the codebase against a pre-defined and categorized set of quality rules and report which of them have been violated. <\/span><\/p>\n<p><span style=\"font-weight: 400;\">Each rule should be tagged with a category like performance, efficiency, maintainability, portability, security, etc. The trick here is to express everything \u2014 even duplications, complexity, etc. \u2014 as a rule. <\/span><\/p>\n<p><span style=\"font-weight: 400;\">For example,\u00a0if we want to ensure that every file has at least 50% code coverage, then we should create such a rule with this threshold.\u00a0Or, if\u00a0we don\u2019t accept methods with a complexity of 11 or more, then we should create a rule that will report when this occurs. <\/span><\/p>\n<p><span style=\"font-weight: 400;\">For every rule,\u00a0we need to determine\u00a0the time needed by the average developer to fix the problem. This is usually expressed in hours but can also be expressed in days. <\/span><\/p>\n<p><span style=\"font-weight: 400;\">The final step is to sum the total number of hours or days needed to fix all of the violated rules, which\u00a0represent all of the codebase technical debt. <strong>Voila \u2014 we have our technical debt metric expressed in man-days!<\/strong><\/span><\/p>\n<p><a href=\"http:\/\/d1vqbpto5tbbz0.cloudfront.net\/blog\/wp-content\/uploads\/2015\/11\/12140006\/Abstract-Numbers-vs-Ratio-cropped.jpg\"><img loading=\"lazy\" decoding=\"async\" width=\"364\" height=\"189\" class=\"alignnone wp-image-6091 size-full\" src=\"http:\/\/d1vqbpto5tbbz0.cloudfront.net\/blog\/wp-content\/uploads\/2015\/11\/12140006\/Abstract-Numbers-vs-Ratio-cropped.jpg\" alt=\"Technical Debt Calculation - Abstract Numbers vs Ratio\" srcset=\"https:\/\/d1vqbpto5tbbz0.cloudfront.net\/blog\/wp-content\/uploads\/2015\/11\/12140006\/Abstract-Numbers-vs-Ratio-cropped.jpg 364w, https:\/\/d1vqbpto5tbbz0.cloudfront.net\/blog\/wp-content\/uploads\/2015\/11\/12140006\/Abstract-Numbers-vs-Ratio-cropped.jpg 300w\" sizes=\"(max-width: 364px) 100vw, 364px\" \/><\/a><\/p>\n<p><em><a title=\"Image credit\" href=\"http:\/\/www.valkor.pl\/public\/assets\/promocje.jpg\" target=\"_blank\">Image credit<\/a><\/em><\/p>\n<h2><span style=\"font-weight: 400;\">Abstract Numbers vs\u00a0Ratio<\/span><\/h2>\n<p><span style=\"font-weight: 400;\">We&#8217;ve now demonstrated that,\u00a0even if technical debt is calculated based on several technical metrics, there\u2019s common ground for both sides of the team.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Technical and non-technical team members can share the same way of expressing technical debt in man-days or currency, and keep track of progress without needing to explain all the technical details. <\/span><\/p>\n<p><span style=\"font-weight: 400;\">Of course,\u00a0the developers will need\u00a0to dive into the technical deep-end\u00a0in order to work on reducing\u00a0the debt,\u00a0but this can be kept safely inside the dev team. <\/span><\/p>\n<h3>However, when it comes to the question: &#8220;How good or bad is the code quality of the product?,\u201d the number above is not enough.<\/h3>\n<p><span style=\"font-weight: 400;\">Let me elaborate on that. Assume that the development team says to the product owner that, in order to hit the goal of decreasing technical debt down to 90%, they need around 250 days (yes, a whole man-year!). Is that good or bad? Reasonable or not? <\/span><\/p>\n<p><span style=\"font-weight: 400;\">What does this\u00a0mean in terms of the code quality? Neither the developers nor the product owner would likely be able to decide simply by seeing this number. <\/span><\/p>\n<p><span style=\"font-weight: 400;\">The main reason is that we don\u2019t know the size of the project.\u00a0<\/span><span style=\"font-weight: 400;\">Are we talking about a green-field project with 30k lines of code started six months ago or a 15-year-old \u201clegacy,\u201d monolithic system with 1.5m lines of code?<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Clearly for the first case, one man-year to eliminate the technical debt is a really huge number, so the answer could be that the quality is bad. On the other hand, the latter example shows that the product seems to be in very good shape. Those 250 man-days don\u2019t look that bad for such a big codebase. <\/span><\/p>\n<p><span style=\"font-weight: 400;\">It took 15 years to produce this technical debt, whereas for the first product it took only six months for the same. <strong>The problem here is\u00a0reporting\u00a0the man-days without giving any information about the project size.<\/strong><\/span><\/p>\n<p><span style=\"font-weight: 400;\">A quick suggestion to overcome this issue would be to also report the total number of lines to the upper management and ask them to do some extra math to determine the overall quality level. <\/span><\/p>\n<p><span style=\"font-weight: 400;\">The problem is this\u00a0actually violates my previous statement: \u201c<\/span><i><span style=\"font-weight: 400;\">metrics should be simple, easy to understand, and objective.<\/span><\/i><span style=\"font-weight: 400;\">\u201d <\/span><\/p>\n<p><span style=\"font-weight: 400;\">Having to do additional calculations\u00a0increases complexity and doesn\u2019t guarantee that everyone will come up with the same conclusion about quality. Besides, there might be a case where\u00a0we need to compare the technical debt of two or more products. So again, the lines of code are not enough. <\/span><\/p>\n<p><span style=\"font-weight: 400;\">One last thing: if man-days or currency is our (only) technical debt metric, then what is the worst possible value? The best value is obviously zero, but what would be the worst? Honestly I have no answer on that, and I have seen some really, really large numbers reported on some projects.<\/span><\/p>\n<h3><span style=\"font-weight: 400;\">Given this,\u00a0the solution is to represent technical debt as a ratio instead of an abstract number (man-days, money spent, etc). <\/span><\/h3>\n<p><span style=\"font-weight: 400;\">This has several advantages over the previous tries:<\/span><\/p>\n<ul>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">It has both a best score (0%) and a worst score (100%).<\/span><\/li>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">It&#8217;s comparable to other projects because it contains the total lines of code.<\/span><\/li>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">It\u2019s still a single, easy to understand, and objective number.<\/span><\/li>\n<\/ul>\n<p><span style=\"font-weight: 400;\">A product with a technical debt ratio of 5% is clearly in better quality shape than a product with a ratio of 25%. But when is\u00a0the right time to start worrying about the code quality? <\/span><\/p>\n<p><span style=\"font-weight: 400;\">Although there are different types\u00a0of projects and every programming language has\u00a0its own characteristics, a safe rule of thumb is that codebases with a technical debt ratio over 10% should be considered candidates of poor quality. In such cases, t<\/span><span style=\"font-weight: 400;\">he management team should work with\u00a0the development team to\u00a0decide how they want to start eliminating the debt. <\/span><\/p>\n<p><span style=\"font-weight: 400;\">(Happily we will discuss different strategies and action plans to work on reducing technical debt in a future post. Stay tuned!)<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Before we move on to\u00a0the available options of technical debt calculation, I\u2019d like to clarify that both numbers we&#8217;ve discussed (man-days and the ratio) are equally important and complement one another. Both should be seriously considered before making any decision about the product quality or steps to eliminate the technical debt.<\/span><\/p>\n<h2><span style=\"font-weight: 400;\">Technical Debt Calculation<\/span><\/h2>\n<p><span style=\"font-weight: 400;\">At this point, we&#8217;ve nearly\u00a0run the whole marathon. The finish line is in sight!<\/span><\/p>\n<p><a href=\"http:\/\/d1vqbpto5tbbz0.cloudfront.net\/blog\/wp-content\/uploads\/2015\/11\/10131510\/10561900273_0418d19636_k.jpg\"><img loading=\"lazy\" decoding=\"async\" width=\"2048\" height=\"1365\" class=\"alignnone wp-image-6054 size-full\" src=\"http:\/\/d1vqbpto5tbbz0.cloudfront.net\/blog\/wp-content\/uploads\/2015\/11\/10131510\/10561900273_0418d19636_k.jpg\" alt=\"Technical Debt Calculation - Finish Line\" srcset=\"https:\/\/d1vqbpto5tbbz0.cloudfront.net\/blog\/wp-content\/uploads\/2015\/11\/10131510\/10561900273_0418d19636_k.jpg 2048w, https:\/\/d1vqbpto5tbbz0.cloudfront.net\/blog\/wp-content\/uploads\/2015\/11\/10131510\/10561900273_0418d19636_k.jpg 300w, https:\/\/d1vqbpto5tbbz0.cloudfront.net\/blog\/wp-content\/uploads\/2015\/11\/10131510\/10561900273_0418d19636_k.jpg 1024w\" sizes=\"(max-width: 2048px) 100vw, 2048px\" \/><\/a><\/p>\n<p><em><a title=\"Finish line image via Flickr\" href=\"https:\/\/www.flickr.com\/photos\/perspective\/10561900273\/\" target=\"_blank\">Image credit<\/a><\/em><\/p>\n<h3><span style=\"font-weight: 400;\">How exactly do we calculate\u00a0the technical debt in man-days, currency spent, and ratio? <\/span><\/h3>\n<p><span style=\"font-weight: 400;\">Manual computation is out of the question even for very small projects. <\/span><\/p>\n<p><span style=\"font-weight: 400;\">One could take\u00a0the whole day to do static code analysis, compute duplications, complexity, and design issues, evaluate security and performance, measure the code coverage and test quality, and many more things in order to come up with the component metrics. Then e<\/span><span style=\"font-weight: 400;\">very single metric must be given a weight in order to compute the one and only technical debt number. <\/span><\/p>\n<p><span style=\"font-weight: 400;\">Additionally, this should not be an ad-hoc process but one in which both the development side and product\/management\/customer side\u00a0are\u00a0able to view the latest reports on a daily basis. <\/span><\/p>\n<p><span style=\"font-weight: 400;\">I guess I probably don\u2019t need to say\u00a0anything else to convince you that it can&#8217;t (or shouldn&#8217;t)\u00a0be done manually. \ud83d\ude42<\/span><\/p>\n<h3><span style=\"font-weight: 400;\">So, the next decision is whether\u00a0we want to implement an in-house system or use an external tool that will do the hard work for us. <\/span><\/h3>\n<p><span style=\"font-weight: 400;\">I would never recommend\u00a0the first approach unless you want to really invest in that area, creating a product specifically for that purpose and then earning revenue by selling it or services based on it.\u00a0<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Luckily, there are a plethora of tools out there that can save\u00a0time and help us calculate\u00a0the technical debt on a daily basis. <\/span><\/p>\n<p><span style=\"font-weight: 400;\">In my next post, I will share\u00a0the most popular ones,\u00a0explaining their key\u00a0features and how you can use them to analyze a small codebase from Github. <\/span><\/p>\n<h2><span style=\"font-weight: 400;\">In Summary<\/span><\/h2>\n<p><span style=\"font-weight: 400;\">In this post, we discussed the value of reporting technical debt in a way\u00a0that can be easily interpreted and understood by both technical and non-technical team members. <\/span><span style=\"font-weight: 400;\">We also identified the challenge\u00a0of expressing technical debt\u00a0as a single number that incorporates project size metrics. <\/span><\/p>\n<p><span style=\"font-weight: 400;\">Both man-days and ratio metrics should be used by management and development teams in determining\u00a0their strategy for reducing\u00a0technical debt because each of them answers a different but equally important question. <\/span><\/p>\n<p><span style=\"font-weight: 400;\">For man-days, the question is &#8220;what is the effort required?,&#8221; whereas for the ratio it&#8217;s &#8220;how good or bad\u00a0is the code quality?&#8221;<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Finally, we\u00a0explained how difficult it is to manually calculate all of the components of technical debt on a daily basis, especially in large codebases with many contributors. We concluded that the only reasonable approach is to use one of the existing code quality tools that I will present in my next post. <\/span><\/p>\n<p>&nbsp;<\/p>\n<p><em><a title=\"Featured image via Flickr\" href=\"https:\/\/www.flickr.com\/photos\/franganillo\/3676227162\/\" target=\"_blank\">Featured image credit<\/a><\/em><\/p>\n","protected":false},"excerpt":{"rendered":"<p>This intro to technical debt calculation explains how to calculate technical debt and express it in a way that can be understood by non-technical folks.<\/p>\n","protected":false},"author":70,"featured_media":6041,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[5],"tags":[485,479,478,467,481,364,482,410,483,404,480],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v22.6 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>How to Calculate Technical Debt and Express It Clearly<\/title>\n<meta name=\"description\" content=\"This intro to technical debt calculation explains how to calculate technical debt and express it in a way that can be understood by non-technical folks.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/thinkapps.com\/blog\/development\/technical-debt-calculation\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How to Calculate Technical Debt and Express It Clearly\" \/>\n<meta property=\"og:description\" content=\"This intro to technical debt calculation explains how to calculate technical debt and express it in a way that can be understood by non-technical folks.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/thinkapps.com\/blog\/development\/technical-debt-calculation\/\" \/>\n<meta property=\"og:site_name\" content=\"Build Blog by ThinkApps | Content on Entrepreneurship, Mobile Apps, Web Platforms and more\" \/>\n<meta property=\"article:published_time\" content=\"2015-11-12T14:00:06+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2015-11-11T23:59:35+00:00\" \/>\n<meta property=\"og:image\" content=\"http:\/\/d1vqbpto5tbbz0.cloudfront.net\/blog\/wp-content\/uploads\/2015\/11\/09153316\/3676227162_ff6e2abe2e_o.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"1200\" \/>\n\t<meta property=\"og:image:height\" content=\"800\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Patroklos Papapetrou\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Patroklos Papapetrou\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"15 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/thinkapps.com\/blog\/development\/technical-debt-calculation\/\",\"url\":\"https:\/\/thinkapps.com\/blog\/development\/technical-debt-calculation\/\",\"name\":\"How to Calculate Technical Debt and Express It Clearly\",\"isPartOf\":{\"@id\":\"http:\/\/localhost:8080\/blog\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/thinkapps.com\/blog\/development\/technical-debt-calculation\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/thinkapps.com\/blog\/development\/technical-debt-calculation\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/d1vqbpto5tbbz0.cloudfront.net\/blog\/wp-content\/uploads\/2015\/11\/09153316\/3676227162_ff6e2abe2e_o.jpg\",\"datePublished\":\"2015-11-12T14:00:06+00:00\",\"dateModified\":\"2015-11-11T23:59:35+00:00\",\"author\":{\"@id\":\"http:\/\/localhost:8080\/blog\/#\/schema\/person\/bbff910ac26ea64d3ed23cdcdb3f166a\"},\"description\":\"This intro to technical debt calculation explains how to calculate technical debt and express it in a way that can be understood by non-technical folks.\",\"breadcrumb\":{\"@id\":\"https:\/\/thinkapps.com\/blog\/development\/technical-debt-calculation\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/thinkapps.com\/blog\/development\/technical-debt-calculation\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/thinkapps.com\/blog\/development\/technical-debt-calculation\/#primaryimage\",\"url\":\"https:\/\/d1vqbpto5tbbz0.cloudfront.net\/blog\/wp-content\/uploads\/2015\/11\/09153316\/3676227162_ff6e2abe2e_o.jpg\",\"contentUrl\":\"https:\/\/d1vqbpto5tbbz0.cloudfront.net\/blog\/wp-content\/uploads\/2015\/11\/09153316\/3676227162_ff6e2abe2e_o.jpg\",\"width\":1200,\"height\":800,\"caption\":\"Technical Debt Calculation\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/thinkapps.com\/blog\/development\/technical-debt-calculation\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"http:\/\/localhost:8080\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"How to Calculate Technical Debt and Express It Clearly\"}]},{\"@type\":\"WebSite\",\"@id\":\"http:\/\/localhost:8080\/blog\/#website\",\"url\":\"http:\/\/localhost:8080\/blog\/\",\"name\":\"Build Blog by ThinkApps | Content on Entrepreneurship, Mobile Apps, Web Platforms and more\",\"description\":\"\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"http:\/\/localhost:8080\/blog\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"http:\/\/localhost:8080\/blog\/#\/schema\/person\/bbff910ac26ea64d3ed23cdcdb3f166a\",\"name\":\"Patroklos Papapetrou\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"http:\/\/localhost:8080\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/a6d5dbc6412ef643e03ffc4e2657e976?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/a6d5dbc6412ef643e03ffc4e2657e976?s=96&d=mm&r=g\",\"caption\":\"Patroklos Papapetrou\"},\"description\":\"Patroklos Papapetrou is a software architect addicted to software quality and an agile team leader with almost 20 years of experience in software development. He is one of the authors of SonarQube in Action and is currently writing The Art of Software Gardening. (He treats software systems as flowers and thus prefers to call himself a software gardener.) Patroklos is also an occasional speaker, giving talks about clean code, code quality, and software gardening.\",\"sameAs\":[\"https:\/\/gr.linkedin.com\/in\/ppapapetrou\",\"https:\/\/x.com\/softwaregarden\"],\"url\":\"https:\/\/thinkapps.com\/blog\/author\/patroklos-papapetrou\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"How to Calculate Technical Debt and Express It Clearly","description":"This intro to technical debt calculation explains how to calculate technical debt and express it in a way that can be understood by non-technical folks.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/thinkapps.com\/blog\/development\/technical-debt-calculation\/","og_locale":"en_US","og_type":"article","og_title":"How to Calculate Technical Debt and Express It Clearly","og_description":"This intro to technical debt calculation explains how to calculate technical debt and express it in a way that can be understood by non-technical folks.","og_url":"https:\/\/thinkapps.com\/blog\/development\/technical-debt-calculation\/","og_site_name":"Build Blog by ThinkApps | Content on Entrepreneurship, Mobile Apps, Web Platforms and more","article_published_time":"2015-11-12T14:00:06+00:00","article_modified_time":"2015-11-11T23:59:35+00:00","og_image":[{"width":1200,"height":800,"url":"http:\/\/d1vqbpto5tbbz0.cloudfront.net\/blog\/wp-content\/uploads\/2015\/11\/09153316\/3676227162_ff6e2abe2e_o.jpg","type":"image\/jpeg"}],"author":"Patroklos Papapetrou","twitter_misc":{"Written by":"Patroklos Papapetrou","Est. reading time":"15 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/thinkapps.com\/blog\/development\/technical-debt-calculation\/","url":"https:\/\/thinkapps.com\/blog\/development\/technical-debt-calculation\/","name":"How to Calculate Technical Debt and Express It Clearly","isPartOf":{"@id":"http:\/\/localhost:8080\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/thinkapps.com\/blog\/development\/technical-debt-calculation\/#primaryimage"},"image":{"@id":"https:\/\/thinkapps.com\/blog\/development\/technical-debt-calculation\/#primaryimage"},"thumbnailUrl":"https:\/\/d1vqbpto5tbbz0.cloudfront.net\/blog\/wp-content\/uploads\/2015\/11\/09153316\/3676227162_ff6e2abe2e_o.jpg","datePublished":"2015-11-12T14:00:06+00:00","dateModified":"2015-11-11T23:59:35+00:00","author":{"@id":"http:\/\/localhost:8080\/blog\/#\/schema\/person\/bbff910ac26ea64d3ed23cdcdb3f166a"},"description":"This intro to technical debt calculation explains how to calculate technical debt and express it in a way that can be understood by non-technical folks.","breadcrumb":{"@id":"https:\/\/thinkapps.com\/blog\/development\/technical-debt-calculation\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/thinkapps.com\/blog\/development\/technical-debt-calculation\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/thinkapps.com\/blog\/development\/technical-debt-calculation\/#primaryimage","url":"https:\/\/d1vqbpto5tbbz0.cloudfront.net\/blog\/wp-content\/uploads\/2015\/11\/09153316\/3676227162_ff6e2abe2e_o.jpg","contentUrl":"https:\/\/d1vqbpto5tbbz0.cloudfront.net\/blog\/wp-content\/uploads\/2015\/11\/09153316\/3676227162_ff6e2abe2e_o.jpg","width":1200,"height":800,"caption":"Technical Debt Calculation"},{"@type":"BreadcrumbList","@id":"https:\/\/thinkapps.com\/blog\/development\/technical-debt-calculation\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"http:\/\/localhost:8080\/blog\/"},{"@type":"ListItem","position":2,"name":"How to Calculate Technical Debt and Express It Clearly"}]},{"@type":"WebSite","@id":"http:\/\/localhost:8080\/blog\/#website","url":"http:\/\/localhost:8080\/blog\/","name":"Build Blog by ThinkApps | Content on Entrepreneurship, Mobile Apps, Web Platforms and more","description":"","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"http:\/\/localhost:8080\/blog\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":"Person","@id":"http:\/\/localhost:8080\/blog\/#\/schema\/person\/bbff910ac26ea64d3ed23cdcdb3f166a","name":"Patroklos Papapetrou","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"http:\/\/localhost:8080\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/a6d5dbc6412ef643e03ffc4e2657e976?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/a6d5dbc6412ef643e03ffc4e2657e976?s=96&d=mm&r=g","caption":"Patroklos Papapetrou"},"description":"Patroklos Papapetrou is a software architect addicted to software quality and an agile team leader with almost 20 years of experience in software development. He is one of the authors of SonarQube in Action and is currently writing The Art of Software Gardening. (He treats software systems as flowers and thus prefers to call himself a software gardener.) Patroklos is also an occasional speaker, giving talks about clean code, code quality, and software gardening.","sameAs":["https:\/\/gr.linkedin.com\/in\/ppapapetrou","https:\/\/x.com\/softwaregarden"],"url":"https:\/\/thinkapps.com\/blog\/author\/patroklos-papapetrou\/"}]}},"_links":{"self":[{"href":"https:\/\/thinkapps.com\/blog\/wp-json\/wp\/v2\/posts\/5984"}],"collection":[{"href":"https:\/\/thinkapps.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/thinkapps.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/thinkapps.com\/blog\/wp-json\/wp\/v2\/users\/70"}],"replies":[{"embeddable":true,"href":"https:\/\/thinkapps.com\/blog\/wp-json\/wp\/v2\/comments?post=5984"}],"version-history":[{"count":51,"href":"https:\/\/thinkapps.com\/blog\/wp-json\/wp\/v2\/posts\/5984\/revisions"}],"predecessor-version":[{"id":6092,"href":"https:\/\/thinkapps.com\/blog\/wp-json\/wp\/v2\/posts\/5984\/revisions\/6092"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/thinkapps.com\/blog\/wp-json\/wp\/v2\/media\/6041"}],"wp:attachment":[{"href":"https:\/\/thinkapps.com\/blog\/wp-json\/wp\/v2\/media?parent=5984"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/thinkapps.com\/blog\/wp-json\/wp\/v2\/categories?post=5984"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/thinkapps.com\/blog\/wp-json\/wp\/v2\/tags?post=5984"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}