• Keine Ergebnisse gefunden

Refactoring based on

N/A
N/A
Protected

Academic year: 2022

Aktie "Refactoring based on"

Copied!
28
0
0

Wird geladen.... (Jetzt Volltext ansehen)

Volltext

(1)

Refactoring

based onCode Completeby Steve McConnell

Philipp Trucks¨aß

June 17, 2015

(2)

Why

is refactoring necessary

All successful software gets changed.

—Fred Brooks

Myth

Software is written once and works flawlessly

Reality

Code evolves and changes dramatically during development

Solution

Refactor to adapt to changes and improve the overall quality

(3)

Why

is refactoring necessary

All successful software gets changed.

—Fred Brooks

Myth

Software is written once and works flawlessly

Reality

Code evolves and changes dramatically during development

Solution

Refactor to adapt to changes and improve the overall quality

(4)

Why

is refactoring necessary

All successful software gets changed.

—Fred Brooks

Myth

Software is written once and works flawlessly

Reality

Code evolves and changes dramatically during development

Solution

Refactor to adapt to changes and improve the overall quality

(5)

Why

is refactoring necessary

All successful software gets changed.

—Fred Brooks

Myth

Software is written once and works flawlessly

Reality

Code evolves and changes dramatically during development

Solution

Refactor to adapt to changes and improve the overall quality

(6)

Why

is refactoring necessary

Cardinal Rule of Software Evolution

Internal quality should improve with code evolution

Method

The tool to achieve this: Refactoring

[Refactoring is] a change made to the internal structure of the software to make it easier to understand and cheaper to modify without changing its observable behavior.

—Fowler(1999)

(7)

Why

is refactoring necessary

Cardinal Rule of Software Evolution

Internal quality should improve with code evolution

Method

The tool to achieve this: Refactoring

[Refactoring is] a change made to the internal structure of the software to make it easier to understand and cheaper to modify without changing its observable behavior.

—Fowler(1999)

(8)

Why

is refactoring necessary

Cardinal Rule of Software Evolution

Internal quality should improve with code evolution

Method

The tool to achieve this: Refactoring

[Refactoring is] a change made to the internal structure of the software to make it easier to understand and cheaper to modify without changing its observable behavior.

—Fowler(1999)

(9)

What

to refactor

Code Smells

Signs that code is bad or has degenerated through changes

(10)

What

to refactor

Code Smells

Signs that code is bad or has degenerated through changes

Duplicate Code Some C++ Code:

Vector3D normalizedA=a/sqrt(a.x*a.x+a.y*a.y+a.z*a.z);

...

Vector3D normalizedB=b/sqrt(b.x*b.x+b.y*b.y+b.z*b.z);

(11)

What

to refactor

Code Smells

Signs that code is bad or has degenerated through changes

Duplicate Code

Refactored C++ Code:

Vector3D normalizedA=a.normalized();

Vector3D normalizedB=b.normalized();

...

Vector3D Vector3D::normalized(){

return this/sqrt(x*x+y*y+z*z);

}

(12)

What

to refactor

Code Smells

Signs that code is bad or has degenerated through changes

Setup & Takedown Code Some C++ Code:

WithdrawalTransaction withdrawal;

withdrawal.SetAccountBalance(accountBalance);

withdrawal.SetWithdrawalAmount(withdrawalAmount);

ProcessWithdrawal(withdrawal);

accountBalance = withdrawal.GetAccountBalance();

withdrawalAmount = withdrawal.GetWithdrawalAmount();

(13)

What

to refactor

Code Smells

Signs that code is bad or has degenerated through changes

Setup & Takedown Code Refactored C++ Code:

ProcessWithdrawal(accountBalance,withdrawalAmount);

(14)

What

to refactor

Code Smells

Signs that code is bad or has degenerated through changes

Many Parameters Some C++ Code:

draw(box.getNumberVertices(),box.getVertices(), box.getIndices(),box.getVertexColors(), box.getModelMatrix());

