Working on a Legacy App

90f7f6e0fe6a8b894481158315b1de07?s=47 Marco Sero
August 27, 2015

Working on a Legacy App

90f7f6e0fe6a8b894481158315b1de07?s=128

Marco Sero

August 27, 2015
Tweet

Transcript

  1. Hi

  2. Marco Sero @marcosero

  3. Microsoft

  4. iOS @ Yammer

  5. WORKING ON A LEGACY APP

  6. DEFINITION OF LEGACY

  7. "Anything handed down from the past, as from an ancestor

    or predecessor"
  8. "Obsolete"

  9. DEFINITION OF LEGACY CODE

  10. No Unit Tests

  11. Still used in Production

  12. IT JUST WORKS* *most of the time

  13. Written in a language that you don't typically do new

    development in
  14. Swift 1.2

  15. Old and complicated History

  16. Many Contributors...

  17. ...That have all quit

  18. Let's recap ✔ Still used in production ! ✔ Old

    or deprecated language ! ✔ Without unit tests ! ✔ Old history with many, many contributors... ! ✔ ...most of which not around anymore !
  19. Or whenever you feel like this

  20. Not much Legacy on iOS

  21. iOS development is new(ish) Short app lifetime Easier to re-write

  22. So why bother?

  23. None
  24. None
  25. JUST STOP PLEASE STOP

  26. WHERE DO I START?

  27. STATS

  28. Identify the risk and start there $ find YourApp -iname

    "*.h" | xargs grep -h 'interface' | cut -d ' ' -f 2 | while read class; do echo `grep -r "\b$class\b" YourApp --include "*.m" | wc -l` $class; done | sort -n -u from Destroy All Software screencasts.
  29. None
  30. Leverage git

  31. Git Blame ⌥⌘⇧㾑

  32. None
  33. None
  34. None
  35. git log -L 1,1:/your/file

  36. COMMIT MESSAGES

  37. None
  38. None
  39. Your COMMIT MESSAGES are your LEGACY

  40. (Maybe) DEAD CODE

  41. TOMBSTONES - (void)possibleDeadCode { // current date when tombstone was

    added log_tombstone(@"2015-08-21"); } • Log found? ➡ Code is alive ! • Log not found? ➡ Code is dead " From David Schnepper's Ignite talk, "Isn't That Code Dead?"
  42. CONTINUOUS DESTRUCTION

  43. Inheritance

  44. None
  45. @implementation RootViewController - (void)doSomething:(NSString *)aString { } @end @implementation RootViewController_iPad

    - (void)doSomething:(NSString *)aString { NSLog(@"%@ iPad", aString); } @end @implementation RootViewController_iPhone - (void)doSomething:(NSString *)aString { NSLog(@"%@ iPhone", aString); } @end RootViewController *vc = [[RootViewController_iPad alloc] init]; [vc doSomething:@"cool"]; // prints "cool iPad"
  46. @implementation RootViewController - (void)doSomething:(NSString *)aString { } @end @implementation RootViewController_iPad

    - (void)doSomething { NSLog(@"iPad"); } @end @implementation RootViewController_iPhone - (void)doSomething:(NSString *)aString { NSLog(@"%@ iPhone", aString); } @end RootViewController *vc = [[RootViewController_iPad alloc] init]; [vc doSomething:@"cool"]; // prints nothing
  47. class RootViewController: UIViewController { func doSomething(aString: String) { } }

    class RootViewController_iPad: RootViewController { override func doSomething(aString: String) { print(aString + "iPad") } } class RootViewController_iPhone: RootViewController { override func doSomething(aString: String) { print(aString + "iPhone") } }
  48. class RootViewController: UIViewController { func doSomething(aString: String) { } }

    class RootViewController_iPad: RootViewController { override func doSomething() { // COMPILE ERROR print("iPad") } } class RootViewController_iPhone: RootViewController { override func doSomething(aString: String) { print(aString + "iPhone") } }
  49. "I've got your back" — Chris Lattner on Swift's Safety

  50. THIRD-PARTY DEPENDENCIES

  51. AVOID THEM (if possible)

  52. Build a small, but non-trivial, Rails app. [...] Go away

    for six months. Come back and update all of your dependencies. Your app no longer works. — Gary Bernhardt
  53. Build a small, but non-trivial, iOS app. [...] Go away

    for six months. Come back and update all of your dependencies. Your app no longer works. — Marco Sero
  54. FORKS

  55. Recap: • Start identifying the risk • Leverage Git •

    Spend some time writing good commit messages • Continuous destruction of dead code • Avoid subclasses and touch them with care • Third party dependencies have a cost and private forks are almost always a bad idea
  56. None
  57. BE A GOOD CITIZEN

  58. HAVE FUN !"#

  59. Thank you. @marcosero • Working Effectively with Legacy Code by

    Michael Feathers • Utter Disregard for Git Commit History by Zach Holman http://zachholman.com/posts/git-commit-history/ • Destroy All Software screencast by Gary Bernhardt https://www.destroyallsoftware.com/screencasts • Isn't That Code Dead? by David Schnepper https://www.youtube.com/watch?v=29UXzfQWOhQ