Misadventures In Legacy Code
44K - views

Misadventures In Legacy Code

Eric Lee. Who am I?. Not a professional presenter – be patient!. 16 years at Microsoft. 6 years in Office building automated testing systems. 9 years in Microsoft Game Studios making games testable.

Download Presentation

Misadventures In Legacy Code




Download Presentation - The PPT/PDF document "Misadventures In Legacy Code" is the property of its rightful owner. Permission is granted to download and print the materials on this web site for personal, non-commercial use only, and to display it on your personal computer provided you do not modify the materials and that you retain all copyright notices contained in the materials. By downloading content from our website, you accept the terms of this agreement.



Presentation on theme: "Misadventures In Legacy Code"— Presentation transcript:

Slide1

Misadventures In Legacy Code

Eric Lee

Slide2

Who am I?

Not a professional presenter – be patient!

16 years at Microsoft

6 years in Office building automated testing systems

9 years in Microsoft Game Studios making games testable

1 year in Engineering Excellence building a secure source code portal

Enthusiastic Agile practitioner

I’ve inherited at least three “legacy” systems during my career

Slide3

The plan

Part 1: What is a legacy system?

Part 2: How do I survive a legacy system?

Part 3: How do I avoid creating more legacy systems?

Slide4

Part 1: What is a legacy system?

Slide5

What does legacy mean?

Slide6

What the dictionary says…

leg·a·cy

[

léggəssee

]

noun  (

plural

leg·a·cies

)

Definition:

1. 

bequest made in will: 

money or property that is left to somebody in a will

2. 

something from past: 

something that is handed down or remains from a previous generation or time

Encarta® World English Dictionary

Slide7

What developers really mean…

Bob

Jagendorf

Slide8

Zombies vs. Legacy apps

Zombies:

Legacy apps:

Walking undead corpsesExtremely hideous and disgustingOverwhelm you with numbersInfect anything they touchConsume your brain and destroy your willVery hard to eradicateCampy fiction

Walking undead corpses

Extremely hideous and disgusting

Overwhelm you with numbers

Infect anything they touch

Consume your brain and destroy your will

Very hard to eradicate

Horrifyingly real

Slide9

Stuart Halloway says…

“Legacy” is the degree to which code:

fails to capture essence

fails to communicate essence

captures irrelevant detail (ceremony)

Slide10

Michael Feathers says…

“Legacy code is code without tests.”

Slide11

Practical Considerations

Legacy apps are often (but not always) old

Sometimes no original developers remain

Extremely difficult to make changes without breaking things

Critical infrastructure has often been lost

Source code is archaic, bewildering, and way too complex for what it does

Documentation is nonexistent or wrong

No automated test suite

Slide12

Part 2: How do I survive a legacy system?

Slide13

"I say we take off and nuke the entire site from orbit. It's the only way to be sure."

Slide14

Should we start over?

Sure, if you have unlimited resources

Otherwise, probably not!

The legacy code base holds valuable, hard-won knowledge

Legacy code base continues to accumulate new features and bug fixes

Feature parity is a moving target

Users want to see regular evidence of progress

Slide15

Then what do we do?

First, take a deep breath - this is

gonna

hurt

Take inventory

Eliminate friction

Build a safety net

Divide and conquer

Practice software archeology

Build for the future

Have boat-loads of patience

Slide16

Take inventory

Understand the environment:

History of the project

Problem space

Stakeholders

Target audience

Future goals

Capture initial code metrics

Inspect and prune all documentation

Slide17

Eliminate friction

FRICTION

Slide18

Eliminate friction

Make lists of annoyances

After three months problems become invisible

Always ask the five whys

Get

everything

under source control

Enable local builds, local execution

Repeatable build process

Build scripts

Dedicated build machine for official builds

Repeatable deployment

Slide19

Build a safety net

You need tests!

Automated if you can, manual if you can’t

Let you change the code with less terror

Baby steps

Start with integration tests

Don’t try to write unit tests for everything all at once

Michael Feathers,

Working Effectively With Legacy Code

Slide20

Divide and conquer

Don’t start with sweeping architectural changes

Focus on one small area at a time

Refactor

/rewrite as you go

Build firewalls to protect new code from old code

Practice the Boy Scout rule

Have patience and a long-term plan

Slide21

Software archeology

Slide22

Software archeology

Legacy code is like an archeological dig site

Layer upon layer of history

Lots of rubble from previous times

Before changing code, try to understand:

The historical purpose of the code

The desired purpose of the code today

Be suspicious and paranoid

Any mysterious behavior will bite you later

Always look for root causes

Slide23

Break the cycle

Clear away the rubble

Source code is a liability, not an asset

Delete dead code

Delete redundant comments

Simplify, simplify, simplify!

I reduced one component from 4000 to 400 ELOC, another from 6800 to 3200

Write unit tests for all new code

Slide24

Break the cycle

Focus on

today’s

requirements, not ancient history

Rethink all assumptions

Bad code is often a symptom of squishy problem definition

Get really crisp on the fundamental concepts

Slide25

Forensic development

The code lies, don’t trust it

Dig until you understand the whole story

Collect evidence and build a case

Refactor

the code until it tells the truth

Slide26

How do I avoid creating more legacy systems?

Slide27

Do the right thing!

Always code as if the person who ends up maintaining your code is a violent psychopath who knows where you live.

Slide28

The right code

Write unit and integration tests for all code

Follow S.O.L.I.D design principles

Be a naming Nazi

Refactor constantly to match current goals

Avoid “minimally invasive” fixes

Write self-explanatory code, skip heavy docs

Slide29

The right process

Promote shared ownership

Create and maintain long-term vision

Stay focused on business value

Automate everything

Stamp out friction

Limit technical debt

Slide30

Questions and followup

Any questions?

Contact me!

Email: saintgimp@hotmail.com

Twitter: @

saintgimp

Blog: http://blogs.msdn.com/elee

Slide31

Slide32

Slide33

Slide34

Slide35

Slide36