(15)

What

to refactor

Code Smells

Signs that code is bad or has degenerated through changes

Many Parameters Refactored C++ Code:

box.draw();

(16)

How

to refactor

80/20 Rule

Do the 20% of possible refactorings that provide 80% of the benefit

When

After additions After fixes

Targets

High complexity Error-prone

(17)

How

to refactor

80/20 Rule

Do the 20% of possible refactorings that provide 80% of the benefit

When

After additions After fixes

Targets

High complexity Error-prone

(18)

How

to refactor

80/20 Rule

Do the 20% of possible refactorings that provide 80% of the benefit

When

After additions After fixes

Targets

High complexity Error-prone

(19)

How

to refactor safely

There is no code so big, twisted, or complex that maintenance can’t make it worse

—Gerald Weinberg

Refactoring Safety

Refactoring can cause more harm than good. Take precautions to prevent missteps

(20)

How

to refactor safely

There is no code so big, twisted, or complex that maintenance can’t make it worse

—Gerald Weinberg

Refactoring Safety

Refactoring can cause more harm than good. Take precautions to prevent missteps

(21)

How

to refactor safely

—Weinberg(1983)

(22)

How

to refactor safely

Backup

Small changes One at a time

”Parking lot” Retest & Review

Bad Times to Refactor

Refactoring does not affect a program’s behavior. Tweaking broken code to make it work is hacking.

(23)

How

to refactor safely

Backup Small changes

One at a time

”Parking lot” Retest & Review

Bad Times to Refactor

Refactoring does not affect a program’s behavior. Tweaking broken code to make it work is hacking.

(24)

How

to refactor safely

Backup Small changes One at a time

”Parking lot” Retest & Review

Bad Times to Refactor

Refactoring does not affect a program’s behavior. Tweaking broken code to make it work is hacking.

(25)

How

to refactor safely

Backup Small changes One at a time

”Parking lot”

Retest & Review

Bad Times to Refactor

Refactoring does not affect a program’s behavior. Tweaking broken code to make it work is hacking.

(26)

How

to refactor safely

Backup Small changes One at a time

”Parking lot”

Retest & Review

Bad Times to Refactor

Refactoring does not affect a program’s behavior. Tweaking broken code to make it work is hacking.

(27)

How

to refactor safely

Backup Small changes One at a time

”Parking lot”

Retest & Review

Bad Times to Refactor

Refactoring does not affect a program’s behavior. Tweaking broken code to make it work is hacking.

(28)

Conclusion

Refactoring during development is the best chance you’ll get to improve your program, to make all the changes you’ll wish you’d made the first time.

—Steve McConnell

Referenzen

ÄHNLICHE DOKUMENTE

Und dann ist da noch das Erbe, für welches sich vor allem Britney und Jeffrey interessieren, während die jüngeren, die stets hier mit dem Vater beisammen waren, keinen

The two different rhenium atoms are octahedrally coordinated by oxygen atoms with average Re-O distances of 193.1 and 187.7 pm for the six- and seven-valent rhenium

14 The estimate of 77 far-right and right-wing MEPs includes 11 western European far- right parties (the French National Front, the Italian Lega Nord, the Dutch Freedom Party,

Sensitivity of runoff t o climatic and other environmental changes is of particular interest t o water resource planners and decision makers because alterations in surface

A host of researchers in the last 15 years [8] have suggested another way to explain software architectures: Instead of pre- senting an architectural model as a

Unfrei- willig ironisch mutet dann bei der Skizze eines Verfahrens an, dass die Notwen- digkeit von Feldforschung betont wird, damit Forschende eine "Interpretations-

The fundamental theoretical framework constitutes of The autobiographical Pact by Philippe Lejeune and a theory of paratexts according to Gérard Genette.. In

– under Article 15 of the GDPR to request information from us about your personal data which we have processed. In particular you may request information about the purposes for