当前位置:网站首页>The power of code refactoring: how to measure the success of refactoring
The power of code refactoring: how to measure the success of refactoring
2022-06-23 03:33:00 【Micro Stone】

Many engineering teams are trying to measure the effectiveness of their refactoring efforts . Let's take a look at what can help you measure the success of refactoring 5 Indicators .
Code refactoring provides developers with much-needed mental rest , I think many developers can relate to this . Writing code all day is very demanding , Especially if you create new features every day . It's a heavy job , Developers often need some space to think about the overall organization of the code base and review areas for improvement .
This is what code refactoring does . It provides developers with this much-needed mental rest , And give them the opportunity to solve higher-level code base related problems . however , This is also a good time to check your code against the code base guidelines . No code base is perfect . A small mistake that violates the rules leads to “ The main ” Branch .
most important of all , It reduces Technical debt . Developers have the opportunity to explore the code base and learn about other parts or features they have not touched . This is a nice side benefit of code refactoring .
However , Many teams are trying to measure the effectiveness of their refactoring efforts . Team leader or CTO It is often necessary to report to management . without “ hard ” Numbers , It is hard to justify the time spent refactoring the code base and developing new functions . For many startups , The pressure is always there . This constant pressure makes it difficult to justify code base refactoring .
This article focuses on different metrics that can be used to measure the success of code refactoring .
Metrics to measure the success of refactoring
You can implement several metrics to measure the success of code base refactoring . You don't need to achieve all the metrics , Because code refactoring is still a logical job . however , Specific metrics can be a good indicator of whether the refactoring is successful .
1. Number of open code base problems
As the number of open code base problems grows , This is a dangerous sign that the quality of the code base is declining . however , In addition to being a danger signal , It can also help you track the success of refactoring efforts . Your obvious goal is to start the next sprint Previously, the number of open code base problems was reduced to zero .
You hope to solve these problems as soon as possible , Because they are still relatively small problems . however , As your code base evolves over time , Small problems can become complex and time consuming . You want to avoid this , Because it will make you more backward - In terms of time and cost .
If you want to know how to track and understand problems with your code base , Please try Stepsize VSCode and JetBrains Expand . This tool will help you :
Connect your problem tool to the code
Share knowledge about the time bomb in the code base within the team
Prioritize issues and track progress
2. In the code base TODO Number
Usually , You don't want to see too much in the code base TODO. This is a sign that things need to be improved but there is no positive solution . As your code base evolves ,TODO The context of may be lost , It is difficult to understand the original problem , what's more , Difficult to solve TODO.
therefore , When refactoring is used, you can delete idle from the code base TODO or You can organize your... In a way that allows you to view the context and resolve them more quickly later TODO.
3. Number of failed unit tests
Many code bases suffer from unit test failures . As long as the percentage of failed unit tests remains relatively low , This does not threaten the quality of your code base .
however , Note the number of failed tests . This is a red flag to start code refactoring and measure the success of code refactoring . At the beginning of a new sprint Before , You want to reduce the number of failed tests to close to zero .
4. Code coverage
Code coverage metrics are closely related to measuring the number of failed unit tests . however , To measure the success of code refactoring , You also want to know how the quality of the code base can be improved . One way to measure the quality of a code base is to measure code coverage , Because it tells you how much you can trust your code base . If the test is written correctly , Higher code coverage usually leads to higher code quality .
No code base is perfect , however , Please try to approach 100% Code coverage . If you don't have the resources to completely cover your code base by testing , Make sure you cover the most critical path in the entire code . This will help you increase trust in your code .
Common pitfalls : Don't forget to write... When refactoring code 、 Update or change tests . You don't want to improve the code , But to reduce code coverage . let me put it another way , Refactoring and code testing go hand in hand .
5. Measurement repetition
Measuring repeatability is not a high-level indicator that you should aim at . however , When refactoring code , It is still a noteworthy indicator . When the contemporary code base grows , People don't always fully understand the code base . therefore , They may not know that a help library or function already exists , And create a new library or function with the same function . The same often happens to modules in larger code bases .
First , Try to identify duplicate code and note the location to measure the success of the refactoring . You can revisit this list to measure how many lines of duplicate code were removed from the code base after code refactoring .
How to use these metrics to improve your refactoring process ?
If you consider code base refactoring , Please do not join directly without a plan . You need to set goals and boundaries for the refactoring process , To make it easier to measure success .
First , You want Collect the problems to be solved during the refactoring sprint in this code base ** All code base related issues for . If some tickets are missing , Make sure to track them or create problems . for example , View all of the... That you want to remove from the code base TODO.
Once you have identified the problem to be solved , Can Develop metrics to help track the success of refactoring . for example , You want to remove three duplicate modules and increase code coverage 15%.
Now that you have collected all the questions and set goals , It's time to share knowledge about the codebase and why specific problems need to be solved . If you don't solve the problem , You can explain the background of the problem and its impact on the project . This is also a good time to share knowledge about new parts of the code base , So all developers can keep up .
Last , Give priority to the problem you want to solve first . You won't be able to complete all the questions in the refactoring week or any timeline you set up . therefore , Before dealing with less important issues , Please make sure to solve the most influential organizational problems first .
To end the code base refactoring , please ** Collect all indicator data and validate it against the goals you set .** Now is a good time to discuss what went wrong and how to improve the code base refactoring process in the future . Don't expect everything to go well . There may be mistakes , This is good .
Conclusion : The success and purpose of refactoring ?
No matter how you measure refactoring success , Make sure you don't use these metrics to evaluate the performance of programmers or to decide on promotions or similar things .
Refactoring code aims to solve code base and organization problems as early as possible . If not dealt with , They may escalate into more serious problems , Need more time and resources to solve .
This is also one of the main arguments for organizing code refactoring . In startups , There is always pressure to deliver new functionality . however , As a team , Sometimes you have to step back to evaluate the code and refactor it to Maintain its quality .
边栏推荐
- Chapter V kubernetes quick start
- TRTC zero foundation -- Video subscription on the code
- Analysis on the development status of China's watch industry in 2021: a large number of electric watches are imported [figure]
- Easygbs solution to video playback failure caused by tcp/udp configuration problems
- Goframe framework: log configuration management
- China's economy has entered the stage of "the third mock examination coexisting", and JD and Shopify have jointly arranged global DTC
- Establishment of JMeter distributed pressure measurement environment
- Golang resource embedding scheme
- Analysis on the development of China's graphene industry chain in 2021: with the support of energy conservation and environmental protection policies, the scale of graphene industry will continue to e
- Network security memorabilia - Summary of vulnerability exploitation events in 2021
猜你喜欢

