Legacy code

Ez a fejezet gyakorlatilag teljes egészében Michael Feathers Working Efficiently with Legacy Code c. könyvén alapszik. Itt elérhető egy prezentáció a szerzőtől.

Mi a Legacy Code?

Code without tests is bad code. It doesn’t matter how well written it is; it doesn’t matter how pretty or object-oriented or well-encapsulated it is. With tests, we can change the behavior of our code quickly and verifiably. Without them, we really don’t know if our code is getting better or worse.

-- Feathers, M. (2004). Working Effectively with Legacy Code: Preface

The Legacy Code Dilemma

When we change code, we should have tests in place. To put tests in place, we often have to change code.

-- Feathers, M. (2004). Working Effectively with Legacy Code: Part I / Chapter 2

Code Smells

Changing Software

adding a featurefix a bugrefactoroptimizing
structurechangeschangeschanges
functionalitychanges
new funcionalitychanges
resource usagechanges

-- Feathers, M. (2004). Working Effectively with Legacy Code: WORK EFFECT LEG CODE p1. pp 6. Prentice Hall Professional.

The legacy code algorithm

Sensing & Separation

  1. Sensing — We break dependencies to sense when we can’t access values our code computes.
  2. Separation — We break dependencies to separate when we can’t even get a piece of code into a test harness to run.

-- Feathers, M. (2004). Working Effectively with Legacy Code: Part I / Chapter 3

Mocking

Seams

A seam is a place where you can alter behavior in your program without editing in that place.

-- Feathers, M. (2004). Working Effectively with Legacy Code: Part I / Chapter 4

SOLID