Refactoring

Summarized using AI

Here Be Dragons: The Hidden Gems of Tech Debt

Ernesto Tagwerker • February 28, 2023 • Providence, RI

In the talk "Here Be Dragons: The Hidden Gems of Tech Debt", Ernesto Tagwerker shares insights into identifying and managing technical debt within codebases. With an emphasis on practical tools, Tagwerker introduces a range of strategies to locate and address the most unmaintainable sections of code, creatively dubbed 'dragons'.

Key Points:

  • Understanding 'Here Be Dragons': The term is inspired by historical cartography, representing unexplored or dangerous areas. Tagwerker uses this metaphor to discuss areas of technical debt in codebases, one should always be cautious of.

  • Identifying Technical Debt: The talk categorizes four types of dragons to help locate technical debt:

    • Complexity Dragon: Refers to the most complex files within a codebase. Tools like Flog can help generate complexity scores, pinpointing the most convoluted parts of the code.
    • Smelly Dragon: This dragon represents code smells, which are indicators of poorly structured code. The tool Reek can identify common code smells, helping developers avoid potential pitfalls.
    • Shape-Shifting Dragon: Symbolizes files that change frequently due to evolving requirements. By examining churn counts through Git or the Churn gem, developers can evaluate the stability of these files.
    • Untested Dragon: Represents areas of code that have not been adequately tested. SimpleCov can assess code coverage and indicate which sections lack sufficient testing.
  • Combining Insights with RubyCritic: Tagwerker promotes RubyCritic as an essential tool for creating comprehensive reports on code quality, combining insights from complexity, code smells, and coverage into a single GPA score. This helps prioritize which areas of the codebase need urgent attention.

Conclusion:

Tagwerker encourages developers to make data-driven decisions regarding technical debt. By utilizing the discussed tools, teams can strategically prioritize refactoring and enhance code quality over time. The takeaway is to define what constitutes a 'dragon' within your projects and to utilize the right toolkit to combat these issues, ensuring a gradual improvement in code sustainability.

Here Be Dragons: The Hidden Gems of Tech Debt
Ernesto Tagwerker • February 28, 2023 • Providence, RI

How do you find the most unmaintainable code in your codebase? What will you prioritize in your next technical debt spike, and why?

In this talk you will learn how you can use RubyCritic, SimpleCov, Flog, Reek, and Skunk to slay dragons in your next refactoring adventure! Find out how the relationship between churn, complexity, and code coverage can give you a common language to talk about code quality and increase trust in your code.

RubyConf 2022 Mini

