Refactoring, 2nd Ed. A love story - JUG Saxony Day 2020 · Like the original, this edition explains...

137
Refactoring, 2nd Ed. A love story Michael Hunger

Transcript of Refactoring, 2nd Ed. A love story - JUG Saxony Day 2020 · Like the original, this edition explains...

Page 1: Refactoring, 2nd Ed. A love story - JUG Saxony Day 2020 · Like the original, this edition explains what refactoring is; why you should refactor; how to recognize code that needs

Refactoring, 2nd Ed.A love story

Michael Hunger

Page 2: Refactoring, 2nd Ed. A love story - JUG Saxony Day 2020 · Like the original, this edition explains what refactoring is; why you should refactor; how to recognize code that needs

Michael Hunger

Open Sourcerer

Neo4j

@mesirii

Page 3: Refactoring, 2nd Ed. A love story - JUG Saxony Day 2020 · Like the original, this edition explains what refactoring is; why you should refactor; how to recognize code that needs

It crashed at 940!

Page 4: Refactoring, 2nd Ed. A love story - JUG Saxony Day 2020 · Like the original, this edition explains what refactoring is; why you should refactor; how to recognize code that needs

I know what you're here for!

Covers By: dev.to/rly

Page 5: Refactoring, 2nd Ed. A love story - JUG Saxony Day 2020 · Like the original, this edition explains what refactoring is; why you should refactor; how to recognize code that needs

Which Refactoring do you like most?

Extract Method

Delete Unused Code

Ok, you won :)

Page 6: Refactoring, 2nd Ed. A love story - JUG Saxony Day 2020 · Like the original, this edition explains what refactoring is; why you should refactor; how to recognize code that needs
Page 7: Refactoring, 2nd Ed. A love story - JUG Saxony Day 2020 · Like the original, this edition explains what refactoring is; why you should refactor; how to recognize code that needs

List of SoundbitesStolen from the 1st Ed.

Page 8: Refactoring, 2nd Ed. A love story - JUG Saxony Day 2020 · Like the original, this edition explains what refactoring is; why you should refactor; how to recognize code that needs

Questions?!

1. Who has seen the Refactoring book?

2. Who has read it?

3. Who thought that it's just common sense?

4. Who refactors code on a daily basis?

5. Who mentors new developers?

Page 9: Refactoring, 2nd Ed. A love story - JUG Saxony Day 2020 · Like the original, this edition explains what refactoring is; why you should refactor; how to recognize code that needs

“Any fool can write code that a computer can understand. Good programmers write code that

humans can understand.”

M. Fowler (1999)

Page 10: Refactoring, 2nd Ed. A love story - JUG Saxony Day 2020 · Like the original, this edition explains what refactoring is; why you should refactor; how to recognize code that needs
Page 11: Refactoring, 2nd Ed. A love story - JUG Saxony Day 2020 · Like the original, this edition explains what refactoring is; why you should refactor; how to recognize code that needs
Page 12: Refactoring, 2nd Ed. A love story - JUG Saxony Day 2020 · Like the original, this edition explains what refactoring is; why you should refactor; how to recognize code that needs

My Refactoring Story

Started 18 years ago

Page 13: Refactoring, 2nd Ed. A love story - JUG Saxony Day 2020 · Like the original, this edition explains what refactoring is; why you should refactor; how to recognize code that needs

Martin Fowler

Foreword by Erich GammaContributions by Kent Beck,William Opdyke, Don Roberts

28. Juni 1999

Page 14: Refactoring, 2nd Ed. A love story - JUG Saxony Day 2020 · Like the original, this edition explains what refactoring is; why you should refactor; how to recognize code that needs
Page 15: Refactoring, 2nd Ed. A love story - JUG Saxony Day 2020 · Like the original, this edition explains what refactoring is; why you should refactor; how to recognize code that needs

"A must-read"

Page 16: Refactoring, 2nd Ed. A love story - JUG Saxony Day 2020 · Like the original, this edition explains what refactoring is; why you should refactor; how to recognize code that needs

I really liked that book too!

Page 17: Refactoring, 2nd Ed. A love story - JUG Saxony Day 2020 · Like the original, this edition explains what refactoring is; why you should refactor; how to recognize code that needs

