big code refactoring with agility

49
HOW DO YOU HANDLE BIG REFACTORING WITH AGILE METHODOLOGIES? Luca Merolla

Upload: luca-merolla

Post on 29-Nov-2014

233 views

Category:

Software


4 download

DESCRIPTION

How do you handle big code refactoring with Agile methodologies.

TRANSCRIPT

Page 1: Big code refactoring with agility

HOW DO YOU HANDLE BIG REFACTORING WITH AGILE

METHODOLOGIES?

Luca Merolla

Page 2: Big code refactoring with agility

What is code refactoring?

Page 3: Big code refactoring with agility

“Process to change the existing code without changing its external behavior.

Refactoring improves nonfunctional attributes of the software”

CODE REFACTORING

Page 4: Big code refactoring with agility

Why we need code refactoring?

Page 5: Big code refactoring with agility

Some arguments :

❏ Quality❏ Code Clean❏ Better Design❏ Right Thing

WHY REFACTORING?

Page 6: Big code refactoring with agility

Some arguments :

❏ Quality❏ Code Clean❏ Better Design❏ Right Thing

WHY REFACTORING?

Good Luck!

Page 7: Big code refactoring with agility

The only “sellable” reason to do refactoring is

WHY REFACTORING?

Page 8: Big code refactoring with agility

The only “sellable” reason to do refactoring is

WHY REFACTORING?

Page 9: Big code refactoring with agility

The only “sellable” reason to do refactoring is

WHY REFACTORING?

Save money Faster to deliver new functionalities

Page 10: Big code refactoring with agility

WHY REFACTORING?

Page 11: Big code refactoring with agility

When to do refactoring?

Page 12: Big code refactoring with agility

Ideally, when we identify:

❏ Code Smells: Things are not right

❏ WTFs: Code is not understandable

❏ It should be different: Product evolved

WHEN REFACTORING?

Page 13: Big code refactoring with agility

Don’t clean up everything.

It should be a constant and gradual improvement

WHEN REFACTORING?

Page 14: Big code refactoring with agility

Keep the balance between:refactoring vs new features

Don't refactor unless you think it will pay off later by allowing faster feature delivery

WHEN REFACTORING?

Page 15: Big code refactoring with agility

How to do refactoring?<

Page 16: Big code refactoring with agility

From the methodology point of view, my experience tells me that:

❏ Revolutionary design is evil

❏ Evolutionary design is good

HOW TO REFACTOR?

Page 17: Big code refactoring with agility

The most common approaches about refactoring are:

❏ “Big Bang”

❏ “Divide and Conquer”

❏ Planned refactoring

HOW TO REFACTOR?

Page 18: Big code refactoring with agility

The “Big Bang” approach:❏ Define a new structure for your code❏ Move the code to the new structure❏ Rebuild the puzzle❏ Make tests green again!

HOW TO REFACTOR?

Page 19: Big code refactoring with agility

The “Big Bang” approach:❏ Define a new structure for your code❏ Move the code to the new structure❏ Rebuild the puzzle❏ Make tests green again!

HOW TO REFACTOR?

❏ High risks!❏ Almost like rewrite from scratch

Page 20: Big code refactoring with agility

The “Divide and Conquer” approach:❏ Define a Vision❏ Break the application into pieces❏ Rebuild the puzzle❏ Make tests green again!

HOW TO REFACTOR?

Page 21: Big code refactoring with agility

The “Divide and Conquer” approach:❏ Define a Vision❏ Break the application into pieces❏ Rebuild the puzzle❏ Make tests green again!

HOW TO REFACTOR?

❏ Difficult estimation (like bugs)❏ Code could be “undeliverable” for

long period

Page 22: Big code refactoring with agility

Planned Refactoring also called as Stabilization periods:❏ No new features developed (Code freeze period)❏ Work without adding Value❏ Not an improvement for the customer

HOW TO REFACTOR?

Page 23: Big code refactoring with agility

Planned Refactoring also called as Stabilization periods:❏ No new features developed (Code freeze period)❏ Work without adding Value❏ Not an improvement for the customer

HOW TO REFACTOR?

❏ It’s a Methodology Smell!❏ No real “value” added to the

application

Page 24: Big code refactoring with agility

What a Good Team does is:❏ Define a Vision❏ Break it into smaller tasks❏ Refactoring all the time (part of regular work)❏ Responsible (Diligently keep the code clean)

