Skip to main content

Working Effectively with Legacy Codes - notes

 Robert C. Martin Series

This series is directed at software developers, team-leaders,

business analysts, and managers who want to increase their

skills and proficiency to the level of a Master Craftsman.

The series contains books that guide software professionals

in the principles, patterns, and practices of programming,

software project management, requirements gathering,

design, analysis, testing, and others.


https://stackoverflow.com/questions/748503/how-do-you-introduce-unit-testing-into-a-large-legacy-c-c-codebase

https://docs.microsoft.com/en-us/archive/msdn-magazine/2009/december/generation-test-automated-unit-tests-for-legacy-code-with-pex

https://www.weeklydevtips.com/episodes/015

https://dzone.com/articles/introduction-test-driven

But using Test-Driven Development for legacy code is a little different from using TDD in a green-fields context. The general approach is identical:

  1. Write a test to reproduce the error (test bar red)
  2. Write code to fix the error (test bar green)
  3. and then refactor (test bar still green)

However, when working with legacy code, you might need to do some refactoring upfront to make the code testable in the first place. In legacy code, it can be hard to write a unit test to reproduce a bug or to understand how a particular piece of code works, because it often contains embedded dependencies on other components which are hard (or impossible) to initialize in a unit testing context. Without breaking these dependencies, you have little option but to work with full integration tests. However, if you succeed in isolating the code you need to test from the surrounding components, there is no reason why you can't write effective unit tests to isolate, reproduce and fix bugs in legacy code.

In fact, Test-Driven Development (along with other related techniques such as Behaviour-Driven Development and Acceptance Test-Driven Development) is a valuable tool for working with legacy code. Test-Driven Development is not just an Agile practice; it is actually just common sense. Would you fly in an airplane where the pilot only ran through the pre-flight check list from time to time, or not at all, and fixed any issues that came up in the air? No, not really. Automated unit tests are like the checklist in a plane - they let you spot problems quickly, automatically, and with little effort on your part. Using Test-Driven Development with existing code is like finding and fixing issues using a pilot's checklist, rather then climbing onto the wing inflight and tightening a bolt or two.

Comments

Popular posts from this blog

Rand mm 10

https://stackoverflow.com/questions/2447791/define-vs-const Oh const vs define, many time I got unexpected interview question. As this one, I do not know much or try to study this. My work flow, and I believe of many programmer is that search topic only when we have task or job to tackle. We ignore many 'basic', 'fundamental' documents, RTFM is boring. So I think it is a trade off between the two way of study language. And I think there are a bridge or balanced way to extract both advantage of two method. There are some huge issue with programmer like me that prevent we master some technique that take only little time if doing properly. For example, some Red Hat certificate program, lesson, course that I have learned during Collage gave our exceptional useful when it cover almost all topic while working with Linux. I remember it called something like RHEL (RedHat Enterprise Linux) Certificate... I think there are many tons of documents, guide n books about Linux bu

Martin Fowler - Software Architecture - Making Architecture matter

  https://martinfowler.com/architecture/ One can appreciate the point of this presentation when one's sense of code smell is trained, functional and utilized. Those controlling the budget as well as developer leads should understand the design stamina hypothesis, so that the appropriate focus and priority is given to internal quality - otherwise pay a high price soon. Andrew Farrell 8 months ago I love that he was able to give an important lesson on the “How?” of software architecture at the very end: delegate decisions to those with the time to focus on them. Very nice and straight-forward talk about the value of software architecture For me, architecture is the distribution of complexity in a system. And also, how subsystems communicate with each other. A battle between craftmanship and the economics and economics always win... https://hackernoon.com/applying-clean-architecture-on-web-application-with-modular-pattern-7b11f1b89011 1. Independent of Frameworks 2. Testable 3. Indepe