refactoring legacy code - entwicklertag · @docondev / @wearecto2 refactoring change the...

47
@DocOnDev / @WeAreCTO2 Refactoring legacy code

Upload: others

Post on 28-Jun-2020

8 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Refactoring legacy code - Entwicklertag · @DocOnDev / @WeAreCTO2 refactoring Change the implementation without Changing the Behavior • Improves nonfunctional attributes of the

@DocOnDev / @WeAreCTO2

Refactoring legacy code

Page 2: Refactoring legacy code - Entwicklertag · @DocOnDev / @WeAreCTO2 refactoring Change the implementation without Changing the Behavior • Improves nonfunctional attributes of the

@DocOnDev / @WeAreCTO2

Doc Norton .Co-Founder + CEO .

[email protected]

Page 3: Refactoring legacy code - Entwicklertag · @DocOnDev / @WeAreCTO2 refactoring Change the implementation without Changing the Behavior • Improves nonfunctional attributes of the

@DocOnDev / @WeAreCTO2

What is refactoring?

Page 4: Refactoring legacy code - Entwicklertag · @DocOnDev / @WeAreCTO2 refactoring Change the implementation without Changing the Behavior • Improves nonfunctional attributes of the

@DocOnDev / @WeAreCTO2

refactoringChange the implementation without Changing the Behavior

• Improves nonfunctional attributes of the software ✴ Improved code readability ✴ Reduced complexity ✴ Improved source-code maintainability ✴ More expressive internal architecture or object model ✴ Improved extensibility

• May also resolve hidden, dormant, or undiscovered bugs

Page 5: Refactoring legacy code - Entwicklertag · @DocOnDev / @WeAreCTO2 refactoring Change the implementation without Changing the Behavior • Improves nonfunctional attributes of the

@DocOnDev / @WeAreCTO2

By continuously improving the design of code, we make it easier and easier to work with. This is in sharp contrast to what typically happens: little refactoring and a great deal of attention paid to expediently adding new features. If you get into the hygienic habit of refactoring continuously, you'll find that it is easier to extend and maintain code.

– Joshua Kerievsky

Refactoring to Patterns

Page 6: Refactoring legacy code - Entwicklertag · @DocOnDev / @WeAreCTO2 refactoring Change the implementation without Changing the Behavior • Improves nonfunctional attributes of the

@DocOnDev / @WeAreCTO2

What isLegacy Code?

Page 7: Refactoring legacy code - Entwicklertag · @DocOnDev / @WeAreCTO2 refactoring Change the implementation without Changing the Behavior • Improves nonfunctional attributes of the

@DocOnDev / @WeAreCTO2

Legacy CodeSo many definitions…

• Difficult to change • Difficult to understand • Get late feedback when you do change it • Not properly / sufficiently tested • Would rather replace it than work with it • Written in out-dated tools/technologies

Page 8: Refactoring legacy code - Entwicklertag · @DocOnDev / @WeAreCTO2 refactoring Change the implementation without Changing the Behavior • Improves nonfunctional attributes of the

@DocOnDev / @WeAreCTO2

Legacy CodeSo many definitions…

• Difficult to change• Difficult to understand • Get late feedback when you do change it• Not properly / sufficiently tested• Would rather replace it than work with it • Written in out-dated tools/technologies

Page 9: Refactoring legacy code - Entwicklertag · @DocOnDev / @WeAreCTO2 refactoring Change the implementation without Changing the Behavior • Improves nonfunctional attributes of the

@DocOnDev / @WeAreCTO2

Legacy CodeSo many definitions…

• Difficult to change• BECAUSE IT IS Difficult to understand

• Get late feedback when you do change it• BECAUSE IT IS Not properly / sufficiently tested

Page 10: Refactoring legacy code - Entwicklertag · @DocOnDev / @WeAreCTO2 refactoring Change the implementation without Changing the Behavior • Improves nonfunctional attributes of the

@DocOnDev / @WeAreCTO2

trivia game

https://github.com/DocOnDev/trivia

Page 11: Refactoring legacy code - Entwicklertag · @DocOnDev / @WeAreCTO2 refactoring Change the implementation without Changing the Behavior • Improves nonfunctional attributes of the

@DocOnDev / @WeAreCTO2

trivia gamehttps://github.com/DocOnDev/trivia

Allow for games with 3, 4, 5, or 6 categories. Pop, Science, Sports, Rock, History, Food

A wrong answer is a fine of 1 gold coin. If player cannot pay fine, send them to penalty box.

Page 12: Refactoring legacy code - Entwicklertag · @DocOnDev / @WeAreCTO2 refactoring Change the implementation without Changing the Behavior • Improves nonfunctional attributes of the

@DocOnDev / @WeAreCTO2

Just CodeAllow for games with 3, 4, 5, or 6 categories.

Pop, Science, Sports, Rock, History, Food

A wrong answer is a fine of 1 gold coin. If player cannot pay fine, send them to penalty box.

