Working Effectively With Legacy Code — Changing Software (Part 1: Chapter 2)

Part 1 : Mechanics of Change:

Chapter 2: Working with Feedback

The Legacy Code DilemmaWhen we have to change code, we should have tests in place. To put tests in place, we often have to change code.
pic source
  • Edit and Pray.
  • Cover and modify.
Software Vise: 
"When we have tests that detect change, it is like having a vise around our code. The behavior of the code is fixed in place. When we make changes, we can know that we are changing only one piece of behavior at a time".
  • Unit Tests.
  • Integration Tests.
  • Functional Tests.
  • End-to-end tests.
  • Acceptance testing.
  • Performance testing.
  • Smoke testing.

“Unit testing is very important in Legacy Code Work”.

What is Unit Testing?

A unit test that takes 1/10th of a second to run is a slow unit test.
  • to localized the error.
  • execute test in shorter time period.
  • find the coverage of the test.
Unit tests run fast. If they don’t run fast, they aren’t unit tests.
  • Talk to database.
  • Communicate across a network.
  • Touch the file system.
  • No special configuration setup to run the test.
Dependency is one of the most critical problems in software development. Much legacy code work involves breaking dependencies so that change can be easier.
  • Identify change points: Find places where you need to make changes.
  • Find test points: Find places where tests can be written.
  • Break dependencies: Dependencies are the most obvious impediment to testing.
  • Write tests: Writing test for legacy code is different than writing for new code.
  • Make changes and refactor: We can use TDD(Test Driven Development) to work in legacy code.
When you break dependencies in legacy code, you often have to make some ugly changes. Some dependencies break cleanly; others end up ugly. If we can cover code around the point we broke the 
dependencies, we can clean the ugliness later.



MyView androidView;

Love podcasts or audiobooks? Learn on the go with our new app.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store