当前位置:网站首页>Pits encountered in refactoring code (1)
Pits encountered in refactoring code (1)
2022-06-24 03:34:00 【mariolu】
One 、 The modified code has enough tests
I have to make sure that the code I'm going to modify has a reliable set of tests . These tests are essential . Following the refactoring technique as much as possible can avoid the introduction of the vast majority of bug The circumstances of , But I am human after all , After all, it is possible to make mistakes .
- Offline test environment :
- Online grayscale environment :
- Online regression testing : Set the kafka Drop logs for testing
Two 、 Long function :
Algorithmic students like stacking code , Do not delete even unused code . It used to just delete an unused pointer in a structure , It saves nearly half of the memory space . Because this structure is a basic unit of the model . Loading models is a big memory consumer .
2.1 Extract Method
function /function Methods corresponding to object-oriented languages /method, Or process /procedure, Or subroutines /subroutine.
All you need to do is browse through a piece of code , Understand its role , Then refine it into a separate function , And name the function for the purpose of this code .
2.2 When to put code into a separate function , There are many different views
Some people think that considering the length of the code , There is a reuse perspective , Think of code that has been used more than once , You should put a separate function , Code that has only been used once remains inline (inline). But the most reasonable view here is to “ Intention and realization are separated ”. If you need to spend time browsing a piece of code to figure out what it is doing , Then the code should be extracted in a function . You can see the purpose of the function at a glance , Most of the time, you don't need to care about how the function achieves its purpose .
Once you accept this rule , Just form a habit : Write very small functions , Usually only a few lines .
Some people worry that short functions will cause a large number of calls and affect performance . But modern compilers are very rare , And short functions are easier to cache .
边栏推荐
- How to register a trademark? Is the process troublesome?
- MySQL stored procedure + function
- On Sunday, I rolled up the uni app "uview excellent UI framework"
- Velocitytracker use
- How to select a server with appropriate configuration when planning to build a live broadcast platform
- [new double 11] the latest interpretation of Tencent cloud double 11! Get 11000 yuan voucher now!!
- What technology does cloud computing elasticity scale? What are the advantages of elastic scaling in cloud computing?
- Actual combat | how to use micro build low code to realize tolerance application
- Which domestic cloud desktop server is good? What are the security guarantees for cloud desktop servers?
- Concise and practical time code
猜你喜欢

QT creator tips

On Sunday, I rolled up the uni app "uview excellent UI framework"

Sorting out of key vulnerabilities identified by CMS in the peripheral management of red team (I)

Community pycharm installation visual database

618大促:手机品牌“神仙打架”,高端市场“谁主沉浮”?

Get to know MySQL database

Simple and beautiful weather code

Ar 3D map technology
![[summary of interview questions] zj6 redis](/img/4b/eadf66ca8d834f049f3546d348fa32.jpg)
[summary of interview questions] zj6 redis

元气森林推“有矿”,农夫山泉们跟着“卷”?
随机推荐
13. Tencent cloud IOT device side learning - data template function and Implementation
Tencent cloud CIF engineering efficiency summit ends perfectly
RI Geng series: tricks of using function pointers
What port does the fortress machine use? What is the role of the fortress machine?
How does cloud computing achieve elastic scaling? What are the characteristics of elasticity?
Case analysis | interpret the truth that multi branch enterprises choose sd-wan network reconstruction in combination with real cases
Understanding Devops from the perspective of decision makers
Tencent Mu Lei: real scene 3D linking industrial Internet and consumer Internet
System library golang Org/x/time/rate frequency limiter bug
Grp: how to add Prometheus monitoring in GRP service?
Tencent cloud launched its new 100g+ cloud server product!! Expect more than 400g+ in the future!
How to select a server with appropriate configuration when planning to build a live broadcast platform
If the cloud knows that security is important
ClickHouse Buffer
web渗透测试----5、暴力破解漏洞--(3)FTP密码破解
MySQL stored procedure + function
Disk partition extension using graphical interface and PowerShell code
Micro build low code enterprise exchange day · Shenzhen station opens registration
Supply chain system platform: two management areas
Grpc: how to add API Prometheus monitoring interceptors / Middleware?