Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Where do i start?


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
  • Be the first to comment

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: • Coderwall: • MojoLive: • LinkedIn: 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
  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. 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: (also available in ePub and PDF files) Code: 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. 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: 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. 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