![Page 2: learning to live with it - ACCU :: ACCU (Pete...2009/03/09 · This presentation will look at practical strategies for working with “old” crufty code. We'll see how to:! start](https://reader036.vdocument.in/reader036/viewer/2022070802/5f02c0757e708231d405d573/html5/thumbnails/2.jpg)
legacy code learning to live with it pete goodliffe
Pete GoodliffeA programmer, a columnist, an author, a teacher. Someone who cares about code. Books: Code Craft, Beautiful Architecture.
www.goodliffe.netgoodliffe.blogspot.com
Pete [email protected]
2
![Page 3: learning to live with it - ACCU :: ACCU (Pete...2009/03/09 · This presentation will look at practical strategies for working with “old” crufty code. We'll see how to:! start](https://reader036.vdocument.in/reader036/viewer/2022070802/5f02c0757e708231d405d573/html5/thumbnails/3.jpg)
legacy code learning to live with it pete goodliffe
Adam
Eve
3
![Page 4: learning to live with it - ACCU :: ACCU (Pete...2009/03/09 · This presentation will look at practical strategies for working with “old” crufty code. We'll see how to:! start](https://reader036.vdocument.in/reader036/viewer/2022070802/5f02c0757e708231d405d573/html5/thumbnails/4.jpg)
legacy code learning to live with it pete goodliffe
most software is
4
![Page 5: learning to live with it - ACCU :: ACCU (Pete...2009/03/09 · This presentation will look at practical strategies for working with “old” crufty code. We'll see how to:! start](https://reader036.vdocument.in/reader036/viewer/2022070802/5f02c0757e708231d405d573/html5/thumbnails/5.jpg)
most software is
5
![Page 6: learning to live with it - ACCU :: ACCU (Pete...2009/03/09 · This presentation will look at practical strategies for working with “old” crufty code. We'll see how to:! start](https://reader036.vdocument.in/reader036/viewer/2022070802/5f02c0757e708231d405d573/html5/thumbnails/6.jpg)
6
![Page 7: learning to live with it - ACCU :: ACCU (Pete...2009/03/09 · This presentation will look at practical strategies for working with “old” crufty code. We'll see how to:! start](https://reader036.vdocument.in/reader036/viewer/2022070802/5f02c0757e708231d405d573/html5/thumbnails/7.jpg)
Legacy code. You can't live with it. You can't live without it.
Well, you can't avoid it, at least. Spend long enough in the software factory,and you'll inevitably run into other people's old code. And of course, noneof this old stuff is any good. It's nothing like the high quality softwareyou craft. Pure tripe.
Let's be honest, sometimes you might even stumble across some of your ownold code, and embarrassing as it is, you have to admit that you don't knowhow it works, let alone how to fix it.
This presentation will look at practical strategies for working with “old”crufty code. We'll see how to:
! start working with a completely unfamiliar codebase
! understand old spaghetti programming
! make correct modifications
! prevent bad code from causing more pain in the future
legacy code learning to live with it pete goodliffe
talk synopsis
7
![Page 8: learning to live with it - ACCU :: ACCU (Pete...2009/03/09 · This presentation will look at practical strategies for working with “old” crufty code. We'll see how to:! start](https://reader036.vdocument.in/reader036/viewer/2022070802/5f02c0757e708231d405d573/html5/thumbnails/8.jpg)
plan of attack! what is legacy code! how to understand it! how to modify it
legacy code learning to live with it pete goodliffe
8
![Page 9: learning to live with it - ACCU :: ACCU (Pete...2009/03/09 · This presentation will look at practical strategies for working with “old” crufty code. We'll see how to:! start](https://reader036.vdocument.in/reader036/viewer/2022070802/5f02c0757e708231d405d573/html5/thumbnails/9.jpg)
plan of attack! what is legacy code! how to understand it! how to modify it
legacy code learning to live with it pete goodliffe
9
![Page 10: learning to live with it - ACCU :: ACCU (Pete...2009/03/09 · This presentation will look at practical strategies for working with “old” crufty code. We'll see how to:! start](https://reader036.vdocument.in/reader036/viewer/2022070802/5f02c0757e708231d405d573/html5/thumbnails/10.jpg)
legacy (noun)
1. Law. a gift of property, esp. personal property, as money, by will; a bequest.2. anything handed down from the past, as from an ancestor or predecessor: the legacy of ancient Rome. ?
10
![Page 11: learning to live with it - ACCU :: ACCU (Pete...2009/03/09 · This presentation will look at practical strategies for working with “old” crufty code. We'll see how to:! start](https://reader036.vdocument.in/reader036/viewer/2022070802/5f02c0757e708231d405d573/html5/thumbnails/11.jpg)
wha
t is leg
ac
y co
de
?
Old code
Any existing code
Out-of-d
ate code
Code you didn’t write
No longer supported by supplier
From a previous product version
Code without tests
Uses old technology
“Bad” code ?11
![Page 12: learning to live with it - ACCU :: ACCU (Pete...2009/03/09 · This presentation will look at practical strategies for working with “old” crufty code. We'll see how to:! start](https://reader036.vdocument.in/reader036/viewer/2022070802/5f02c0757e708231d405d573/html5/thumbnails/12.jpg)
There is a lot of legacy code being written
right now ?12
![Page 13: learning to live with it - ACCU :: ACCU (Pete...2009/03/09 · This presentation will look at practical strategies for working with “old” crufty code. We'll see how to:! start](https://reader036.vdocument.in/reader036/viewer/2022070802/5f02c0757e708231d405d573/html5/thumbnails/13.jpg)
?why do we care?
! Requirements change
Old code needs to be extended
! Bugs are discovered
Old code needs to be fixed
! Technology changes
Old code needs to be ported
13
![Page 14: learning to live with it - ACCU :: ACCU (Pete...2009/03/09 · This presentation will look at practical strategies for working with “old” crufty code. We'll see how to:! start](https://reader036.vdocument.in/reader036/viewer/2022070802/5f02c0757e708231d405d573/html5/thumbnails/14.jpg)
is it actually bad?not necessarily *
* terms and conditions apply14
![Page 15: learning to live with it - ACCU :: ACCU (Pete...2009/03/09 · This presentation will look at practical strategies for working with “old” crufty code. We'll see how to:! start](https://reader036.vdocument.in/reader036/viewer/2022070802/5f02c0757e708231d405d573/html5/thumbnails/15.jpg)
who works with it?muggins here
skills >>
(good luck with that)
15
![Page 16: learning to live with it - ACCU :: ACCU (Pete...2009/03/09 · This presentation will look at practical strategies for working with “old” crufty code. We'll see how to:! start](https://reader036.vdocument.in/reader036/viewer/2022070802/5f02c0757e708231d405d573/html5/thumbnails/16.jpg)
helpful traits! bravery
16
![Page 17: learning to live with it - ACCU :: ACCU (Pete...2009/03/09 · This presentation will look at practical strategies for working with “old” crufty code. We'll see how to:! start](https://reader036.vdocument.in/reader036/viewer/2022070802/5f02c0757e708231d405d573/html5/thumbnails/17.jpg)
helpful traits! bravery! memory
17
![Page 18: learning to live with it - ACCU :: ACCU (Pete...2009/03/09 · This presentation will look at practical strategies for working with “old” crufty code. We'll see how to:! start](https://reader036.vdocument.in/reader036/viewer/2022070802/5f02c0757e708231d405d573/html5/thumbnails/18.jpg)
helpful traits! bravery! memory! methodicalness(osity)
18
![Page 19: learning to live with it - ACCU :: ACCU (Pete...2009/03/09 · This presentation will look at practical strategies for working with “old” crufty code. We'll see how to:! start](https://reader036.vdocument.in/reader036/viewer/2022070802/5f02c0757e708231d405d573/html5/thumbnails/19.jpg)
helpful traits! bravery! memory! methodicalness(osity)! imagination
19
![Page 20: learning to live with it - ACCU :: ACCU (Pete...2009/03/09 · This presentation will look at practical strategies for working with “old” crufty code. We'll see how to:! start](https://reader036.vdocument.in/reader036/viewer/2022070802/5f02c0757e708231d405d573/html5/thumbnails/20.jpg)
helpful traits! bravery! memory! methodicalness(osity)! imagination
20
![Page 21: learning to live with it - ACCU :: ACCU (Pete...2009/03/09 · This presentation will look at practical strategies for working with “old” crufty code. We'll see how to:! start](https://reader036.vdocument.in/reader036/viewer/2022070802/5f02c0757e708231d405d573/html5/thumbnails/21.jpg)
helpful traits! bravery! memory! methodicalness(osity)! imagination! patience! intelligence! empathy! experience! persistence! curiosity! application! dedication
21
![Page 22: learning to live with it - ACCU :: ACCU (Pete...2009/03/09 · This presentation will look at practical strategies for working with “old” crufty code. We'll see how to:! start](https://reader036.vdocument.in/reader036/viewer/2022070802/5f02c0757e708231d405d573/html5/thumbnails/22.jpg)
plan of attack! what is legacy code! how to understand it! how to modify it
legacy code learning to live with it pete goodliffe
22
![Page 23: learning to live with it - ACCU :: ACCU (Pete...2009/03/09 · This presentation will look at practical strategies for working with “old” crufty code. We'll see how to:! start](https://reader036.vdocument.in/reader036/viewer/2022070802/5f02c0757e708231d405d573/html5/thumbnails/23.jpg)
<< understanding
modifying >>
23
![Page 24: learning to live with it - ACCU :: ACCU (Pete...2009/03/09 · This presentation will look at practical strategies for working with “old” crufty code. We'll see how to:! start](https://reader036.vdocument.in/reader036/viewer/2022070802/5f02c0757e708231d405d573/html5/thumbnails/24.jpg)
Everything that irritates us about others can lead us to a better understanding of
ourselves.
Carl Jung (1875 - 1961)
24
![Page 25: learning to live with it - ACCU :: ACCU (Pete...2009/03/09 · This presentation will look at practical strategies for working with “old” crufty code. We'll see how to:! start](https://reader036.vdocument.in/reader036/viewer/2022070802/5f02c0757e708231d405d573/html5/thumbnails/25.jpg)
you have to understand
! the software you are changing
! the changes you must make
! the code you are changing
! how to approach the code
25
![Page 26: learning to live with it - ACCU :: ACCU (Pete...2009/03/09 · This presentation will look at practical strategies for working with “old” crufty code. We'll see how to:! start](https://reader036.vdocument.in/reader036/viewer/2022070802/5f02c0757e708231d405d573/html5/thumbnails/26.jpg)
(software)understand: the software
! what type of software is it?! e.g. shrinkwrap, server, bespoke
! what does it do?
! what does it do? really?
! have you used it?
! how is it tested?! what QA is there?
! is there documentation?
! are there manuals?
! gauge the quality (e.g. bug count, reliability)
26
![Page 27: learning to live with it - ACCU :: ACCU (Pete...2009/03/09 · This presentation will look at practical strategies for working with “old” crufty code. We'll see how to:! start](https://reader036.vdocument.in/reader036/viewer/2022070802/5f02c0757e708231d405d573/html5/thumbnails/27.jpg)
(people)understand: the software
! who has domain expertise?! do you need domain expertise?
! who wrote it?
! who owns it?
! what’s the license?
! who are the users?! are they technical?
! have they been involved in development?
27
![Page 28: learning to live with it - ACCU :: ACCU (Pete...2009/03/09 · This presentation will look at practical strategies for working with “old” crufty code. We'll see how to:! start](https://reader036.vdocument.in/reader036/viewer/2022070802/5f02c0757e708231d405d573/html5/thumbnails/28.jpg)
(claptrap)understand: the software
! what platform(s) does it run on?
! how is it deployed?
! what dev processes is it encumbered by?
28
![Page 29: learning to live with it - ACCU :: ACCU (Pete...2009/03/09 · This presentation will look at practical strategies for working with “old” crufty code. We'll see how to:! start](https://reader036.vdocument.in/reader036/viewer/2022070802/5f02c0757e708231d405d573/html5/thumbnails/29.jpg)
(changes)understand: the software
! where is it stored?
! change control
! where is the repository (what system)
! trunk/branching strategy! feature/release/personal branching
! who can commit, when! who else is working on the same branch as you?
! can you break build?
29
![Page 30: learning to live with it - ACCU :: ACCU (Pete...2009/03/09 · This presentation will look at practical strategies for working with “old” crufty code. We'll see how to:! start](https://reader036.vdocument.in/reader036/viewer/2022070802/5f02c0757e708231d405d573/html5/thumbnails/30.jpg)
(malarkey)understand: the software
! other procedural tools
! bug tracker?! bug management process?
! who manages?
! who hands out bugs?
! who gives you an account?
! continuous integration
! testing process! how thorough?
! is it automated?
30
![Page 31: learning to live with it - ACCU :: ACCU (Pete...2009/03/09 · This presentation will look at practical strategies for working with “old” crufty code. We'll see how to:! start](https://reader036.vdocument.in/reader036/viewer/2022070802/5f02c0757e708231d405d573/html5/thumbnails/31.jpg)
(attitude)understand: your approach
the right attitude
Weakness of attitude becomes weakness of character.Albert Einstein
! don’t freak out!
! someone once understood it
! conquer disgust
! you can improve it
31
![Page 32: learning to live with it - ACCU :: ACCU (Pete...2009/03/09 · This presentation will look at practical strategies for working with “old” crufty code. We'll see how to:! start](https://reader036.vdocument.in/reader036/viewer/2022070802/5f02c0757e708231d405d573/html5/thumbnails/32.jpg)
(strategise)understand: your approach
strategise
become effective by being selective
! how much time do you have to work with it?
! affects how you work a route through it
! how long will you be working with it for?
! how much of it do you need to know?
32
![Page 33: learning to live with it - ACCU :: ACCU (Pete...2009/03/09 · This presentation will look at practical strategies for working with “old” crufty code. We'll see how to:! start](https://reader036.vdocument.in/reader036/viewer/2022070802/5f02c0757e708231d405d573/html5/thumbnails/33.jpg)
understand: the changes
(mission)what do you have to do?
Do not, for one repulse, forego the purpose that you resolved to effect.
William Shakespeare, ‘The Tempest’
! what was the old behaviour?
! what will the new behaviour be?
! how will you know you are done?
33
![Page 34: learning to live with it - ACCU :: ACCU (Pete...2009/03/09 · This presentation will look at practical strategies for working with “old” crufty code. We'll see how to:! start](https://reader036.vdocument.in/reader036/viewer/2022070802/5f02c0757e708231d405d573/html5/thumbnails/34.jpg)
understand: the changes
(mission)what do you have to do?
! is it a single coding task?
! or ongoing work in the system?! drive-by programming?!
! will you take responsibility for whole section of code?
! are you on a schedule?! do you agree with work packages?
34
![Page 35: learning to live with it - ACCU :: ACCU (Pete...2009/03/09 · This presentation will look at practical strategies for working with “old” crufty code. We'll see how to:! start](https://reader036.vdocument.in/reader036/viewer/2022070802/5f02c0757e708231d405d573/html5/thumbnails/35.jpg)
understand: the code
(the code)this is the real task: mapping the software
! the usual approach: guesswork
! a better approach: structured investigation
35
![Page 36: learning to live with it - ACCU :: ACCU (Pete...2009/03/09 · This presentation will look at practical strategies for working with “old” crufty code. We'll see how to:! start](https://reader036.vdocument.in/reader036/viewer/2022070802/5f02c0757e708231d405d573/html5/thumbnails/36.jpg)
understand: the code
this is the real task: mapping the software
! the usual approach: guesswork
! a better approach: structured investigation
36
![Page 37: learning to live with it - ACCU :: ACCU (Pete...2009/03/09 · This presentation will look at practical strategies for working with “old” crufty code. We'll see how to:! start](https://reader036.vdocument.in/reader036/viewer/2022070802/5f02c0757e708231d405d573/html5/thumbnails/37.jpg)
(the map)understand: the code
#1: the basic facts
! the language(s)! and the language version (e.g. C# 2.0, C89, Python 2.0)
! the size! LOC, classes, files, age (does this seem in keeping with project?)
! the build technology! check every build variant
! how its deployed
! main technologies! libraries
! database(s)?
! design tools
! validation/QA tools
! external dependencies
37
![Page 38: learning to live with it - ACCU :: ACCU (Pete...2009/03/09 · This presentation will look at practical strategies for working with “old” crufty code. We'll see how to:! start](https://reader036.vdocument.in/reader036/viewer/2022070802/5f02c0757e708231d405d573/html5/thumbnails/38.jpg)
(the map)understand: the code
build it. now.! don’t go any further until you’ve got it cleanly built and running
! only then can you modify anything sanely
38
![Page 39: learning to live with it - ACCU :: ACCU (Pete...2009/03/09 · This presentation will look at practical strategies for working with “old” crufty code. We'll see how to:! start](https://reader036.vdocument.in/reader036/viewer/2022070802/5f02c0757e708231d405d573/html5/thumbnails/39.jpg)
(the map)understand: the code
find your route in
! is the code structure! data-centric
! control-centric
! does the system decompose into parts?! for separate build
! for separate use
! which bits do you need to look at now?
! can you ask someone?
39
![Page 40: learning to live with it - ACCU :: ACCU (Pete...2009/03/09 · This presentation will look at practical strategies for working with “old” crufty code. We'll see how to:! start](https://reader036.vdocument.in/reader036/viewer/2022070802/5f02c0757e708231d405d573/html5/thumbnails/40.jpg)
(the map)understand: the code
find your route in
gauge the quality >>as you find a route
40
![Page 41: learning to live with it - ACCU :: ACCU (Pete...2009/03/09 · This presentation will look at practical strategies for working with “old” crufty code. We'll see how to:! start](https://reader036.vdocument.in/reader036/viewer/2022070802/5f02c0757e708231d405d573/html5/thumbnails/41.jpg)
mapping by guesswork
! the fir
st resort
! what do you think it s
hould look like?
! what subsectio
ns do you expect to fin
d?
! build a mental m
odel: your map
operating system
databaseav libs
business logic
user interface
41
![Page 42: learning to live with it - ACCU :: ACCU (Pete...2009/03/09 · This presentation will look at practical strategies for working with “old” crufty code. We'll see how to:! start](https://reader036.vdocument.in/reader036/viewer/2022070802/5f02c0757e708231d405d573/html5/thumbnails/42.jpg)
mapping by interface
! identify
interface points
! the places in system where subsystems interface
! the nature of th
e interfaces
! technology, style, quality
, breadth
! high-level / low-level
! refin
e your map
operating system
databaseav libs
user interface & business logic
mp3
operating system
database
ui/bl goo
aac wav
media access db veneer
42
![Page 43: learning to live with it - ACCU :: ACCU (Pete...2009/03/09 · This presentation will look at practical strategies for working with “old” crufty code. We'll see how to:! start](https://reader036.vdocument.in/reader036/viewer/2022070802/5f02c0757e708231d405d573/html5/thumbnails/43.jpg)
mapping by file structure
! can give a valuable insight
! eith
er shows internal structure of project
! or lack of in
ternal structure of project
! clues for quality
of project
!the process:
1. find the code
2. plot the directory structure
3. QED
! does it m
atch project structure?
! recognise common structures
! GNU project shape
! IDEs
43
![Page 44: learning to live with it - ACCU :: ACCU (Pete...2009/03/09 · This presentation will look at practical strategies for working with “old” crufty code. We'll see how to:! start](https://reader036.vdocument.in/reader036/viewer/2022070802/5f02c0757e708231d405d573/html5/thumbnails/44.jpg)
mapping by section
! determine how “sectio
ns” separate
! do they separate?
! high level
! programs
! threads
! libraries
! projects
! low level
! namespaces
! packages
! naming conventio
ns
! comment m
arkup
! sometim
es this isn’t obvious until
you’ve worked with the project
async audio async audio
sync audio(real time)
dbdb
ui
44
![Page 45: learning to live with it - ACCU :: ACCU (Pete...2009/03/09 · This presentation will look at practical strategies for working with “old” crufty code. We'll see how to:! start](https://reader036.vdocument.in/reader036/viewer/2022070802/5f02c0757e708231d405d573/html5/thumbnails/45.jpg)
mapping by dependency
! can you see architectural m
odel?
! layered, component, p
ipe/filter
! do dependencies match?
! trace dependencies with
tools
! follow #includes, im
ports
! call g
raphs
! quality
of dependency
! tied to quality
of interface
! cohesion / coupling
! maps effect propagatio
n
45
![Page 46: learning to live with it - ACCU :: ACCU (Pete...2009/03/09 · This presentation will look at practical strategies for working with “old” crufty code. We'll see how to:! start](https://reader036.vdocument.in/reader036/viewer/2022070802/5f02c0757e708231d405d573/html5/thumbnails/46.jpg)
mapping by control flow
! where is the entry point?
! where is the “main” hub of control?
! linear, batch process
! event lo
op
! message queue
! app framework, component in
terface
! is it t
hreaded?
! how well c
ontrolled are the threads?
! is it a
ctually thread safe?
! is it c
lear what can & can’t be concurrent?
! thread prioritie
s
46
![Page 47: learning to live with it - ACCU :: ACCU (Pete...2009/03/09 · This presentation will look at practical strategies for working with “old” crufty code. We'll see how to:! start](https://reader036.vdocument.in/reader036/viewer/2022070802/5f02c0757e708231d405d573/html5/thumbnails/47.jpg)
mapping by history
! the age of th
e code
! when was it s
tarted?
! when was it l
ast modifie
d?
! mine revision control
! who wrote it
! one author / many authors?
! do you have the latest version?
! what branch are you working on?
! do other branches have interestin
g (useful) s
tuff?
! the source it c
ame from originally
! download / vendor / other team
! where it i
s going?
! internal, r
esubmit upstream, publish to lic
ensees
47
![Page 48: learning to live with it - ACCU :: ACCU (Pete...2009/03/09 · This presentation will look at practical strategies for working with “old” crufty code. We'll see how to:! start](https://reader036.vdocument.in/reader036/viewer/2022070802/5f02c0757e708231d405d573/html5/thumbnails/48.jpg)
select mapping tools
! command line
! graphical
! programatic
48
![Page 49: learning to live with it - ACCU :: ACCU (Pete...2009/03/09 · This presentation will look at practical strategies for working with “old” crufty code. We'll see how to:! start](https://reader036.vdocument.in/reader036/viewer/2022070802/5f02c0757e708231d405d573/html5/thumbnails/49.jpg)
command line tools
! wc -l
! grep (-i)
! find (-name)
! xargs
! piping
! ls -hF --color -R
! find . -name “*.h” -o -name “*.c” | xargs cat | wc -l
! find . -name “*.h” -o -name “*.c” | xargs grep -i “usb_debug”
! cygwin
! ctags (excuberant ctags)
! mlcscope
49
![Page 50: learning to live with it - ACCU :: ACCU (Pete...2009/03/09 · This presentation will look at practical strategies for working with “old” crufty code. We'll see how to:! start](https://reader036.vdocument.in/reader036/viewer/2022070802/5f02c0757e708231d405d573/html5/thumbnails/50.jpg)
graphical tools
! code visualisation (modeling)
! doxygen, Ndoc
! a good IDE
! profiler
! debugger (not so good in large projects)
! understand for C++
testing
! static analysis! code test (lints, gcc -Wall)
! code coverage (clover, coverlipse)
! purify
! valgrind! (memcheck, cachegrind, callgrind, kcachegrind, etc)
50
![Page 51: learning to live with it - ACCU :: ACCU (Pete...2009/03/09 · This presentation will look at practical strategies for working with “old” crufty code. We'll see how to:! start](https://reader036.vdocument.in/reader036/viewer/2022070802/5f02c0757e708231d405d573/html5/thumbnails/51.jpg)
programatic tools
! unit test frameworks
! continuous integration
! refactor-capable editor
! source control
51
![Page 52: learning to live with it - ACCU :: ACCU (Pete...2009/03/09 · This presentation will look at practical strategies for working with “old” crufty code. We'll see how to:! start](https://reader036.vdocument.in/reader036/viewer/2022070802/5f02c0757e708231d405d573/html5/thumbnails/52.jpg)
(the map)understand: the code
keep notes
! notebook
! wiki
! text files
-diagrams-keep them updated
-what’s wrong-bits that don’t fit-things to look at later in
more detail-bits to fix later-record progress-unanswered questions
52
![Page 53: learning to live with it - ACCU :: ACCU (Pete...2009/03/09 · This presentation will look at practical strategies for working with “old” crufty code. We'll see how to:! start](https://reader036.vdocument.in/reader036/viewer/2022070802/5f02c0757e708231d405d573/html5/thumbnails/53.jpg)
(the map)understand: the code
gauge quality
! structure! appropriateness
! cohesion/coupling
! single responsibility
! code quality! readability
! for separate use
! the build! ease of building
! documentation
! automated (automatable)
! does it build without warnings?
53
![Page 54: learning to live with it - ACCU :: ACCU (Pete...2009/03/09 · This presentation will look at practical strategies for working with “old” crufty code. We'll see how to:! start](https://reader036.vdocument.in/reader036/viewer/2022070802/5f02c0757e708231d405d573/html5/thumbnails/54.jpg)
(the caution)remember, this is not an event, its an ongoing
process
54
![Page 55: learning to live with it - ACCU :: ACCU (Pete...2009/03/09 · This presentation will look at practical strategies for working with “old” crufty code. We'll see how to:! start](https://reader036.vdocument.in/reader036/viewer/2022070802/5f02c0757e708231d405d573/html5/thumbnails/55.jpg)
plan of attack! what is legacy code! how to understand it! how to modify it
legacy code learning to live with it pete goodliffe
55
![Page 56: learning to live with it - ACCU :: ACCU (Pete...2009/03/09 · This presentation will look at practical strategies for working with “old” crufty code. We'll see how to:! start](https://reader036.vdocument.in/reader036/viewer/2022070802/5f02c0757e708231d405d573/html5/thumbnails/56.jpg)
this is the easy bitwell, not really
56
![Page 57: learning to live with it - ACCU :: ACCU (Pete...2009/03/09 · This presentation will look at practical strategies for working with “old” crufty code. We'll see how to:! start](https://reader036.vdocument.in/reader036/viewer/2022070802/5f02c0757e708231d405d573/html5/thumbnails/57.jpg)
your mission! make the changes
! don’t break anything
! improve the code on the way
57
![Page 58: learning to live with it - ACCU :: ACCU (Pete...2009/03/09 · This presentation will look at practical strategies for working with “old” crufty code. We'll see how to:! start](https://reader036.vdocument.in/reader036/viewer/2022070802/5f02c0757e708231d405d573/html5/thumbnails/58.jpg)
your mission! what are the requirements?
! one task at a time
! what else do you need to do?
! fix bugs! refactor! integrate
! one task at a time
58
![Page 59: learning to live with it - ACCU :: ACCU (Pete...2009/03/09 · This presentation will look at practical strategies for working with “old” crufty code. We'll see how to:! start](https://reader036.vdocument.in/reader036/viewer/2022070802/5f02c0757e708231d405d573/html5/thumbnails/59.jpg)
! one task at a time
59
![Page 60: learning to live with it - ACCU :: ACCU (Pete...2009/03/09 · This presentation will look at practical strategies for working with “old” crufty code. We'll see how to:! start](https://reader036.vdocument.in/reader036/viewer/2022070802/5f02c0757e708231d405d573/html5/thumbnails/60.jpg)
strate
gise
Pinpoint the code to change
Note locations for change
Down to exact function(s)
What else might be affected by changes?
Are you changing interfaces?
What kind of change is appropriate
Wee fertle
Open heart surgery
Rip up and replace
Maintain old interface?
Experiment: try prototypes
60
![Page 61: learning to live with it - ACCU :: ACCU (Pete...2009/03/09 · This presentation will look at practical strategies for working with “old” crufty code. We'll see how to:! start](https://reader036.vdocument.in/reader036/viewer/2022070802/5f02c0757e708231d405d573/html5/thumbnails/61.jpg)
write the code
61
![Page 62: learning to live with it - ACCU :: ACCU (Pete...2009/03/09 · This presentation will look at practical strategies for working with “old” crufty code. We'll see how to:! start](https://reader036.vdocument.in/reader036/viewer/2022070802/5f02c0757e708231d405d573/html5/thumbnails/62.jpg)
write the codebut that’s a different talk...
follow these rules >>
62
![Page 63: learning to live with it - ACCU :: ACCU (Pete...2009/03/09 · This presentation will look at practical strategies for working with “old” crufty code. We'll see how to:! start](https://reader036.vdocument.in/reader036/viewer/2022070802/5f02c0757e708231d405d573/html5/thumbnails/63.jpg)
rule #1: code tact
! Follow the existing style
Layout, naming, lib
raries
Add libraries carefully
! Respect earlier programmers
Whether still around or not
! Treat th
e code carefully
It’s a fragile beast
Be polite to it
! Don’t a
sk too much of the code
One thing at a time
63
![Page 64: learning to live with it - ACCU :: ACCU (Pete...2009/03/09 · This presentation will look at practical strategies for working with “old” crufty code. We'll see how to:! start](https://reader036.vdocument.in/reader036/viewer/2022070802/5f02c0757e708231d405d573/html5/thumbnails/64.jpg)
rule #2: know who to trust
! Don’t trust the build system
Rebuild, make clean, dependencies
Especially if has custom steps
! Not the earlier programmers
Keep the benefit of the doubt
! Not the specifications
Documents get outdated
! Only the codeWhat it does right now
Know how to ask it
64
![Page 65: learning to live with it - ACCU :: ACCU (Pete...2009/03/09 · This presentation will look at practical strategies for working with “old” crufty code. We'll see how to:! start](https://reader036.vdocument.in/reader036/viewer/2022070802/5f02c0757e708231d405d573/html5/thumbnails/65.jpg)
rule
#3:
clos
e th
e fe
edba
ck lo
op
! Build it. Run it. Test it. Repeat.
How long does it take?
! Break itJust to prove you’ve changed it
! Do one thing at a time
Then you know what made the
change! Construct a test environm
ent
Don’t stab in the dark
65
![Page 66: learning to live with it - ACCU :: ACCU (Pete...2009/03/09 · This presentation will look at practical strategies for working with “old” crufty code. We'll see how to:! start](https://reader036.vdocument.in/reader036/viewer/2022070802/5f02c0757e708231d405d573/html5/thumbnails/66.jpg)
rule
#3:
clos
e th
e fe
edba
ck lo
op
! Avoid switching out
Speed up turnaround
Helps you get into flow
Enables experimentation
Prevents errors
Slow turnaround kills development
Encourages multiple sim
ultaneous changes
Switching tasks between builds
66
![Page 67: learning to live with it - ACCU :: ACCU (Pete...2009/03/09 · This presentation will look at practical strategies for working with “old” crufty code. We'll see how to:! start](https://reader036.vdocument.in/reader036/viewer/2022070802/5f02c0757e708231d405d573/html5/thumbnails/67.jpg)
rule
#3:
clos
e th
e fe
edba
ck lo
op
! Prove your changes work
Nothing was broken
New functionality works
You have done what was required
! How do you do this?
testingNeeds a good covering
! unit tests
! acceptance tests
67
![Page 68: learning to live with it - ACCU :: ACCU (Pete...2009/03/09 · This presentation will look at practical strategies for working with “old” crufty code. We'll see how to:! start](https://reader036.vdocument.in/reader036/viewer/2022070802/5f02c0757e708231d405d573/html5/thumbnails/68.jpg)
(tests)! don’t need to create 100% test coverage!
! more tests better than fewer
! broad coverage for main parts of functionality! a few broad tests probably more effective than many narrow ones
! targeted tests for the piece you’re changing
! test-first for new code
! adding tests is not easy! break out mockable interfaces
! find/create seams to inspect behaviour
! refactor
! easier for OO code than procedural
! explore existing functionality! capture them in tests!
68
![Page 69: learning to live with it - ACCU :: ACCU (Pete...2009/03/09 · This presentation will look at practical strategies for working with “old” crufty code. We'll see how to:! start](https://reader036.vdocument.in/reader036/viewer/2022070802/5f02c0757e708231d405d573/html5/thumbnails/69.jpg)
rule #4:
meddle methodically
! Tidy the house
Don’t leave commented out code
Delete unnecessary/old code
Comment clearly
Leave it as you’d lik
e to live in
! Minimise intrusion
Only change what is necessary
Break out interfaces for change
Wrap and extend
Sprout functionality
! Laziness: le
an on the compiler
Let the compiler help you make
changes
69
![Page 70: learning to live with it - ACCU :: ACCU (Pete...2009/03/09 · This presentation will look at practical strategies for working with “old” crufty code. We'll see how to:! start](https://reader036.vdocument.in/reader036/viewer/2022070802/5f02c0757e708231d405d573/html5/thumbnails/70.jpg)
rule #4:
meddle methodically
! Tidy the house
Don’t leave commented out code
Delete unnecessary/old code
Comment clearly
Leave it as you’d lik
e to live in
! Minimise intrusion
Only change what is necessary
Break out interfaces for change
Wrap and extend
Sprout functionality
! Laziness: le
an on the compiler
Let the compiler help you make
changes
class Frog{ void Paint(Colour c); Food FavouriteFood() const;};
70
![Page 71: learning to live with it - ACCU :: ACCU (Pete...2009/03/09 · This presentation will look at practical strategies for working with “old” crufty code. We'll see how to:! start](https://reader036.vdocument.in/reader036/viewer/2022070802/5f02c0757e708231d405d573/html5/thumbnails/71.jpg)
rule #4:
meddle methodically
! Tidy the house
Don’t leave commented out code
Delete unnecessary/old code
Comment clearly
Leave it as you’d lik
e to live in
! Minimise intrusion
Only change what is necessary
Break out interfaces for change
Wrap and extend
Sprout functionality
! Laziness: le
an on the compiler
Let the compiler help you make
changes
class Frog{ void Paint(Colour c); Food FavouriteFood() const; static Colour GetLivery(Food f);};
71
![Page 72: learning to live with it - ACCU :: ACCU (Pete...2009/03/09 · This presentation will look at practical strategies for working with “old” crufty code. We'll see how to:! start](https://reader036.vdocument.in/reader036/viewer/2022070802/5f02c0757e708231d405d573/html5/thumbnails/72.jpg)
rule #4:
meddle methodically
! Tidy the house
Don’t leave commented out code
Delete unnecessary/old code
Comment clearly
Leave it as you’d lik
e to live in
! Minimise intrusion
Only change what is necessary
Break out interfaces for change
Wrap and extend
Sprout functionality
! Laziness: le
an on the compiler
Let the compiler help you make
changes
class Frog{ void Paint(Colour c); Food FavouriteFood() const; static Colour GetLivery(Food f);};
Colour c = Frog::GetLivery(freddie.FavouriteFood());freddie.Paint(c);
72
![Page 73: learning to live with it - ACCU :: ACCU (Pete...2009/03/09 · This presentation will look at practical strategies for working with “old” crufty code. We'll see how to:! start](https://reader036.vdocument.in/reader036/viewer/2022070802/5f02c0757e708231d405d573/html5/thumbnails/73.jpg)
rule #4:
meddle methodically
! Tidy the house
Don’t leave commented out code
Delete unnecessary/old code
Comment clearly
Leave it as you’d lik
e to live in
! Minimise intrusion
Only change what is necessary
Break out interfaces for change
Wrap and extend
Sprout functionality
! Laziness: le
an on the compiler
Let the compiler help you make
changes
class Frog{ void Paint(Colour c); Food FavouriteFood() const; static Colour GetLivery(Food f);};
Colour c = Frog::GetLivery(freddie.FavouriteFood());freddie.Paint(c);
73
![Page 74: learning to live with it - ACCU :: ACCU (Pete...2009/03/09 · This presentation will look at practical strategies for working with “old” crufty code. We'll see how to:! start](https://reader036.vdocument.in/reader036/viewer/2022070802/5f02c0757e708231d405d573/html5/thumbnails/74.jpg)
rule #4:
meddle methodically
! Tidy the house
Don’t leave commented out code
Delete unnecessary/old code
Comment clearly
Leave it as you’d lik
e to live in
! Minimise intrusion
Only change what is necessary
Break out interfaces for change
Wrap and extend
Sprout functionality
! Laziness: le
an on the compiler
Let the compiler help you make
changes
class Frog{ void XXX_Paint(Colour c); void PaintInLivery(); Food FavouriteFood() const; static Colour GetLivery(Food f);};
Colour c = Frog::GetLivery(freddie.FavouriteFood());freddie.Paint(c); //< fails to compile
74
![Page 75: learning to live with it - ACCU :: ACCU (Pete...2009/03/09 · This presentation will look at practical strategies for working with “old” crufty code. We'll see how to:! start](https://reader036.vdocument.in/reader036/viewer/2022070802/5f02c0757e708231d405d573/html5/thumbnails/75.jpg)
rule #4:
meddle methodically
! Tidy the house
Don’t leave commented out code
Delete unnecessary/old code
Comment clearly
Leave it as you’d lik
e to live in
! Minimise intrusion
Only change what is necessary
Break out interfaces for change
Wrap and extend
Sprout functionality
! Laziness: le
an on the compiler
Let the compiler help you make
changes
class Frog{ void XXX_Paint(Colour c); void PaintInLivery(); Food FavouriteFood() const; static Colour GetLivery(Food f);};
freddie.PaintInLivery();
75
![Page 76: learning to live with it - ACCU :: ACCU (Pete...2009/03/09 · This presentation will look at practical strategies for working with “old” crufty code. We'll see how to:! start](https://reader036.vdocument.in/reader036/viewer/2022070802/5f02c0757e708231d405d573/html5/thumbnails/76.jpg)
rule #4:
meddle methodically
! Tidy the house
Don’t leave commented out code
Delete unnecessary/old code
Comment clearly
Leave it as you’d lik
e to live in
! Minimise intrusion
Only change what is necessary
Break out interfaces for change
Wrap and extend
Sprout functionality
! Laziness: le
an on the compiler
Let the compiler help you make
changes
class Frog{ void Paint(Colour c); void PaintInLivery(); Food FavouriteFood() const; static Colour GetLivery(Food f);};
freddie.PaintInLivery();
76
![Page 77: learning to live with it - ACCU :: ACCU (Pete...2009/03/09 · This presentation will look at practical strategies for working with “old” crufty code. We'll see how to:! start](https://reader036.vdocument.in/reader036/viewer/2022070802/5f02c0757e708231d405d573/html5/thumbnails/77.jpg)
! code tact! trust the code! close the feedback loop! meddle methodically
how to modify it
77
![Page 78: learning to live with it - ACCU :: ACCU (Pete...2009/03/09 · This presentation will look at practical strategies for working with “old” crufty code. We'll see how to:! start](https://reader036.vdocument.in/reader036/viewer/2022070802/5f02c0757e708231d405d573/html5/thumbnails/78.jpg)
plan of attack! what is legacy code! how to understand it! how to modify it
legacy code learning to live with it pete goodliffe
78
![Page 79: learning to live with it - ACCU :: ACCU (Pete...2009/03/09 · This presentation will look at practical strategies for working with “old” crufty code. We'll see how to:! start](https://reader036.vdocument.in/reader036/viewer/2022070802/5f02c0757e708231d405d573/html5/thumbnails/79.jpg)
lessons to learn
legacy code learning to live with it pete goodliffe
! new code becomes old instantly! write code that’s easy to modify! prevent errors in the future
! leave a legacy: test suite! make your code heard to misinterpret
! strive for clear interfaces and sound structure! file structure follows code structure! increase development speed! take small verifiable steps: one thing at a time! learn from legacy code to make new code better
79
![Page 80: learning to live with it - ACCU :: ACCU (Pete...2009/03/09 · This presentation will look at practical strategies for working with “old” crufty code. We'll see how to:! start](https://reader036.vdocument.in/reader036/viewer/2022070802/5f02c0757e708231d405d573/html5/thumbnails/80.jpg)
further reading
80