[xpday.vn] legacy code workshop (at) [xp day vietnam 2015]

35
www.odd-e.com Fight Legacy Code Write Unit Test Stanly Lau

Upload: agile-day-vietnam

Post on 22-Aug-2015

62 views

Category:

Software


2 download

TRANSCRIPT

www.odd-e.com

Fight Legacy Code!Write Unit Test!

Stanly Lau

2

I’m Stanly

• Lives in Singapore!• Agile coach, SW developer!• Worked in small to large

companies!• Experienced in Insurance, Mobile

Safety, Education, Logistics and Banking!

• Java, .Net, JavaScript, Objective-C

[email protected]

5

What is Legacy Code?!!

The Problem!!

How to deal with it?

6

What is legacy code?

7

Legacy Code is!Code without Unit Test

8

Michael Feathers

9

It is not a unit test when: • It talks to the database!• It communicates across the network!• It touches the file system!• It can't run at the same time

as any of your other unit tests!• You have to do special things to your

environment (such as editing config files) to run it.

Michael Feathers

The problem

10

13

Inheritance nightmare

14

Code tends to grow

15

amount of bad

code

panic

amount of code

smells

time spend on

bug fixing

motivation

developers

quick hacks

opportunity for

# of bugs

indicates

O

refactoring

O

16

Existing Behaviour New

This is where we spent most time on,!preserving behaviour!

Codebase

17

Productive

Working duration in a day

Does your day looks like this?

18

Productive =(

Don’t know why the ‘if’ doesn’t work

19

Productive =(

Stuck on understanding what the

code is doing

20

Productive =(

Stuck on thinking of a general solution to solve multiple

problems

21

Productive =(

Realised you misunderstood the requirements

22

Productive =(

Fixing production bug

23

Features Estimates

Business Developers

Competitive dynamic

Limits everyone’s perspectives

24

James Grenning

“Software change is part of being a developer, so you better get used to it. !Even more, you better get good at it!”

How to deal with it?

25

26

Modern engineering practices

26

Test-Driven Development

Refactoring

Continuous Integration

Emergent Design

27

Test-driven development • Increments of functionality!• Always in working state

Code and fix • Large functionalities!• Long time to get to a working statef

t

The Legacy Code Dilemma

30

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

But I don't understand the code well enough to change It =(

31

Scratch RefactoringNotes/Sketching

Delete Unused Code

Legacy code algorithm

32

1. Identify change point!2. Find test points!3. Break dependencies!4. Write tests!5. Make changes and refactor

Exercise:!Dependency Breaking!Characterisation Tests!

!

http://bit.ly/FightLegacyCode

33

Are we going faster?

34

Feels faster

Feels slower

35

Kent Beck

“I'm not a great programmer;!I'm just a good programmer with great habits”

Closing

36

Books - Technical Practices

37

38

@avernois

[email protected] !

@stanlylau

39