Legacy code rehab

18
Legacy Code : Rehab A Workshop with @johnnonolan Friday, 26 April 13

Transcript of Legacy code rehab

Page 1: Legacy code rehab

Legacy Code : Rehab

A Workshop with @johnnonolan

Friday, 26 April 13

Page 2: Legacy code rehab

• Spent a few years thinking about rewrites.

• Not an expert/guru.

• Written a load of crap.

Me

Friday, 26 April 13

Page 3: Legacy code rehab

What is legacy?• Code without tests?

• Old tech?

• Not the latest thing?

• Not invented here?

Friday, 26 April 13

Page 4: Legacy code rehab

Is legacy so bad?Outside of software, how do we see legacy?

Friday, 26 April 13

Page 5: Legacy code rehab

Theres no getting away with it

Legacy is everywhere

Friday, 26 April 13

Page 6: Legacy code rehab

2 choices

Rebuild or RenovatePhoto by John T Pilot

Friday, 26 April 13

Page 7: Legacy code rehab

• Estimates always wrong.

• New bugs.

• Secret knowledge in the code.

• Lengthy code freeze.

• Organisation needs to wait for new features.

Risks of Re-building

Friday, 26 April 13

Page 8: Legacy code rehab

But Renovating?• The code is a mess.

• You don't know where to start.

• It has become poorly designed.

• It is typically untested.

Friday, 26 April 13

Page 9: Legacy code rehab

Botch it then?• Just hack the change in.

• Code will be worse.

• Which leads to worse code.

Friday, 26 April 13

Page 10: Legacy code rehab

Right let's do it!• Scratch refactor

• Tell the story of the system

• Sketches

• Characterization tests

• Golden Master technique

Friday, 26 April 13

Page 11: Legacy code rehab

Code SampleTrivia Code base

https://github.com/jbrains/trivia

Friday, 26 April 13

Page 12: Legacy code rehab

Scratch refactor• Start playing with the code.

• Throw away the changes.

Friday, 26 April 13

Page 13: Legacy code rehab

Telling the story?• Just the essentials

• Then move on to more granular bits

• Rinse & repeat.

Friday, 26 April 13

Page 14: Legacy code rehab

Sketches• Feature sketches

• Effect Sketches

• Effect analysis

Friday, 26 April 13

Page 15: Legacy code rehab

Characterization tests• Fail

• Pass

• Sensing variables

• Inheritance

• change access modifier

• Throwaway?

Friday, 26 April 13

Page 16: Legacy code rehab

New Feature

Friday, 26 April 13

Page 17: Legacy code rehab

Thanks• This session is all about understanding the impact of

change.

• Small safe steps.

• Vices.

Friday, 26 April 13

Page 18: Legacy code rehab

FeedbackEmail : [email protected]

Twitter: @johnnonolan

Friday, 26 April 13