Slide 1

Slide 1 text

Practical Refactoring Tips For Developers That Love Legacy Applications 2017-08-17 @ Nomad PHP Davi Marcondes Moreira - @devdrops

Slide 2

Slide 2 text

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

Slide 3

Slide 3 text

Agenda ➔ Intro ➔ Why worry about refactoring? ➔ Practical tips! ➔ The most important tip - of all!!! Trust me, it’s really the most important! :D

Slide 4

Slide 4 text

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!

Slide 5

Slide 5 text

Why worry about refactoring? Makers vs Menders Creating is awesome, but fixing is where I find my true passion.

Slide 6

Slide 6 text

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.

Slide 7

Slide 7 text

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

Slide 8

Slide 8 text

Practical tips! Where do I begin? Or, how to cure a sickness? With a proper diagnosis :P

Slide 9

Slide 9 text

No content

Slide 10

Slide 10 text

No content

Slide 11

Slide 11 text

No content

Slide 12

Slide 12 text

No content

Slide 13

Slide 13 text

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.

Slide 14

Slide 14 text

Practical tips! // Class spread all over your app class Foo { public function oldScaryMethod( $foo, $bar, $baz ) { // Lots of things happening here } }

Slide 15

Slide 15 text

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! } }

Slide 16

Slide 16 text

Practical tips! 2. Extracting responsabilities Single Responsability Principle Identify where you can move extra responsabilities found in your code into new classes/methods.

Slide 17

Slide 17 text

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.

Slide 18

Slide 18 text

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.

Slide 19

Slide 19 text

Thank you! :D @devdrops devdrops.me/about