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

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).

Davi Marcondes Moreira

August 17, 2017
Tweet

More Decks by Davi Marcondes Moreira

Other Decks in Programming

Transcript

  1. Agenda ➔ Intro ➔ Why worry about refactoring? ➔ Practical

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

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

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

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

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

    you can move extra responsabilities found in your code into new classes/methods.
  11. 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.
  12. 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.