Page 13: Refactoring legacy code - Entwicklertag · @DocOnDev / @WeAreCTO2 refactoring Change the implementation without Changing the Behavior • Improves nonfunctional attributes of the

@WeAreCTO2 / @DocOnDev

Huddle Time

Page 14: Refactoring legacy code - Entwicklertag · @DocOnDev / @WeAreCTO2 refactoring Change the implementation without Changing the Behavior • Improves nonfunctional attributes of the

@DocOnDev / @WeAreCTO2

clean firstAllow for games with 3, 4, 5, or 6 categories.

Pop, Science, Sports, Rock, History, Food

A wrong answer is a fine of 1 gold coin. If player cannot pay fine, send them to penalty box.

Page 15: Refactoring legacy code - Entwicklertag · @DocOnDev / @WeAreCTO2 refactoring Change the implementation without Changing the Behavior • Improves nonfunctional attributes of the

@DocOnDev / @WeAreCTO2

Refactored with no tests

Page 16: Refactoring legacy code - Entwicklertag · @DocOnDev / @WeAreCTO2 refactoring Change the implementation without Changing the Behavior • Improves nonfunctional attributes of the

@WeAreCTO2 / @DocOnDev

Huddle Time

Page 17: Refactoring legacy code - Entwicklertag · @DocOnDev / @WeAreCTO2 refactoring Change the implementation without Changing the Behavior • Improves nonfunctional attributes of the
Page 18: Refactoring legacy code - Entwicklertag · @DocOnDev / @WeAreCTO2 refactoring Change the implementation without Changing the Behavior • Improves nonfunctional attributes of the

@DocOnDev / @WeAreCTO2

Golden Master

Page 19: Refactoring legacy code - Entwicklertag · @DocOnDev / @WeAreCTO2 refactoring Change the implementation without Changing the Behavior • Improves nonfunctional attributes of the

@DocOnDev / @WeAreCTO2

Golden Master

http://texttest.sourceforge.net/

http://texttest.readthedocs.io/

Page 20: Refactoring legacy code - Entwicklertag · @DocOnDev / @WeAreCTO2 refactoring Change the implementation without Changing the Behavior • Improves nonfunctional attributes of the

@WeAreCTO2 / @DocOnDev

Huddle Time

Page 21: Refactoring legacy code - Entwicklertag · @DocOnDev / @WeAreCTO2 refactoring Change the implementation without Changing the Behavior • Improves nonfunctional attributes of the

@DocOnDev / @WeAreCTO2

break

Page 22: Refactoring legacy code - Entwicklertag · @DocOnDev / @WeAreCTO2 refactoring Change the implementation without Changing the Behavior • Improves nonfunctional attributes of the

@DocOnDev / @WeAreCTO2

Code Profiling

Page 23: Refactoring legacy code - Entwicklertag · @DocOnDev / @WeAreCTO2 refactoring Change the implementation without Changing the Behavior • Improves nonfunctional attributes of the

@DocOnDev / @WeAreCTO2

Code characterization

Page 24: Refactoring legacy code - Entwicklertag · @DocOnDev / @WeAreCTO2 refactoring Change the implementation without Changing the Behavior • Improves nonfunctional attributes of the

@DocOnDev / @WeAreCTO2

Test NamesCharacter_

Characterization, not verified - should pass. Character_Invalid_

Reviewed and is NOT wanted - should pass.

Page 25: Refactoring legacy code - Entwicklertag · @DocOnDev / @WeAreCTO2 refactoring Change the implementation without Changing the Behavior • Improves nonfunctional attributes of the

@DocOnDev / @WeAreCTO2

character tests

Page 26: Refactoring legacy code - Entwicklertag · @DocOnDev / @WeAreCTO2 refactoring Change the implementation without Changing the Behavior • Improves nonfunctional attributes of the

@WeAreCTO2 / @DocOnDev

Huddle Time

Page 27: Refactoring legacy code - Entwicklertag · @DocOnDev / @WeAreCTO2 refactoring Change the implementation without Changing the Behavior • Improves nonfunctional attributes of the

@DocOnDev / @WeAreCTO2

Mikado Method

Page 28: Refactoring legacy code - Entwicklertag · @DocOnDev / @WeAreCTO2 refactoring Change the implementation without Changing the Behavior • Improves nonfunctional attributes of the

@DocOnDev / @WeAreCTO2

Why Mikado?• Incremental Approach

• Lower Risk

• Keeps Code Base Stable for Duration of Large Refactoring

• Change Map Improves Communication

• Goal Focused

Page 29: Refactoring legacy code - Entwicklertag · @DocOnDev / @WeAreCTO2 refactoring Change the implementation without Changing the Behavior • Improves nonfunctional attributes of the

@DocOnDev / @WeAreCTO2

Page 30: Refactoring legacy code - Entwicklertag · @DocOnDev / @WeAreCTO2 refactoring Change the implementation without Changing the Behavior • Improves nonfunctional attributes of the

@DocOnDev / @WeAreCTO2

Main Goal