As did others ...

… e.g. authors!

Page 18: Refactoring, 2nd Ed. A love story - JUG Saxony Day 2020 · Like the original, this edition explains what refactoring is; why you should refactor; how to recognize code that needs
Page 19: Refactoring, 2nd Ed. A love story - JUG Saxony Day 2020 · Like the original, this edition explains what refactoring is; why you should refactor; how to recognize code that needs
Page 20: Refactoring, 2nd Ed. A love story - JUG Saxony Day 2020 · Like the original, this edition explains what refactoring is; why you should refactor; how to recognize code that needs
Page 21: Refactoring, 2nd Ed. A love story - JUG Saxony Day 2020 · Like the original, this edition explains what refactoring is; why you should refactor; how to recognize code that needs
Page 22: Refactoring, 2nd Ed. A love story - JUG Saxony Day 2020 · Like the original, this edition explains what refactoring is; why you should refactor; how to recognize code that needs

My Student thesis atTU Dresden

Page 23: Refactoring, 2nd Ed. A love story - JUG Saxony Day 2020 · Like the original, this edition explains what refactoring is; why you should refactor; how to recognize code that needs

Student thesis atTU Dresden

""

bit.ly/refactoring-thesis

Page 24: Refactoring, 2nd Ed. A love story - JUG Saxony Day 2020 · Like the original, this edition explains what refactoring is; why you should refactor; how to recognize code that needs
Page 25: Refactoring, 2nd Ed. A love story - JUG Saxony Day 2020 · Like the original, this edition explains what refactoring is; why you should refactor; how to recognize code that needs

Refactoring Tools for Java

in 2000!

Page 26: Refactoring, 2nd Ed. A love story - JUG Saxony Day 2020 · Like the original, this edition explains what refactoring is; why you should refactor; how to recognize code that needs
Page 27: Refactoring, 2nd Ed. A love story - JUG Saxony Day 2020 · Like the original, this edition explains what refactoring is; why you should refactor; how to recognize code that needs
Page 28: Refactoring, 2nd Ed. A love story - JUG Saxony Day 2020 · Like the original, this edition explains what refactoring is; why you should refactor; how to recognize code that needs
Page 29: Refactoring, 2nd Ed. A love story - JUG Saxony Day 2020 · Like the original, this edition explains what refactoring is; why you should refactor; how to recognize code that needs

Fast Forward 18 years

Page 30: Refactoring, 2nd Ed. A love story - JUG Saxony Day 2020 · Like the original, this edition explains what refactoring is; why you should refactor; how to recognize code that needs

A nice surprise

Page 31: Refactoring, 2nd Ed. A love story - JUG Saxony Day 2020 · Like the original, this edition explains what refactoring is; why you should refactor; how to recognize code that needs

Michael,

I'm Martin Fowler's editor at Addison-Wesley. We are working on a revision of his Refactoring book. Martin suggested that I reach out to you about reviewing the manuscript. He was very impressed with feedback you've provided on other projects.

Thanks,

Greg

-- Gregory DoenchExecutive EditorPearson Technology Group

Page 32: Refactoring, 2nd Ed. A love story - JUG Saxony Day 2020 · Like the original, this edition explains what refactoring is; why you should refactor; how to recognize code that needs

Several Weeks and 435 Pages later

Page 33: Refactoring, 2nd Ed. A love story - JUG Saxony Day 2020 · Like the original, this edition explains what refactoring is; why you should refactor; how to recognize code that needs

28. November 2018

Latest Memo: Most people will be disappointed by the second edition

martinfowler.com/articles/refactoring-2nd-ed.html

Page 34: Refactoring, 2nd Ed. A love story - JUG Saxony Day 2020 · Like the original, this edition explains what refactoring is; why you should refactor; how to recognize code that needs

Like the original, this edition explains what refactoring is; why you should refactor; how to recognize code that needs refactoring; and how to actually do it successfully, no matter what language you use.

● Understand the process and general principles of refactoring● Quickly apply useful refactorings to make a program easier to

comprehend and change● Recognize “bad smells” in code that signal opportunities to refactor● Explore the refactorings, each with explanations, motivation, mechanics,

