It is time to fight the black holes in your software. Don't let legacy code dictate your work. Start learning and practicing dependency injection and refactoring. Become more agile.
2. I was told itâs good to start
a presentation with an
interesting personal story.
I have a personal story but
itâs not so interesting.
Many years ago I worked on
a Legacy systemâŠ
3. There was a specific area
that was prone to defects.
So I asked my manager to
refactor it. After 3 days of
refactoring there were no
more defects. Not very
interesting indeed.
4. 4 |
In many software
organizations there are
these black holes in the
software.
8. Fear Of Legacy Code Make US:
ï¶ Dependent on specific people for specific tasks
ï¶ Avoid the right solution
ï¶ Slow to react
ï¶ Not as agile as we would like to be
8 |
Can you afford to have this
in your organization?
9. Ending The Fear Of Legacy Code
ï¶ Understand what is our safety net
ï¶ Weave the safety net
ï¶ Make it easy to understand and change
ï¶ Make the change
9 |
Are the steps to handle
these black holes.
10. Ending The Fear Of Legacy Code
ï¶ Understand what is our safety net
ï¶ Weave the safety net
ï¶ Make it easy to understand and change
ï¶ Make the change
10 |
11. At the road
Before starting road works,
thereâs a lot of work to be
done, to make it safe.
17. Unit tests!
ï¶ Quick
ï¶ Pin pointed
ï¶ Cheap
Unit tests are very cheap,
very quick and pin point the
problem when it fails.
However it requires
discipline.
18. Unit Tests
18 |
Arrange
Act
Assert
Unit tests are built of three
phases: arrange data, act
(do the job), assert that the
actual outcome is what was
expected
19. 19 |
The answer I get from people
in organizations: âYouâre
absolutely right. However our
code is like spaghetti, therefore
it is impossible to run unit
tests.â
22. Ending The Fear Of Legacy Code
ï¶ Understand what is our safety net
ï¶ Weave the safety net
ï¶ Make it easy to understand and change
ï¶ Make the change
22 |
So, what do we do with our
spaghetti code?
23. 23 |
Method
Method
Method
Method
Database
External API
Globals/static methods
Parameters
Output
1. Wrap, extract
to Interface.2. Add it as a
parameter/ field etc.
3. Create a
fake (Stub,
Mock or
Spy) for
your tests.Use available tests (manual, Integration) and
IDE refactoring (when exist) to do this slowly
and safely
Subclass and
override the
method for
the test
We handle the dependencies
one by one
24. 24 |
Thatâs a lot of work!
This is about technique, practice
and discipline.
25. 25 |
It took some of us one day
to create a unit test for a
method that everyone were
afraid of in a startup.
26. 26 |
Fixate the results
You donât need a design
document to know how
should the method work.
You just need to make sure
it continues doing what it
already does.
27. Return on Investment
ï¶ Start real slow
ï¶ See benefits
ï¶ Decide how to continue
27 |
No big investment is required.
You just need to start. It wonât
take long until you need to
make a change in a place that
already has tests â thatâs
something!
28. Ending The Fear Of Legacy Code
ï¶ Understand what is our safety net
ï¶ Weave the safety net
ï¶ Make it easy to understand and change
ï¶ Make the change
28 |
Once the safety net is there the
fun begins. Now it is time to
start refactoring
29. Code Smells
ï¶ Black sheep/Oddball solution
ï¶ conditional complexity (If-Else)
ï¶ Deodorant method
ï¶ Duplicated code
ï¶ Feature envy
ï¶ Inappropriate intimacy/Indecent
exposure
ï¶ Inefficient name
ï¶ Long method/Lost intent, Large
class
29 |
ï¶ Long parameter list
ï¶ Primitive obsession
ï¶ Side effect
ï¶ Solution sprawl
ï¶ Speculative generality
ï¶ Switch statement
ï¶ Temporary field
There are many instances of
bad code
34. Refactoring To Patterns: Small Steps (2 Min.)
34 |
Use design patterns to make the
system more robust, easier to
change
35. 35 |
Every two minutes:
âą Make a small change, test
âą Make a small change, test
âą Make a small change, test
âą Make a small change, test
âą Make a small change, test
âą Make a small change, test
âą Stop any time, move to another task. Go home
36. Ending The Fear Of Legacy Code
ï¶ Understand what is our safety net
ï¶ Weave the safety net
ï¶ Make it easy to understand and change
ï¶ Make the change
36 |
With the safety net there and
with the code readable and
easy to change, making a
change is easy
37. Test Driven Design
ï¶ Write a test to make sure what you want to move
ï¶ Make the test fail
ï¶ Make it pass
ï¶ Refator
37 |
38. Ending The Fear Of Legacy Code
ï¶ Understand what is our safety net
ï¶ Weave the safety net
ï¶ Make it easy to understand and change
ï¶ Make the change
38 |