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

Refactoring Risky Code

Refactoring Risky Code

In this talk we will see how to refactor hard to test code, like bluetooth with no tests, without introducing new bugs and minimal manual testing effort.

Philipp Hofmann

March 07, 2019
Tweet

More Decks by Philipp Hofmann

Other Decks in Programming

Transcript

  1. “Any fool can write code that a computer can understand.

    Good programmers write code that humans can understand.” Martin Fowler
  2. 70 to 90% of our time we spend on understanding

    code. Robert C. Martin, Carola Lilienthal and The Mythical Man Month
  3. Risky Code • Has no tests • Is not testable

    • Can break a lot • Can make users angry National Geographic
  4. “Refactoring is the process of changing a software system in

    a way that does not alter the external behaviour of the code yet improves its internal structure.” Martin Fowler
  5. ?

  6. /** * Scans for Bluetooth Classic devices. */ interface ClassicScanner

    { /** * Starts a scan when subscribed, * stops the scan when unsubscribed. */ fun scan(): Observable<ClassicScanResult> }
  7. Refactoring Survival Guide 1. Only wear one hat at a

    time 2. Keep your code green. 3. Keep your tests green. 4. Tests. Tests. Tests. 5. Small tasks. 6. Commit a lot. 7. Use the tools. 8. Minimise the damage. 9. Ship.
  8. Further Readings • Refactoring: Improving the Design of Existing Code

    • Working Efficiently With Legacy Code • Workflows of Refactoring • Opportunistic Refactoring • Clean Code: A Handbook of Agile Software Craftmanship