and simple examples● Build solid tests for your refactorings● Recognize tradeoffs and obstacles to refactoring

Page 35: Refactoring, 2nd Ed. A love story - JUG Saxony Day 2020 · Like the original, this edition explains what refactoring is; why you should refactor; how to recognize code that needs

Why a new book?

Page 36: Refactoring, 2nd Ed. A love story - JUG Saxony Day 2020 · Like the original, this edition explains what refactoring is; why you should refactor; how to recognize code that needs

Refactoring is as important as ever

Educate a new generation!

Page 37: Refactoring, 2nd Ed. A love story - JUG Saxony Day 2020 · Like the original, this edition explains what refactoring is; why you should refactor; how to recognize code that needs

What changed?

martinfowler.com/articles/refactoring-2nd-changes.html

Page 38: Refactoring, 2nd Ed. A love story - JUG Saxony Day 2020 · Like the original, this edition explains what refactoring is; why you should refactor; how to recognize code that needs

No one knows anymorewhat video rentals are!

Page 39: Refactoring, 2nd Ed. A love story - JUG Saxony Day 2020 · Like the original, this edition explains what refactoring is; why you should refactor; how to recognize code that needs

Javascript !?!?!

Page 40: Refactoring, 2nd Ed. A love story - JUG Saxony Day 2020 · Like the original, this edition explains what refactoring is; why you should refactor; how to recognize code that needs

Javascript !?!?!

Page 41: Refactoring, 2nd Ed. A love story - JUG Saxony Day 2020 · Like the original, this edition explains what refactoring is; why you should refactor; how to recognize code that needs

Book Structure (Basically the same)

1. Opening Narrative ExampleTheatre Invoicing

2. Principles3. Code Smells4. Testing5. Catalogue

a. most important ones firstb. other refactorings

6. Dropped tangential topics and big refactorings

Page 42: Refactoring, 2nd Ed. A love story - JUG Saxony Day 2020 · Like the original, this edition explains what refactoring is; why you should refactor; how to recognize code that needs

Refactoring Changes

"Split Temporary Variable" => "Split Variable"

"Extract Method" => "Extract Function"

Add Parameter, Remove Parameter, Rename Method

=> Change Function Declaration

Page 43: Refactoring, 2nd Ed. A love story - JUG Saxony Day 2020 · Like the original, this edition explains what refactoring is; why you should refactor; how to recognize code that needs

Extract Function

Inline Function

Extract Variable

Inline Variable

Rename Variable

Encapsulate Variable

Highlighted: Most important Refactorings

Migrate Function Declaration

Change Function Declaration

Introduce Parameter Object

Combine Functions into Class

Combine Functions into Transform

Page 44: Refactoring, 2nd Ed. A love story - JUG Saxony Day 2020 · Like the original, this edition explains what refactoring is; why you should refactor; how to recognize code that needs
Page 45: Refactoring, 2nd Ed. A love story - JUG Saxony Day 2020 · Like the original, this edition explains what refactoring is; why you should refactor; how to recognize code that needs

New Refactorings

All about Functions andPipelines

Page 46: Refactoring, 2nd Ed. A love story - JUG Saxony Day 2020 · Like the original, this edition explains what refactoring is; why you should refactor; how to recognize code that needs

Combine Functions into Class

Combine Functions into Transform

Move Statements into Function

Move Statements to Callers

Remove Dead Code

Rename Field

Rename Variable

Replace Command with Function

New Refactorings

Replace Derived Variable with Query

Replace Inline Code with Function Call

Replace Loop with Pipeline

Replace Query with Parameter

Replace Subclass with Delegate

Return Modified Value

Split Phase

Page 47: Refactoring, 2nd Ed. A love story - JUG Saxony Day 2020 · Like the original, this edition explains what refactoring is; why you should refactor; how to recognize code that needs
Page 48: Refactoring, 2nd Ed. A love story - JUG Saxony Day 2020 · Like the original, this edition explains what refactoring is; why you should refactor; how to recognize code that needs
Page 49: Refactoring, 2nd Ed. A love story - JUG Saxony Day 2020 · Like the original, this edition explains what refactoring is; why you should refactor; how to recognize code that needs
Page 50: Refactoring, 2nd Ed. A love story - JUG Saxony Day 2020 · Like the original, this edition explains what refactoring is; why you should refactor; how to recognize code that needs
Page 51: Refactoring, 2nd Ed. A love story - JUG Saxony Day 2020 · Like the original, this edition explains what refactoring is; why you should refactor; how to recognize code that needs