Encryption related to returnee of national market supervision public service platform

Google Earth Engine(GEE)——长时间序列逐月VCI数据提取分析和面积计算(墨西哥为例)

1-1VMware介绍
![Analysis of China's integrated circuit industry chain in 2021: huge downstream market demand [figure]](/img/de/d73805aaf4345ca3d2a7baf85aab8d.jpg)
Analysis of China's integrated circuit industry chain in 2021: huge downstream market demand [figure]
![Analysis on development history, industrial chain, output and enterprise layout of medical polypropylene in China in 2020 [figure]](/img/28/ebfc25ec288627706e15a07e6bdb77.jpg)
Analysis on development history, industrial chain, output and enterprise layout of medical polypropylene in China in 2020 [figure]

Analysis on the development of China's satellite navigation industry chain in 2021: satellite navigation is fully integrated into production and life, and the satellite navigation industry is also boo

1058 multiple choice questions (20 points)

Detailed discussion on modular architecture design of MCU firmware

新版kali切换最高账户

【贪心】leetcode991. Broken Calculator
随机推荐
CentOS install redis
What should be prepared to develop the company's official website?
SwiftUI 组件大全之使用 ScrollView 和 GeometryReader 创建动画 3D卡片 滚动效果
Easynvr is displayed online after cascading the upper platform, but what is the reason for the video playback timeout?
JS counts the number of times a string appears in another string
Flink practice tutorial: advanced 7- basic operation and maintenance
CFs of cifs/smb protocol is mounted on win10/2019. Error 1272 is reported. The security policy prevents unauthenticated guest access
How to print multiple barcode labels on one sheet of paper
What is the difference between JS undefined and null
Parsing the implementation of easygbs compatible token as parameter passing
Flowable refactoring process editor to obtain user information
An implementation of universal interface caching Middleware
【二分】leetcode1011. Capacity To Ship Packages Within D Days
The difference between the use of return, break and continue in the if statement in JS
Chapter IV open source projects and deployment
Fetch request details
JSON. Function of the stringify() optional parameter
【贪心】leetcode991. Broken Calculator
Build information query applet by using micro build
QUIC or TCP