Page 31: Refactoring legacy code - Entwicklertag · @DocOnDev / @WeAreCTO2 refactoring Change the implementation without Changing the Behavior • Improves nonfunctional attributes of the

@DocOnDev / @WeAreCTO2

Main Goal

Page 32: Refactoring legacy code - Entwicklertag · @DocOnDev / @WeAreCTO2 refactoring Change the implementation without Changing the Behavior • Improves nonfunctional attributes of the

@DocOnDev / @WeAreCTO2

Main Goal

Page 33: Refactoring legacy code - Entwicklertag · @DocOnDev / @WeAreCTO2 refactoring Change the implementation without Changing the Behavior • Improves nonfunctional attributes of the

@DocOnDev / @WeAreCTO2

Main Goal

Page 34: Refactoring legacy code - Entwicklertag · @DocOnDev / @WeAreCTO2 refactoring Change the implementation without Changing the Behavior • Improves nonfunctional attributes of the

@DocOnDev / @WeAreCTO2

Main Goal

Pre-Requisite One

Pre-Requisite Two

Page 35: Refactoring legacy code - Entwicklertag · @DocOnDev / @WeAreCTO2 refactoring Change the implementation without Changing the Behavior • Improves nonfunctional attributes of the

@DocOnDev / @WeAreCTO2

Main Goal

Pre-Requisite One

Pre-Requisite Two

Page 36: Refactoring legacy code - Entwicklertag · @DocOnDev / @WeAreCTO2 refactoring Change the implementation without Changing the Behavior • Improves nonfunctional attributes of the

@DocOnDev / @WeAreCTO2

Main Goal

Pre-Requisite One

Pre-Requisite Two

Standard Class

Aged Class

Legend Class

Page 37: Refactoring legacy code - Entwicklertag · @DocOnDev / @WeAreCTO2 refactoring Change the implementation without Changing the Behavior • Improves nonfunctional attributes of the

@DocOnDev / @WeAreCTO2

Main Goal

Pre-Requisite One

Pre-Requisite Two

Standard Class

Aged Class

Legend Class

Page 38: Refactoring legacy code - Entwicklertag · @DocOnDev / @WeAreCTO2 refactoring Change the implementation without Changing the Behavior • Improves nonfunctional attributes of the

@DocOnDev / @WeAreCTO2

Main Goal

Pre-Requisite One

Pre-Requisite Two

Standard Class

Aged Class

Legend Class

Page 39: Refactoring legacy code - Entwicklertag · @DocOnDev / @WeAreCTO2 refactoring Change the implementation without Changing the Behavior • Improves nonfunctional attributes of the

@DocOnDev / @WeAreCTO2

Main Goal

Pre-Requisite One

Pre-Requisite Two

Standard Class

Aged Class

Legend Class

Page 40: Refactoring legacy code - Entwicklertag · @DocOnDev / @WeAreCTO2 refactoring Change the implementation without Changing the Behavior • Improves nonfunctional attributes of the

@DocOnDev / @WeAreCTO2

Main Goal

Pre-Requisite One

Pre-Requisite Two

Standard Class

Aged Class

Legend Class

Page 41: Refactoring legacy code - Entwicklertag · @DocOnDev / @WeAreCTO2 refactoring Change the implementation without Changing the Behavior • Improves nonfunctional attributes of the

@DocOnDev / @WeAreCTO2

break

Page 42: Refactoring legacy code - Entwicklertag · @DocOnDev / @WeAreCTO2 refactoring Change the implementation without Changing the Behavior • Improves nonfunctional attributes of the

@DocOnDev / @WeAreCTO2

mikado methodAllow for games with 3, 4, 5, or 6

categories. Pop, Science, Sports, Rock, History, Food

A wrong answer is a fine of 1 gold coin. If player cannot pay fine, send them to

penalty box.

Page 43: Refactoring legacy code - Entwicklertag · @DocOnDev / @WeAreCTO2 refactoring Change the implementation without Changing the Behavior • Improves nonfunctional attributes of the

@WeAreCTO2 / @DocOnDev

Huddle Time

Page 44: Refactoring legacy code - Entwicklertag · @DocOnDev / @WeAreCTO2 refactoring Change the implementation without Changing the Behavior • Improves nonfunctional attributes of the

@DocOnDev / @WeAreCTO2

mikado methodAllow for games with 3, 4, 5, or 6

categories. Pop, Science, Sports, Rock, History, Food

A wrong answer is a fine of 1 gold coin. If player cannot pay fine, send them to

penalty box.

Page 45: Refactoring legacy code - Entwicklertag · @DocOnDev / @WeAreCTO2 refactoring Change the implementation without Changing the Behavior • Improves nonfunctional attributes of the

@WeAreCTO2 / @DocOnDev

Huddle Time

Page 46: Refactoring legacy code - Entwicklertag · @DocOnDev / @WeAreCTO2 refactoring Change the implementation without Changing the Behavior • Improves nonfunctional attributes of the

@DocOnDev / @WeAreCTO2

Thank You!!

Refactoring legacy code