Web-BookAvailableon Safari

Page 52: Refactoring, 2nd Ed. A love story - JUG Saxony Day 2020 · Like the original, this edition explains what refactoring is; why you should refactor; how to recognize code that needs

My take on the new book

Page 53: Refactoring, 2nd Ed. A love story - JUG Saxony Day 2020 · Like the original, this edition explains what refactoring is; why you should refactor; how to recognize code that needs

Back to the essence

Page 54: Refactoring, 2nd Ed. A love story - JUG Saxony Day 2020 · Like the original, this edition explains what refactoring is; why you should refactor; how to recognize code that needs

Student thesis atTU Dresden

""

Page 55: Refactoring, 2nd Ed. A love story - JUG Saxony Day 2020 · Like the original, this edition explains what refactoring is; why you should refactor; how to recognize code that needs

Topics

1. What, When, How

2. Benefits

3. Costs / Issues

4. History

5. Catalogue

6. Tools

7. Example

Page 56: Refactoring, 2nd Ed. A love story - JUG Saxony Day 2020 · Like the original, this edition explains what refactoring is; why you should refactor; how to recognize code that needs

What?

Page 57: Refactoring, 2nd Ed. A love story - JUG Saxony Day 2020 · Like the original, this edition explains what refactoring is; why you should refactor; how to recognize code that needs

Refactoring (noun): a change made to the internal structure of software to make it

easier to understand and cheaper to modify

without changing the observable behavior of the software.

Page 58: Refactoring, 2nd Ed. A love story - JUG Saxony Day 2020 · Like the original, this edition explains what refactoring is; why you should refactor; how to recognize code that needs

Refactor (verb): to restructure software by applying a series of refactorings

without changing the observable behavior of the software.

Page 59: Refactoring, 2nd Ed. A love story - JUG Saxony Day 2020 · Like the original, this edition explains what refactoring is; why you should refactor; how to recognize code that needs

When?

Page 60: Refactoring, 2nd Ed. A love story - JUG Saxony Day 2020 · Like the original, this edition explains what refactoring is; why you should refactor; how to recognize code that needs

Code Smells!

If it stinks, change it- Grandma Beck

Page 61: Refactoring, 2nd Ed. A love story - JUG Saxony Day 2020 · Like the original, this edition explains what refactoring is; why you should refactor; how to recognize code that needs

Mysterious NameDuplicated CodeLong FunctionLong Parameter ListGlobal DataMutable DataDivergent ChangeShotgun SurgeryFeature EnvyData ClumpsPrimitive ObsessionRepeated Switches

Code SmellsLazy ElementSpeculative GeneralityTemporary FieldMessage ChainsMiddle ManInsider TradingLarge ClassAlternative Classes with Different InterfacesData ClassRefused BequestCommentsLoops

Page 62: Refactoring, 2nd Ed. A love story - JUG Saxony Day 2020 · Like the original, this edition explains what refactoring is; why you should refactor; how to recognize code that needs

Adding features is hard?

Page 63: Refactoring, 2nd Ed. A love story - JUG Saxony Day 2020 · Like the original, this edition explains what refactoring is; why you should refactor; how to recognize code that needs

WorkingEffectivelywithLegacyCode

Michael Feathers

Page 64: Refactoring, 2nd Ed. A love story - JUG Saxony Day 2020 · Like the original, this edition explains what refactoring is; why you should refactor; how to recognize code that needs

Full of complexity and bugs

Page 65: Refactoring, 2nd Ed. A love story - JUG Saxony Day 2020 · Like the original, this edition explains what refactoring is; why you should refactor; how to recognize code that needs

Code as a Crime Scene

Software DesignX-Rays

Adam Tornhill

Page 66: Refactoring, 2nd Ed. A love story - JUG Saxony Day 2020 · Like the original, this edition explains what refactoring is; why you should refactor; how to recognize code that needs

