Refactoring Legacy Code STEP BY STEP (Part 3)

Опубликовано: 10 Октябрь 2024
на канале: Continuous Delivery
9,534
348

TDD is great, but where do you start if you already have legacy code that wasn't built with software testing in mind? How do you change legacy-code to make it testable? In the 3rd episode, in a three part mini-series, Dave Farley's tutorial demonstrates how to refactor some nasty, legacy code to the point where it is testable. Dave discovers real, pre-existing bugs in the code by virtue of the software tests that he introduces.

When Kent Beck wrote about TDD he introduced a profoundly valuable engineering practice to software development. In his book “ Working Effectively with Legacy Code” Michael Feathers defines a legacy system as “a system without automated tests”. So how can we take advantage of the benefits of TDD when our code is the wrong shape, when it was developed without automated tests?

In this episode Dave demonstrates the value of the work done earlier. Now we get to see the concrete value of the work of setting up the Approval Test, Removing Clutter, Reducing Cyclomatic Complexity and Composing Methods. In this final episode in his refactoring mini-series, Dave takes this nasty code the final step to testability and discovers some unexpected things.

If you would like to try this for yourself, you can find the bad code, a simple Approval Test, and a sample XML file to support the test here: https://github.com/davef77/Refactorin...

---------------------------------------------------------------------------------------

If you want to learn Continuous Delivery and DevOps skills, check out Dave Farley's courses:
➡️ https://bit.ly/DFTraining

📚 BOOKS:

📖 Dave’s NEW BOOK "Modern Software Engineering" is now available on
Amazon ➡️ https://amzn.to/3DwdwT3
In this book, Dave brings together his ideas and proven techniques to describe a durable, coherent and foundational approach to effective software development, for programmers, managers and technical leads, at all levels of experience.

📖 "Continuous Delivery Pipelines" by Dave Farley
paperback ➡️ https://amzn.to/3gIULlA
ebook version ➡️ https://leanpub.com/cd-pipelines

📖 The original award-winning “Continuous Delivery" book by Dave Farley and Jez Humble
➡️ https://amzn.to/2WxRYmx

--------------------------------------------------------------------------------------

Keep up to date with the latest discussions, free "How To..." guides, events and online courses and get Dave Farley's FREE "How To..." guide on Acceptance Testing here
➡️ https://www.subscribepage.com/cd-atdd...

-------------------------------------------------------------------------

Continuous Delivery Ltd. ➡️ https://bit.ly/ContinuousDeliveryDF

Dave Farley's Blog ➡️ https://bit.ly/DaveFWebBlog

Dave Farley on Twitter ➡️ https://bit.ly/DaveFTwitter

Dave Farley on LinkedIn ➡️ https://bit.ly/DaveF-LI

-------------------------------------------------------------------------
Other Useful Books on this topic:
(Please note, if you buy a book from these links I get a small fee, without increasing the cost to you)

Test Driven Development: By Example (The Addison-Wesley Signature Series), Kent Beck ➡️ https://amzn.to/2NcqgGh

Working Effectively with Legacy Code, Michael Feathers ➡️ https://amzn.to/3hP0F4z