HOW TO REFACTOR?

Page 25: Big code refactoring with agility

What a Good Team does is:❏ Define a Vision❏ Break it into smaller tasks❏ Refactoring all the time (part of regular work)❏ Responsible (Diligently keep the code clean)

HOW TO REFACTOR?

❏ Code can be delivered (often)❏ New features benefits from the

refactor (faster to develop)

Page 26: Big code refactoring with agility

How much refactoring should we be doing?

<

Page 27: Big code refactoring with agility

HOW MUCH REFACTOR?

We need to always consider the benefits of refactoring❏ Tolerance level (metrics could help)❏ Don’t clean up everything❏ Make refactoring part of our daily work❏ Multiple small improvements❏ Don’t refactor what is not likely to change❏ Consider the economic factor:

Cleaner code ⇨ Quicker and Cheaper changes

Page 28: Big code refactoring with agility

How can we obtain Refactoring with Agile

Methodologies?

Page 29: Big code refactoring with agility

Agile Methodologies focuses on continuous (or at least frequent) Value delivery.

The Value (for the customer) is realized when the product is shipped in production, not before.

AGILE & REFACTOR?

Page 30: Big code refactoring with agility

In order to use Agile Methodologies for big refactoring, we need to enforce some practices:

❏ Define and communicate the Vision

❏ Start with small tasks

❏ Iterate and Learn

AGILE & REFACTOR?

Page 31: Big code refactoring with agility

VISIONWhere to go MUST be clear.

Page 32: Big code refactoring with agility

Small Steps(Tasks) are

easier tohandle

Page 33: Big code refactoring with agility

Iterate and Learn throughout the process

Page 34: Big code refactoring with agility

Which Tools and Techniques should we use?

Page 35: Big code refactoring with agility

There are different tools and techniques that can help us to be more agile and deliver more often:

❏ Trunk Based Development

❏ Branch By Abstraction

❏ Feature Toggles/Flags

TOOLS & TECHNIQUES

Page 36: Big code refactoring with agility

What is Trunk Based Development?

Page 37: Big code refactoring with agility

Branches act as an Isolation from the “real world”.

TRUNK BASED DEV.

Page 38: Big code refactoring with agility

Multi branchescan make the codeundeployable for long periods

TRUNK BASED DEV.

● Undeployable● Deployable

Page 39: Big code refactoring with agility

What is really wrong with Branches?

❏ Branching is not bad, long lived branches are bad

❏ “Isolation” for prolonged periods of time is bad

❏ Multi-branches can lead to undeployable code

TRUNK BASED DEV.

Page 40: Big code refactoring with agility

How does TBD look like?

TRUNK BASED DEV.

Page 41: Big code refactoring with agility

What are the benefits of TBD?❏ Work on a single shared trunk❏ Always work against the latest code❏ Merge and integration pain is minimised

Note:❏ TBD does not prohibit branching

TRUNK BASED DEV.

Page 42: Big code refactoring with agility

TRUNK BASED DEV.

TRUNK209 210 211R D ?

TRUNK209 210 211R D ?

209.xFIX

R

209.1

F

D ?

R RELEASED

DEVELOPED NO COMMITS YET

F FIXTBD Optimistic Branching

Page 43: Big code refactoring with agility

TRUNK BASED DEV.

D ?

R RELEASED

DEVELOPED NO COMMITS YET

F FIXTBD Pessimistic Branching

TRUNK209 210 211R D

209.x

TRUNK209 210 211R D

209.xFIX

R

209.1

F

TRUNK209 210 211R D ?

209.x?

R

211.x?

R

211.x?

Page 44: Big code refactoring with agility

What is Branch By Abstraction?

Page 45: Big code refactoring with agility

BRANCH BY ABSTRACTION

1. Introduce an abstraction layer

2. Update all the code to rely on the abstraction

3. Make new implementation of the abstraction

4. Remove the old implementation

Page 46: Big code refactoring with agility

BRANCH BY ABSTRACTION

Page 47: Big code refactoring with agility

What are feature toggles/flags?

Page 48: Big code refactoring with agility

TOGGLES & FLAGS?

What are the advantages of using Feature Toggles:

❏ Decouples code deployment from feature❏ No need to rollback (disable the feature)❏ A/B testing❏ Deliver features to specific users only❏ Continuous delivery

Page 49: Big code refactoring with agility

THANK YOU!

@lucamerolla

Questions?