Code is not habitable

Page 67: Refactoring, 2nd Ed. A love story - JUG Saxony Day 2020 · Like the original, this edition explains what refactoring is; why you should refactor; how to recognize code that needs

TimelessWay ofBuilding

Christopher Alexander

Page 68: Refactoring, 2nd Ed. A love story - JUG Saxony Day 2020 · Like the original, this edition explains what refactoring is; why you should refactor; how to recognize code that needs

How?

Page 69: Refactoring, 2nd Ed. A love story - JUG Saxony Day 2020 · Like the original, this edition explains what refactoring is; why you should refactor; how to recognize code that needs

Refactoring is as much about safety

testing, small steps, commit

as it is about code changes.

Page 70: Refactoring, 2nd Ed. A love story - JUG Saxony Day 2020 · Like the original, this edition explains what refactoring is; why you should refactor; how to recognize code that needs

Refactoring changes the programs in small steps. If you make a mistake, it is

easy to find the bug.

Page 71: Refactoring, 2nd Ed. A love story - JUG Saxony Day 2020 · Like the original, this edition explains what refactoring is; why you should refactor; how to recognize code that needs

Two Hats

Page 72: Refactoring, 2nd Ed. A love story - JUG Saxony Day 2020 · Like the original, this edition explains what refactoring is; why you should refactor; how to recognize code that needs

martinfowler.com/articles/preparatory-refactoring-example.html

Page 73: Refactoring, 2nd Ed. A love story - JUG Saxony Day 2020 · Like the original, this edition explains what refactoring is; why you should refactor; how to recognize code that needs
Page 74: Refactoring, 2nd Ed. A love story - JUG Saxony Day 2020 · Like the original, this edition explains what refactoring is; why you should refactor; how to recognize code that needs

Add Function

blog.gdinwiddie.com/2012/12/26/tdd-hat/

1. Red

2. Green

3. Refactor

Page 75: Refactoring, 2nd Ed. A love story - JUG Saxony Day 2020 · Like the original, this edition explains what refactoring is; why you should refactor; how to recognize code that needs

1. Refactor

2. Green

3. Commit

Refactor

Page 76: Refactoring, 2nd Ed. A love story - JUG Saxony Day 2020 · Like the original, this edition explains what refactoring is; why you should refactor; how to recognize code that needs

Before you start refactoring, check that you have a solid suite of tests. These

tests must be self-checking.

Martin Fowler

Page 77: Refactoring, 2nd Ed. A love story - JUG Saxony Day 2020 · Like the original, this edition explains what refactoring is; why you should refactor; how to recognize code that needs

Tests, are your safety net

Listen to the flight attendentthis one time

Page 78: Refactoring, 2nd Ed. A love story - JUG Saxony Day 2020 · Like the original, this edition explains what refactoring is; why you should refactor; how to recognize code that needs

Make sure all tests are fully automatic and that they check their own results.

Martin Fowler

Page 79: Refactoring, 2nd Ed. A love story - JUG Saxony Day 2020 · Like the original, this edition explains what refactoring is; why you should refactor; how to recognize code that needs

Fast Tests

Page 80: Refactoring, 2nd Ed. A love story - JUG Saxony Day 2020 · Like the original, this edition explains what refactoring is; why you should refactor; how to recognize code that needs

Test Ordering

R.I.P. JunitMax

Page 81: Refactoring, 2nd Ed. A love story - JUG Saxony Day 2020 · Like the original, this edition explains what refactoring is; why you should refactor; how to recognize code that needs

Many small commits

Can squash later

Page 82: Refactoring, 2nd Ed. A love story - JUG Saxony Day 2020 · Like the original, this edition explains what refactoring is; why you should refactor; how to recognize code that needs

Run your tests frequently. Localize tests whenever you compile - every test at

least every day.

Martin Fowler

Page 83: Refactoring, 2nd Ed. A love story - JUG Saxony Day 2020 · Like the original, this edition explains what refactoring is; why you should refactor; how to recognize code that needs

A suite of tests is a powerful bug detector

that decapitates the time it takes to find bugs.

Martin Fowler

Page 84: Refactoring, 2nd Ed. A love story - JUG Saxony Day 2020 · Like the original, this edition explains what refactoring is; why you should refactor; how to recognize code that needs

