Practical Refactoring Tips For Developers That Love Legacy Applications (Nomad PHP)

Practical Refactoring Tips For Developers That Love Legacy Applications (Nomad PHP)

Lightning talk realized at Nomad PHP (https://www.youtube.com/watch?v=B9fOYN3tUF8).

049fbbe4e5fb94c45d6ccd656290d6fb?s=128

Davi Marcondes Moreira

August 17, 2017
Tweet

Transcript

  1. 2.

    Agenda ➔ Intro ➔ Why worry about refactoring? ➔ Practical

    tips! ➔ The most important tip - of all!!!
  2. 3.

    Agenda ➔ Intro ➔ Why worry about refactoring? ➔ Practical

    tips! ➔ The most important tip - of all!!! Trust me, it’s really the most important! :D
  3. 4.

    Intro Hi! I’m Davi Marcondes Moreira I’m a software developer

    at Pagar.me (Sao Paulo, Brazil). ~8 years PHP and (now struggling with) Node.js. Refactor enthusiast (mending is awesome!). I love dogs/cats/a bunch of other stuff!
  4. 5.

    Why worry about refactoring? Makers vs Menders Creating is awesome,

    but fixing is where I find my true passion.
  5. 6.

    Why worry about refactoring? Makers vs Menders Creating is awesome,

    but fixing is where I find my true passion. Broken Window Theory Software maintenance is critical for all business.
  6. 8.

    Practical tips! Where do I begin? Or, how to cure

    a sickness? With a proper diagnosis :P
  7. 9.
  8. 10.
  9. 11.
  10. 12.
  11. 13.

    Practical tips! 1. Renaming methods Using a clearer and more

    descriptive declaration. Be explicit as possible. In critical situations, you can insert the new call inside the old one; so you can keep changing without breaking any compatibility in your code base.
  12. 14.

    Practical tips! // Class spread all over your app class

    Foo { public function oldScaryMethod( $foo, $bar, $baz ) { // Lots of things happening here } }
  13. 15.

    Practical tips! // Class spread all over your app class

    Foo { public function oldScaryMethod( $foo, $bar, $baz ) { // Lots of things happening here } } // Call encapsulated in another method class Foo { public function newMethod( $foo ) { // We can act here $this->oldScaryMethod(...); } public function oldScaryMethod(...) { // Complexity is now isolated! } }
  14. 16.

    Practical tips! 2. Extracting responsabilities Single Responsability Principle Identify where

    you can move extra responsabilities found in your code into new classes/methods.
  15. 17.

    Practical tips! 3. Remove dead code Copied-and-pasted or commented code:

    seek and destroy. Don’t be affraid to delete code - use your VCS and relax. Remember to always have a good test strategy to make sure that things aren’t left broken.
  16. 18.

    The most important tip - of all!! Is the Intention!

    Encourage your team by cultivating a good culture of refactoring, involving tests, boldness, and empowerment. Don’t be negligent: the problem you neglect today will become the bug you will fix tomorrow - or 10 minutes after deploying.