00:00:00.299 Hello everyone, and welcome.
00:00:11.719 We're here to talk about dragons and technical debt.
00:00:12.460 My name is Ernesto, and you can find me on Twitter or GitHub under the handle etacworker.
00:00:16.500 My pronouns are he/him, and I'm originally from Argentina. For the next three weeks, you might catch me watching football, or as you might call it, soccer.
00:00:24.859 I currently live in Philadelphia. I'm one of the organizers of the Philly Ruby Meetup, and of course, we love the Eagles and table tennis.
00:00:38.520 Aside from that, I love open source and Ruby. I wouldn’t be here speaking today if it weren’t for the work of many other people who published their code.
00:00:44.600 When I'm pairing with my daughter, she usually drives, meaning she's the one coding, and I navigate and help her with the libraries I maintain.
00:01:14.159 I want to take a moment to thank my sponsors: my wife Claire, my son Teo, and my daughter Lily. I wouldn’t be here today if it weren't for their support.
00:01:42.720 When I'm not spending time with my family, I work at my company called Ombu Labs, where we focus extensively on Ruby on Rails, JavaScript, and open-source projects.
00:02:06.680 A few years ago, we launched a service called fastruby.io that's focused on helping companies upgrade to more recent versions of Ruby and Rails.
00:02:15.900 The tools I'll discuss today are something we use on a weekly basis to assess whether a project is worth working on because not all applications are ready for upgrade.
00:02:30.780 This gives me the opportunity to work on open source frequently. I'm a co-maintainer of RubyCritic, Skunk, Bundler, Leak, and Next Rails.
00:03:00.540 Now, let’s discuss the concept of 'Here Be Dragons.' I know that many people might be wondering what this is all about—is it a game, or just a meme? There’s a story behind this.
00:03:31.380 In the 16th century, cartographers would create maps and place labels that read 'Here be dragons' to indicate areas that were unexplored. They sometimes drew monsters on those maps to signal danger and warning.
00:04:22.440 While I love this story, it's worth mentioning that it isn’t entirely true. There are no known maps that explicitly say 'Here be dragons.' However, there is a globe called the Hunt-Lennox Globe that contains that phrase.
00:04:42.600 If you're ever in New York, you can visit the public library to see it, or you can find a 3D model online that showcases the phrase.
00:05:12.960 Now, let’s pivot back to the topic of code. What if there were a map for your codebase? Imagine joining a team and instead of asking around about thorny issues, you could simply look at a map labeled with warnings.
00:05:22.200 What if you could translate the phrase 'Here be dragons' into 'Be careful with this part of the codebase; nobody wants to touch it because there’s a lot of technical debt'?
00:05:51.480 So how do you locate these dragons in your codebase? Identifying technical debt can be straightforward at times, even staring right at you, yet you may overlook it.
00:06:13.660 Of course, we will talk about technical debt and dragons interchangeably. Today, I'll address four different 'dragons': the Complexity Dragon, the Smelly Dragon, the Shape-Shifting Dragon, and the Untested Dragon.
00:06:34.720 Let's start with the first dragon: the complexity dragon. If I were to ask you where to find the technical debt in your codebase, you might say, 'Just find the most complex files.'
00:06:57.120 Often, these files are chaotic, and you might open one and find yourself frustrated, wondering where to begin refactoring.
00:07:05.640 To stop relying on gut feelings, we can leverage tools that provide measurable insights. For instance, we can examine a specific file containing a method that performs computations and checks a condition.
00:07:40.560 Using a tool like Flog, we can get a report on the most complicated code, and you can install Flog to generate a complexity score when run against your files.
00:08:50.220 Each operation in your code assigns a numerical value: assignments are worth 1.2, evaluates worth 6.0, etc. Understanding this scoring helps evaluate complexity in measurable terms.
00:09:48.960 However, Flog alone won't highlight issues such as code smells or code duplication. That's where the Smelly Dragon comes in.
00:10:08.519 You might encounter a file replete with code smells, signifying areas where the code could be hard to maintain or read, not necessarily wrong but indicating potential debt.
00:10:38.760 For example, while duplication is a code smell, it’s often far cheaper than making incorrect abstractions. Having good tests is crucial for maintaining code quality.
00:10:56.940 To find these code smells, consider using a tool called Reek, which provides a crowdsourced repository of common code smells with explanations.
00:11:03.720 Reek utilizes a Ruby parser to scan your codebase, and it can identify specific smells in your files. Even small files can contain significant code smells, which highlights their presence.
00:11:45.840 As an example, if you review a file and find an 'irresponsible module' warning due to a lack of documentation or comments, like no clear variable naming, you're uncovering actionable items.
00:12:14.040 Next, we address the Shape-Shifting Dragon, which refers to files that continuously change because of evolving requirements. We use Git for tracking these changes.
00:12:49.740 By executing 'git log', you can find a file's churn count and gather information about its stability over time. If you aren't using Git, there's a Ruby gem called Churn that supports other version control systems.
00:13:19.380 Churn can provide a detailed analysis of changes within the Ruby files over an extended timeframe, which, when correlated with other metrics, becomes valuable.
00:13:46.740 Ultimately, to effectively combine complexity, code smells, and churn, RubyCritic is an excellent tool to consider. It can create a detailed HTML report summarizing all these concerns.
00:14:27.234 This report includes various insights, represented by a GPA score similar to an academic grading scale. The goal is to focus on files that are challenging to comprehend and maintain.
00:15:06.780 The GPA score is computed based on complexity and code smells from several tools, giving you a comprehensive overview of your codebase's health.
00:15:48.120 Different sections of the graph provide insights into where you want to focus your efforts. The lower left segment is ideal, indicating low churn and low complexity.
00:16:39.180 As you traverse through the graph, you'll find problem areas that might require immediate attention, as they tend to be complex and change frequently.
00:17:23.880 The fourth and final dragon I want to bring to your attention is the Untested Dragon. This dragon is particularly troublesome because it hasn't been tested in a long time, making it unpredictable.
00:17:55.440 Good news is that we have a tool called SimpleCov that allows us to calculate code coverage. This tool is easy to add to your project.
00:18:28.920 Once integrated, it can provide reports on which files have adequate tests and which don’t, informing you of potential risk areas in your codebase.
00:19:10.920 The combination of RubyCritic and SimpleCov allows for a comprehensive means of assessing your codebase, using coverage percentage as an essential performance indicator.
00:19:55.680 Let’s summarize everything we discussed. During our sprint, if we have time to refactor files, we should prioritize based on tools that provide technical debt scores.
00:20:48.060 If you discover that two files have equal technical debt scores, investigating their test coverage will guide your decision on which file is safer to refactor.
00:21:19.820 Combining insights from complexity, code smells, and code coverage allows you to make informed decisions regarding technical debt, leading to more sustainable code.
00:22:42.720 As we dive deeper into code analytics, it’s vital to be strategic and to choose dragons wisely for slaying. Remember to make it data-driven, rather than relying on gut instinct.
00:23:36.180 Finally, I encourage you all to define what constitutes a 'dragon' for your projects and choose the right toolkit to combat them.
00:24:11.160 Focus on measurable targets and improve your codebase gradually. Thank you very much for your attention, and let’s embrace this journey together.
Explore all talks recorded at RubyConf 2022 Mini
+29