Unit tests are like the second pair of eyes of a pair programmer.

Kent Beck

Page 85: Refactoring, 2nd Ed. A love story - JUG Saxony Day 2020 · Like the original, this edition explains what refactoring is; why you should refactor; how to recognize code that needs

When you get a bug report, start by writing a unit test that exposes the bug.

Martin Fowler

Page 86: Refactoring, 2nd Ed. A love story - JUG Saxony Day 2020 · Like the original, this edition explains what refactoring is; why you should refactor; how to recognize code that needs

Think of the boundary conditions under which things might go wrong and

concentrate your tests there.

Martin Fowler

Page 87: Refactoring, 2nd Ed. A love story - JUG Saxony Day 2020 · Like the original, this edition explains what refactoring is; why you should refactor; how to recognize code that needs

Don’t forget to test that exceptions are raised when things are expected to go

wrong.

Martin Fowler

Page 88: Refactoring, 2nd Ed. A love story - JUG Saxony Day 2020 · Like the original, this edition explains what refactoring is; why you should refactor; how to recognize code that needs

Kinds of Refactoring

Page 89: Refactoring, 2nd Ed. A love story - JUG Saxony Day 2020 · Like the original, this edition explains what refactoring is; why you should refactor; how to recognize code that needs

Quick Fixes Refactoring Rewrite

Page 90: Refactoring, 2nd Ed. A love story - JUG Saxony Day 2020 · Like the original, this edition explains what refactoring is; why you should refactor; how to recognize code that needs

Continous Clean-Up

Page 91: Refactoring, 2nd Ed. A love story - JUG Saxony Day 2020 · Like the original, this edition explains what refactoring is; why you should refactor; how to recognize code that needs

Continous Clean-Up● Rename● Replace comment with function● Make intent clear● Intention in your IDE● Not about polishing

Page 92: Refactoring, 2nd Ed. A love story - JUG Saxony Day 2020 · Like the original, this edition explains what refactoring is; why you should refactor; how to recognize code that needs

DRY

Three strikes and you refactor.

Page 93: Refactoring, 2nd Ed. A love story - JUG Saxony Day 2020 · Like the original, this edition explains what refactoring is; why you should refactor; how to recognize code that needs

Boy Scout Rule

Leave it better than you found it

Page 94: Refactoring, 2nd Ed. A love story - JUG Saxony Day 2020 · Like the original, this edition explains what refactoring is; why you should refactor; how to recognize code that needs

Use >> Reuse

Reuse within your module not across.

Page 95: Refactoring, 2nd Ed. A love story - JUG Saxony Day 2020 · Like the original, this edition explains what refactoring is; why you should refactor; how to recognize code that needs

Planned Refactoring

Page 96: Refactoring, 2nd Ed. A love story - JUG Saxony Day 2020 · Like the original, this edition explains what refactoring is; why you should refactor; how to recognize code that needs

● Before adding a feature● Addressing technical debt● Improve testability (seams)● Improve understandability● For learning about a

new code-base

Planned Refactoring

Page 97: Refactoring, 2nd Ed. A love story - JUG Saxony Day 2020 · Like the original, this edition explains what refactoring is; why you should refactor; how to recognize code that needs

(BIG) Refactoring /Rewrite

Page 98: Refactoring, 2nd Ed. A love story - JUG Saxony Day 2020 · Like the original, this edition explains what refactoring is; why you should refactor; how to recognize code that needs

Sunken Cost Fallacy

Page 99: Refactoring, 2nd Ed. A love story - JUG Saxony Day 2020 · Like the original, this edition explains what refactoring is; why you should refactor; how to recognize code that needs

Deliberate Discovery

Dan North

Page 100: Refactoring, 2nd Ed. A love story - JUG Saxony Day 2020 · Like the original, this edition explains what refactoring is; why you should refactor; how to recognize code that needs

Benefits

Page 101: Refactoring, 2nd Ed. A love story - JUG Saxony Day 2020 · Like the original, this edition explains what refactoring is; why you should refactor; how to recognize code that needs

Forces you to test

