THEY CALL IT LEGACY
Because it's killing me to work on it
Tuesday, July 9, 13
WHERE DO I START?
Tuesday, July 9, 13
WHO AM I?
• Twitter: @arlen
• GitHub: Paladin
• Blog: http://www.theodicius.com
• Coderwall: https://coderwall.com/paladin...
LEGACY CODE
It's everywhere
Tuesday, July 9, 13
IT WASTHERE BEFORE
YOU ARRIVED
It'll be there after you're gone
Tuesday, July 9, 13
YOU DON'T
UNDERSTAND IT
Will those who follow you understand yours?
Tuesday, July 9, 13
YOU DON'T KNOWTHEIR
SKILL OR KNOWLEDGE
How will those who follow you know yours?
Tuesday, July 9, 13
THETRUTH IS INTHE
CODE
Yes,Agent Mulder. But where?
Tuesday, July 9, 13
Tuesday, July 9, 13
NOWTHATYOU HAVE IT
What are you going to do with it?
Tuesday, July 9, 13
REWRITE IT?
Tuesday, July 9, 13
Tuesday, July 9, 13
WATCH ME REWRITETHAT
CODE FROM SCRATCH!
That trick never works!
Tuesday, July 9, 13
WHAT’STHE PAIN POINT?
Why are you here in the first place?
Tuesday, July 9, 13
THETARRASCH PRINCIPLE
“When there is nothing
concrete to do, improve the
position of your worst
piece.”
Tuesday, July 9, 13
OK, SIGGY OLD BOY
How do I measure my
“worst piece” of software?
Tuesday, July 9, 13
W. EDWARDS DEMING
"You can't manage what
you can't measure"
Tuesday, July 9, 13
STOP AND SMELLTHE
CODE
Code “smells” are simple metrics you can use to
quickly locate potential trouble spots
Tuesday, Jul...
ODOR - STATIC CALL
Class::method() syntax reduces the code’s flexibility
Tuesday, July 9, 13
ODOR - LONG
ARGUMENT LIST
Many arguments may mean the method is connected
to the code in too many ways.
Tuesday, July 9, 13
ODOR - LONG METHOD
Too many lines may mean the method is trying to do
too much
Tuesday, July 9, 13
ODOR - LARGE CLASS
A class with too many methods may be trying to do
too much
Tuesday, July 9, 13
MORE COMPLEX CODE
METRICS
Tuesday, July 9, 13
NPATH COMPLEXITY
Number of paths through the code
Tuesday, July 9, 13
ACYCYLIC
DEPENDENCIES
Classes that depend upon classes that depend upon
them
Tuesday, July 9, 13
CYCLOMATIC
COMPLEXITY
Paths - nodes + 2 * endpoints
Tuesday, July 9, 13
CHANGE RISK ANALYSIS
AND PREDICTION
CC(m)^2 * (1 – Coverage(m)/100)^3 + CC(m)
Tuesday, July 9, 13
ARETHERETESTS?
Don't be silly
Tuesday, July 9, 13
YOU NEEDTESTS
Tests need seams
Tuesday, July 9, 13
DEBUGGINGTHROUGHTESTINGTHE COMPLETE
CODE STACK
Tuesday, July 9, 13
Find an existing seam, if possible
Create new seams by sprouting a new class or
method
Tuesday, July 9, 13
NOWYOU HAVETESTS
Are we there yet?
Tuesday, July 9, 13
HOW DO I USETHE
METRICS?
Tuesday, July 9, 13
SIMPLICATE
Tuesday, July 9, 13
TOO MANY METHODS?
Look to move some methods into new objects
Tuesday, July 9, 13
METHODTOO LONG?
Extract smaller methods from it.
Tuesday, July 9, 13
OBJECTTOO COMPLEX?
Simplify the coding by enforcing command/query
separation
Tuesday, July 9, 13
TOOLS!
You said there would be tools!
Tuesday, July 9, 13
DANGER,WILL ROBINSON!!
Don’t confuse the map with
the territory.The metrics are
a map to the location of
possible problems...
COPY/PASTE DETECTION
Finds code duplication in your project. Extracting them into a
single method will make future mainten...
PHPUNIT
The most popular automated unit testing framework for php,
used in most significant open source projects, such as D...
PHP MESS DETECTOR
The PHP Project Mess Detector goes through single files or an
entire project looking for many potential p...
PHP DEPEND
PHP Depend is a small program that generates several
different reports about the condition of a code project it...
THE OVERVIEW PYRAMID
This is a high-level view of the metrics of the system. It
calculates the cyclomatic complexity, coun...
OVERVIEW PYRAMID CHART
The overview Pyramid
charts for Drupal,Wordpress
and Joomla give us a “50,000
ft” view of the syste...
ABSTRACTION AND
INSTABILITY
The Abstraction metric (0-1) is measure of how easily the
system can be expanded/modified.
The ...
ABSTRACTION-INSTABILITY
CHART
These are the A-I charts for
Drupal,Wordpress, and Joomla.
Drupal has very few objects
but t...
SYMFONY2
Here are the charts for the
Symfony2 framework.
The overview looks very
good, while the A-I chart
shows a well-di...
Upcoming SlideShare
Loading in …5
×

