Add daily email for 2024-09-01
You need tests to refactor safely
This commit is contained in:
parent
d6d09ab172
commit
6ca5704c21
31
source/_daily_emails/2024-09-01.md
Normal file
31
source/_daily_emails/2024-09-01.md
Normal file
|
@ -0,0 +1,31 @@
|
|||
---
|
||||
title: You need tests to refactor safely
|
||||
date: 2024-09-01
|
||||
permalink: daily/2024/09/01/you-need-tests-to-refactor-safely
|
||||
tags:
|
||||
- software-development
|
||||
- refactoring
|
||||
- automated-testing
|
||||
- test-driven-development
|
||||
cta: call
|
||||
snippet: |
|
||||
When refactoring, you should have automated tests to ensure it's done safely.
|
||||
---
|
||||
|
||||
[Once you have working code][0], you can refactor it to make it better.
|
||||
|
||||
You can rename variables, extract new functions or classes, ensure the code is styled and formatted correctly - anything to make the code easier to read, understand or maintain.
|
||||
|
||||
But, the key thing is the code still needs to work.
|
||||
|
||||
You don't want to break working code and introduce a regression, even if it is messy or difficult to read.
|
||||
|
||||
The best way I know to approach this is by having automated tests covering this code, and ensure they are working and passing before starting to refactor.
|
||||
|
||||
Then you can run the tests again and ensure they still pass.
|
||||
|
||||
If they pass, the code still works and the refactoring was successful.
|
||||
|
||||
If not, the code is broken and you need to revert the changes and start again.
|
||||
|
||||
[0]: {{site.url}}/daily/2024/08/31/make-it-work-then-make-it-good
|
Loading…
Reference in a new issue