Page 102: Refactoring, 2nd Ed. A love story - JUG Saxony Day 2020 · Like the original, this edition explains what refactoring is; why you should refactor; how to recognize code that needs

Don’t let the fear that testing can’t catch all bugs stop you from writing the tests

that will catch most bugs.

Martin Fowler

Page 103: Refactoring, 2nd Ed. A love story - JUG Saxony Day 2020 · Like the original, this edition explains what refactoring is; why you should refactor; how to recognize code that needs

It is better to write and run incomplete tests than not to run complete tests.

Martin Fowler

Page 104: Refactoring, 2nd Ed. A love story - JUG Saxony Day 2020 · Like the original, this edition explains what refactoring is; why you should refactor; how to recognize code that needs

Code Ownership

Modify your code ownership policies to smooth refactoring.

Page 105: Refactoring, 2nd Ed. A love story - JUG Saxony Day 2020 · Like the original, this edition explains what refactoring is; why you should refactor; how to recognize code that needs

Fights Code Rot and Decay

Page 106: Refactoring, 2nd Ed. A love story - JUG Saxony Day 2020 · Like the original, this edition explains what refactoring is; why you should refactor; how to recognize code that needs

Improves Understanding

Page 107: Refactoring, 2nd Ed. A love story - JUG Saxony Day 2020 · Like the original, this edition explains what refactoring is; why you should refactor; how to recognize code that needs

Costs

Page 108: Refactoring, 2nd Ed. A love story - JUG Saxony Day 2020 · Like the original, this edition explains what refactoring is; why you should refactor; how to recognize code that needs

APIs

Don’t publish interfaces prematurely. Downstream dependencies.

Page 109: Refactoring, 2nd Ed. A love story - JUG Saxony Day 2020 · Like the original, this edition explains what refactoring is; why you should refactor; how to recognize code that needs

Side Effects

e.g. Performance

Page 110: Refactoring, 2nd Ed. A love story - JUG Saxony Day 2020 · Like the original, this edition explains what refactoring is; why you should refactor; how to recognize code that needs

How do I tell my Boss?

Page 111: Refactoring, 2nd Ed. A love story - JUG Saxony Day 2020 · Like the original, this edition explains what refactoring is; why you should refactor; how to recognize code that needs

Time invested

Page 112: Refactoring, 2nd Ed. A love story - JUG Saxony Day 2020 · Like the original, this edition explains what refactoring is; why you should refactor; how to recognize code that needs

Refactoring & Design

Page 113: Refactoring, 2nd Ed. A love story - JUG Saxony Day 2020 · Like the original, this edition explains what refactoring is; why you should refactor; how to recognize code that needs

Refactoring & Design

Page 114: Refactoring, 2nd Ed. A love story - JUG Saxony Day 2020 · Like the original, this edition explains what refactoring is; why you should refactor; how to recognize code that needs

Refactoring Catalogue

Page 115: Refactoring, 2nd Ed. A love story - JUG Saxony Day 2020 · Like the original, this edition explains what refactoring is; why you should refactor; how to recognize code that needs

Refactoring Catalogue (my favorites)Move Function

Split Loop

Replace Loop with Pipeline (Stream)

Replace Magic Literal

Replace Derived Variable with Query

Replace Typecode with Subclass

Replace Superclass with Delegate

Replace Control Flag with Break (Return)

Introduce Special Case (Null Object)

Replace Nested Conditionals with Guad

Clauses

Extract Function

Extract Variable

Push Statements into Function

Push members up

Extract Interface / Superclass

Migrate Function Declaration

Combine Functions into Transform

Encapsulate Collection

Replace Temp with Query

Separate Query from Modifier

Parameterize Function

Page 116: Refactoring, 2nd Ed. A love story - JUG Saxony Day 2020 · Like the original, this edition explains what refactoring is; why you should refactor; how to recognize code that needs
Page 117: Refactoring, 2nd Ed. A love story - JUG Saxony Day 2020 · Like the original, this edition explains what refactoring is; why you should refactor; how to recognize code that needs
Page 118: Refactoring, 2nd Ed. A love story - JUG Saxony Day 2020 · Like the original, this edition explains what refactoring is; why you should refactor; how to recognize code that needs
Page 119: Refactoring, 2nd Ed. A love story - JUG Saxony Day 2020 · Like the original, this edition explains what refactoring is; why you should refactor; how to recognize code that needs
Page 120: Refactoring, 2nd Ed. A love story - JUG Saxony Day 2020 · Like the original, this edition explains what refactoring is; why you should refactor; how to recognize code that needs
Page 121: Refactoring, 2nd Ed. A love story - JUG Saxony Day 2020 · Like the original, this edition explains what refactoring is; why you should refactor; how to recognize code that needs