Where do i start?

513 views
474 views

Published on

Legacy code is something we all deal with. How can you figure out where to start untangling the big ball of mud you've been handed.

Note: photos excluded from CC LIcense.

Published in: Technology
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
513
On SlideShare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
2
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

Where do i start?

  1. 1. THEY CALL IT LEGACY Because it's killing me to work on it Tuesday, July 9, 13
  2. 2. WHERE DO I START? Tuesday, July 9, 13
  3. 3. WHO AM I? • Twitter: @arlen • GitHub: Paladin • Blog: http://www.theodicius.com • Coderwall: https://coderwall.com/paladin • MojoLive: http://mojolive.com/profile/paladin • LinkedIn: www.linkedin.com/in/arlenwalker/ Tuesday, July 9, 13
  4. 4. LEGACY CODE It's everywhere Tuesday, July 9, 13
  5. 5. IT WASTHERE BEFORE YOU ARRIVED It'll be there after you're gone Tuesday, July 9, 13
  6. 6. YOU DON'T UNDERSTAND IT Will those who follow you understand yours? Tuesday, July 9, 13
  7. 7. YOU DON'T KNOWTHEIR SKILL OR KNOWLEDGE How will those who follow you know yours? Tuesday, July 9, 13
  8. 8. THETRUTH IS INTHE CODE Yes,Agent Mulder. But where? Tuesday, July 9, 13
  9. 9. Tuesday, July 9, 13
  10. 10. NOWTHATYOU HAVE IT What are you going to do with it? Tuesday, July 9, 13
  11. 11. REWRITE IT? Tuesday, July 9, 13
  12. 12. Tuesday, July 9, 13
  13. 13. WATCH ME REWRITETHAT CODE FROM SCRATCH! That trick never works! Tuesday, July 9, 13
  14. 14. WHAT’STHE PAIN POINT? Why are you here in the first place? Tuesday, July 9, 13
  15. 15. THETARRASCH PRINCIPLE “When there is nothing concrete to do, improve the position of your worst piece.” Tuesday, July 9, 13
  16. 16. OK, SIGGY OLD BOY How do I measure my “worst piece” of software? Tuesday, July 9, 13
  17. 17. W. EDWARDS DEMING "You can't manage what you can't measure" Tuesday, July 9, 13
  18. 18. STOP AND SMELLTHE CODE Code “smells” are simple metrics you can use to quickly locate potential trouble spots Tuesday, July 9, 13
  19. 19. ODOR - STATIC CALL Class::method() syntax reduces the code’s flexibility Tuesday, July 9, 13
  20. 20. ODOR - LONG ARGUMENT LIST Many arguments may mean the method is connected to the code in too many ways. Tuesday, July 9, 13
  21. 21. ODOR - LONG METHOD Too many lines may mean the method is trying to do too much Tuesday, July 9, 13
  22. 22. ODOR - LARGE CLASS A class with too many methods may be trying to do too much Tuesday, July 9, 13
  23. 23. MORE COMPLEX CODE METRICS Tuesday, July 9, 13
  24. 24. NPATH COMPLEXITY Number of paths through the code Tuesday, July 9, 13
  25. 25. ACYCYLIC DEPENDENCIES Classes that depend upon classes that depend upon them Tuesday, July 9, 13
  26. 26. CYCLOMATIC COMPLEXITY Paths - nodes + 2 * endpoints Tuesday, July 9, 13
  27. 27. CHANGE RISK ANALYSIS AND PREDICTION CC(m)^2 * (1 – Coverage(m)/100)^3 + CC(m) Tuesday, July 9, 13
  28. 28. ARETHERETESTS? Don't be silly Tuesday, July 9, 13
  29. 29. YOU NEEDTESTS Tests need seams Tuesday, July 9, 13
  30. 30. DEBUGGINGTHROUGHTESTINGTHE COMPLETE CODE STACK Tuesday, July 9, 13
  31. 31. Find an existing seam, if possible Create new seams by sprouting a new class or method Tuesday, July 9, 13
  32. 32. NOWYOU HAVETESTS Are we there yet? Tuesday, July 9, 13
  33. 33. HOW DO I USETHE METRICS? Tuesday, July 9, 13
  34. 34. SIMPLICATE Tuesday, July 9, 13
  35. 35. TOO MANY METHODS? Look to move some methods into new objects Tuesday, July 9, 13
  36. 36. METHODTOO LONG? Extract smaller methods from it. Tuesday, July 9, 13
  37. 37. OBJECTTOO COMPLEX? Simplify the coding by enforcing command/query separation Tuesday, July 9, 13
  38. 38. TOOLS! You said there would be tools! Tuesday, July 9, 13
  39. 39. DANGER,WILL ROBINSON!! Don’t confuse the map with the territory.The metrics are a map to the location of possible problems in your code.They are not your code. Use the metrics, don’t let the metrics use you. Publicity photo from “Lost in Space” Tuesday, July 9, 13
  40. 40. COPY/PASTE DETECTION Finds code duplication in your project. Extracting them into a single method will make future maintenance easier It will also shorten the methods including them. Identical methods across multiple classes make good candidates for inheritance orTraits. https://github.com/sebastianbergmann/phpcpd Tuesday, July 9, 13
  41. 41. PHPUNIT The most popular automated unit testing framework for php, used in most significant open source projects, such as Drupal, Joomla, Zend Framework2, Symfony2, etc. Calculates a CRAP index on the code as part of the coverage report, but only for code executed as part of running the tests. Manual: http://phpunit.de/manual/current/en/index.html (also available in ePub and PDF files) Code: https://github.com/sebastianbergmann/phpunit/ Tuesday, July 9, 13
  42. 42. PHP MESS DETECTOR The PHP Project Mess Detector goes through single files or an entire project looking for many potential problem areas. It has some factors included in it, but you can create your own tests, if you have others you’d like to rely on. http://phpmd.org Tuesday, July 9, 13
  43. 43. PHP DEPEND PHP Depend is a small program that generates several different reports about the condition of a code project it’s pointed at.Aside from the “normal” reports, it produces two graphics that are quite useful for giving you a general idea of what you’re looking at: the Abstraction-Instability Chart and the Overview Pyramid. Code & Docs: http://www.pdepend.org/ Tuesday, July 9, 13
  44. 44. THE OVERVIEW PYRAMID This is a high-level view of the metrics of the system. It calculates the cyclomatic complexity, counts lines of code, methods, classes and packages. It also counts the distinct method calls, and “fan-out,” the references from a class to a class in a different inheritance branch, and analyses the inheritance heirarchy. Tuesday, July 9, 13
  45. 45. OVERVIEW PYRAMID CHART The overview Pyramid charts for Drupal,Wordpress and Joomla give us a “50,000 ft” view of the systems. Tuesday, July 9, 13
  46. 46. ABSTRACTION AND INSTABILITY The Abstraction metric (0-1) is measure of how easily the system can be expanded/modified. The instability metric (0 - 1) is an attempt to measure the ease of change. Packages approaching [0,0] are rigid. Packages approaching [1,1] are completely abstract, therefore useless.The “happy meridian” is a diagonal through the center of the chart. http://www.objectmentor.com/resources/articles/oodmetrc.pdf Tuesday, July 9, 13
  47. 47. ABSTRACTION-INSTABILITY CHART These are the A-I charts for Drupal,Wordpress, and Joomla. Drupal has very few objects but they’re well balanced. Wordpress has more, but no abstraction. Joomla has a wide range of objects, not all well-balanced. Tuesday, July 9, 13
  48. 48. SYMFONY2 Here are the charts for the Symfony2 framework. The overview looks very good, while the A-I chart shows a well-distributed mix of objects in the system. Tuesday, July 9, 13

×