Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Working with Legacy codebase

Paul Taykalo
July 16, 2016
100

Working with Legacy codebase

Paul Taykalo

July 16, 2016
Tweet

Transcript

  1. Plan 4 What is Legacy Code 4 Problems with Legacy

    Code 4 Dealing with Legacy Code 4 Features vs Refactoring balance 4 Measure our Success :) Paul Taykalo, UMT 2016 3
  2. an amount of money or property left to someone in

    a will :) Definition Legacy Code /lɛɡəsi/ Paul Taykalo, UMT 2016 5
  3. So here we'll tell what legacy code is not :)

    Legacy code is not... Paul Taykalo, UMT 2016 6
  4. Even the code is bad it doesn't make it a

    Legacy. Bad code can be covered with tests, and works fine. And sometimes more then enough. Don't mark it as a Legacy if you think that it's just look bad Bad Code is not always a Legacy Code Paul Taykalo, UMT 2016 7
  5. It's always good to blame other people for making a

    legacy code. If you know people who are writing the code, and you can reach them - they writing kind'a ok code. In case if they left their job, for some reasons people automatically tend to think that code of people who left is legacy. by default. Other people's code is not a Legacy code Paul Taykalo, UMT 2016 8
  6. This works backwards too Nice looking code can be a

    Legacy code Paul Taykalo, UMT 2016 10
  7. Code without tests is bad code. It doesn't matter how

    well written it is 1 Michael C. Feathers Working with Legacy Code Paul Taykalo, UMT 2016 11
  8. Why do we so care about it? May be Legacy

    Code is just another buzzword we complains about? Why do we care about Legacy Code? Paul Taykalo, UMT 2016 12
  9. It strikes you when you aren't expecting it. At Friday's

    evening, for example https://www.youtube.com/watch?v=DT2X5b0tyDI Legacy code is... Unpredictable Paul Taykalo, UMT 2016 15
  10. Because all of above, it's really hard to support this

    kind of code in reasonable timte Legacy code is... Time consuming Paul Taykalo, UMT 2016 17
  11. And beacuse of that Legacy code actually becomes a proble.

    It just stops feature delivery Legacy code ... Stops features delivery Paul Taykalo, UMT 2016 18
  12. Ask yourself, do you have Legacy in the Project? Why

    do we write it? Paul Taykalo, UMT 2016 19
  13. Sometimes it's really "Tecnical Debt", when customer comes in and

    asks to make feature really fast. But some lazy developers tend to use Unmaintainable code generators 4 So called "Technical Debt" Paul Taykalo, UMT 2016 21
  14. No comment here Unmaintainable code generators 4 So called "Technical

    Debt" 4 Code without Tests Paul Taykalo, UMT 2016 22
  15. YAA makes project way more complex, an way more harder

    to support Unmaintainable code generators 4 So called "Technical Debt" 4 Code without Tests 4 Yet Another Architecture Paul Taykalo, UMT 2016 23
  16. It's the same for another cute awesome library. In ost

    cases it's better to avoid additional library. You just can't allow to add to your code even more complexity Unmaintainable code generators 4 So called "Technical Debt" 4 Code without Tests 4 Yet Another Architecture 4 Super Awesome Library X Paul Taykalo, UMT 2016 24
  17. Funny one. Other people generates Legacy Code by default. It

    is known Unmaintainable code generators 4 So called "Technical Debt" 4 Code without Tests 4 Yet Another Architecture 4 Super Awesome Library X 4 Other people* Paul Taykalo, UMT 2016 25
  18. So here ae some tecnics that will prevent us from

    writing legacy code. Dealing with Legacy Code Preventive measures Paul Taykalo, UMT 2016 27
  19. If you don't write any code - you won't be

    able to add more legacy to it. Also, it's obviously that reading few lines of code is way simpler than reading 200 Stop writing code! 4 More code - more legacy code 4 Less code - less errors 4 Less code is easier to read Paul Taykalo, UMT 2016 29
  20. This is actually contrexample, when you need to write more

    code to make it more readable. The Idea here is to make code readable and understandable. Check two exampes above Less code exceptions mViewModels.value.map { $0.map { $0.map { $0.price }}} mViewModels.value.map { sections in sections.map { items in items.map { item in item.price } } } Paul Taykalo, UMT 2016 31
  21. Hey, I'm captain obsious here, but you need to add

    them, seriously Start adding tests Paul Taykalo, UMT 2016 33
  22. You should start writing tests from tomorrow. Start adding tests

    If you don't write tests you will never learn how to write them, its better to write bad tests then not to write any — https://t.co/KgfdqTbOSr Paul Taykalo, UMT 2016 34
  23. Start adding tests Whenever you are tempted to type something

    into a print statement or a debugger expression, write it as a test instead. — Martin Fowler Paul Taykalo, UMT 2016 35
  24. I have an opinion about this part. Depending on the

    project size So here, depending on the side of the project, if project is small, you would probably wont' receive any time saves, just beacuase o fproject size. So technically test setup and runs will take you way more precious time to do. Paul Taykalo, UMT 2016 36
  25. Generated code. Really helpful to prevent mistakes. If it works

    - it works for every generated class. if it wont - it won't Do code generation Paul Taykalo, UMT 2016 37
  26. Do code generation! 4 Stops you from manual work 4

    Unifies project architecture 4 Prevents you from human-like mistakes Paul Taykalo, UMT 2016 38
  27. If you're about to stick to the same architecture, it

    means, that you can predefine some parts to be in templates. This will decreas amount of time to rewrite things, and also Make templates for classes or big code parts Paul Taykalo, UMT 2016 39
  28. Pull Requests. At least more than one person will know

    about what happening in the code base Let other people read your code Paul Taykalo, UMT 2016 40
  29. Am I doing better today? Is it better then previous

    year? Dealing with Legacy Code Know your status Paul Taykalo, UMT 2016 41
  30. More than that. Make your code easy to delete Dealing

    with Legacy Code Delete code Paul Taykalo, UMT 2016 43
  31. EACH big project will have unused classes/methods etc It's superb

    to / Libraries Remove old unused code Paul Taykalo, UMT 2016 44
  32. Just remove it. Easily. It's simple Remove old unused code

    func removeItem(item: MenuItem) { var sectionsToRemove: [CartOrderSection] = [] // mSections.value.forEach { section in // section.removeItem(item) // let containsNonPinnedItems = section.items.value.contains { $0.menuItem.pinned != true } // if !containsNonPinnedItems { // sectionsToRemove += [section] // } // } for section in sectionsToRemove { removeSection(section) } mSections.value = mSections.value } Paul Taykalo, UMT 2016 45
  33. Not all IDEs will tell you about that. Be careful

    if you do dynamic classes Remove old unused code Paul Taykalo, UMT 2016 46
  34. Feel free to mark classes/methods as deprecated, this will prevent

    these classes/methos usage across the prohect. You don't want really bad code to spread around more than it does now Deprecate unwanted code Paul Taykalo, UMT 2016 47
  35. If you spent some time reading legacy code - and

    you cannot fix it now, but you unrestood what next possible steps should be Leave a comment. This will prevent you or other people for re- reading and rethinking the complex part of the code. Leave comments Leave warnings Paul Taykalo, UMT 2016 48
  36. In general case dependencies always grows. We should recheck our

    deps from time to time Recheck and cleanup dependencies Paul Taykalo, UMT 2016 49
  37. Instead of blindly rewriting old code in new "way", make

    sure that "new way" written code won't become Legacy in short We're forcing to have tests for the new functionality as well as when we're changing old parts of code those without tests Add tests on changes you make Don't use "Change and Pray" approach Paul Taykalo, UMT 2016 50
  38. It's really hard to stop fixing everything, when there are

    a lot of things wrong, but you should be careful about big breaking changes One refactor at the time Paul Taykalo, UMT 2016 51
  39. There are some good tools for refactoring. Don't rely on

    the Xcode only. Some IDE's know how to do it correctly. Use tools for refactoring Paul Taykalo, UMT 2016 52
  40. In case of big and long running project, there's a

    big desire to try some new better approaches to do something in new way. Try to avoid this as much as possible. i.e KVO vs manual observing vs Notifications. Stick to the same architecture within the project* Paul Taykalo, UMT 2016 53
  41. This one is a bit cardinal solution, but there's always

    an option to put some parts of the project into the library. This will prevent logic leaking through All the layers of the project, and also decrease main project size. This could take a while, but it worth it. In worst case, we could try to make another application insteead of doing everthing in one app. Decrease project size Paul Taykalo, UMT 2016 54
  42. Understanding what went wrong 4 Crashes 4 Bugs 4 Deadlocks

    4 Data loss 4 Unexpected behaviours Paul Taykalo, UMT 2016 56
  43. Captain obvious :)) Everyone doing it, right? Understanding what went

    wrong Crash logging Paul Taykalo, UMT 2016 57
  44. Here are some tools for crash Understanding what went wrong

    Crash logging Tools 4 Crashlytics 4 HockeyApp 4 TestFlight 4 BugSee Paul Taykalo, UMT 2016 58
  45. This can be done while trying to replicate things Understanding

    went wrong Debugging Paul Taykalo, UMT 2016 59
  46. Xcode, LLDB, Chisel Understanding went wrong Debugging tools 4 Xcode

    4 LLDB 4 Chisel 4 View Debugging / Description Paul Taykalo, UMT 2016 60
  47. This can be done while trying to replicate things Understanding

    went wrong Remote Logging Paul Taykalo, UMT 2016 61
  48. Here are some tools for remote logs Understanding went wrong

    Remote logging tools 4 Crashlytics 4 LogEntries Paul Taykalo, UMT 2016 62
  49. If you give enough time to the developers, they will

    rewrite code again and again and again until it will be "perfect" At least for some time Features delivery We aren't paid for fighting with Technical Debt Paul Taykalo, UMT 2016 65
  50. But each feature 4 Adds more code 4 Adds complexity

    4 Increases project size 4 Increases testing time Paul Taykalo, UMT 2016 66
  51. This one is hard. Depending on how big your project

    is, you can either work with with new features and Features vs Tech Debt Paul Taykalo, UMT 2016 67
  52. Different features types 4 Affects nothing (independent) 4 Affects one

    localized previous feature 4 Affects multiple previous features 4 Affects all application Paul Taykalo, UMT 2016 69
  53. Always have time to clean up a project. Plan accordingly.

    From the other hand, focus on feature while doing it And don't spend any time on rewriting old functionality - Put TODOS, comments etc. 90/10 Principle* Paul Taykalo, UMT 2016 70
  54. Some techical stuff, easy to read, easy to check shoud

    be check automatically //TODO : Graph Image Measure 4 Tests count 4 Test coverage 4 Code Lines Count 4 Tests Lines Count Paul Taykalo, UMT 2016 72
  55. Not everything can be tracked automatically, but can be measured.

    Results need to be checked at retru // TODO: Other reports Measure 4 Crash-free users/sessions 4 Number of days since last incident 4 Amount of bugs create in the last X days 4 Regressions count Paul Taykalo, UMT 2016 74
  56. Measure development speed 4 Features count per time 4 Time

    per feature to be delivered Paul Taykalo, UMT 2016 76
  57. Recap 4 Get the project status 4 Set up goals

    4 Tack changes 4 Stop writing Legacy Code Paul Taykalo, UMT 2016 78