Tools

Page 122: Refactoring, 2nd Ed. A love story - JUG Saxony Day 2020 · Like the original, this edition explains what refactoring is; why you should refactor; how to recognize code that needs

Tools today make Refactoring a Joy

Page 123: Refactoring, 2nd Ed. A love story - JUG Saxony Day 2020 · Like the original, this edition explains what refactoring is; why you should refactor; how to recognize code that needs

Smart Understanding of code & intent

Useful suggestions

Intentions & Quick fixes

Page 124: Refactoring, 2nd Ed. A love story - JUG Saxony Day 2020 · Like the original, this edition explains what refactoring is; why you should refactor; how to recognize code that needs

Use and Learn the Shortcuts

Pragmatic Programmer

Page 125: Refactoring, 2nd Ed. A love story - JUG Saxony Day 2020 · Like the original, this edition explains what refactoring is; why you should refactor; how to recognize code that needs

Intentions & Quick Fixes

Page 126: Refactoring, 2nd Ed. A love story - JUG Saxony Day 2020 · Like the original, this edition explains what refactoring is; why you should refactor; how to recognize code that needs

IntelliJ & all Jetbrains IDEs

Page 127: Refactoring, 2nd Ed. A love story - JUG Saxony Day 2020 · Like the original, this edition explains what refactoring is; why you should refactor; how to recognize code that needs

HelpProductivityGuide

Page 128: Refactoring, 2nd Ed. A love story - JUG Saxony Day 2020 · Like the original, this edition explains what refactoring is; why you should refactor; how to recognize code that needs

What did youNOT use yet

Page 129: Refactoring, 2nd Ed. A love story - JUG Saxony Day 2020 · Like the original, this edition explains what refactoring is; why you should refactor; how to recognize code that needs

Eclipse

Page 130: Refactoring, 2nd Ed. A love story - JUG Saxony Day 2020 · Like the original, this edition explains what refactoring is; why you should refactor; how to recognize code that needs

EclipseLanguageServer

Page 131: Refactoring, 2nd Ed. A love story - JUG Saxony Day 2020 · Like the original, this edition explains what refactoring is; why you should refactor; how to recognize code that needs

Netbeans

Page 132: Refactoring, 2nd Ed. A love story - JUG Saxony Day 2020 · Like the original, this edition explains what refactoring is; why you should refactor; how to recognize code that needs

VS Code & Visual Studio

Page 133: Refactoring, 2nd Ed. A love story - JUG Saxony Day 2020 · Like the original, this edition explains what refactoring is; why you should refactor; how to recognize code that needs
Page 134: Refactoring, 2nd Ed. A love story - JUG Saxony Day 2020 · Like the original, this edition explains what refactoring is; why you should refactor; how to recognize code that needs

Refactoring & Patterns

Page 135: Refactoring, 2nd Ed. A love story - JUG Saxony Day 2020 · Like the original, this edition explains what refactoring is; why you should refactor; how to recognize code that needs

Refactoring & Patterns● patterns encapsulate good solutions in a context

● represent roles of components

● avoid code-smells

● they can be the goal of a design improvment

● refactorings are steps to those designs

Page 136: Refactoring, 2nd Ed. A love story - JUG Saxony Day 2020 · Like the original, this edition explains what refactoring is; why you should refactor; how to recognize code that needs

Resources

dzone.com/refcardz/refactoring-patterns refactoring.guru

martinfowler.com/tags/refactoring.html refactoring.com/catalog

Page 137: Refactoring, 2nd Ed. A love story - JUG Saxony Day 2020 · Like the original, this edition explains what refactoring is; why you should refactor; how to recognize code that needs

Ask your questions?

Thank you for your time!

Follow @mesirii