Pro Yearly is on sale from $80 to $50! »

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. Practical Refactoring Tips For Developers That Love Legacy Applications 2017-08-17

    @ Nomad PHP Davi Marcondes Moreira - @devdrops
  2. Agenda ➔ Intro ➔ Why worry about refactoring? ➔ Practical

    tips! ➔ The most important tip - of all!!!
  3. Agenda ➔ Intro ➔ Why worry about refactoring? ➔ Practical

    tips! ➔ The most important tip - of all!!! Trust me, it’s really the most important! :D
  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!
  5. Why worry about refactoring? Makers vs Menders Creating is awesome,

    but fixing is where I find my true passion.
  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.
  7. Practical tips! Where do I begin? Or, how to cure

    a sickness?
  8. Practical tips! Where do I begin? Or, how to cure

    a sickness? With a proper diagnosis :P
  9. None
  10. None
  11. None
  12. None
  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.
  14. Practical tips! // Class spread all over your app class

    Foo { public function oldScaryMethod( $foo, $bar, $baz ) { // Lots of things happening here } }
  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! } }
  16. Practical tips! 2. Extracting responsabilities Single Responsability Principle Identify where

    you can move extra responsabilities found in your code into new classes/methods.
  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.
  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.
  19. Thank you! :D @devdrops devdrops.me/about