28
1 How We Refactor, and How We Know It Emerson Murphy-Hill Portland State (now UBC) Chris Parnin Georgia Tech Andrew Black Portland State Thanks to Ki-Yung Ahn, Barry Anderson, Lee Beckman, Brett Cannon, Tim Chevalier, Sara Dadizadeh, Sam Davis, Danny Dig, Rafael Fernandez-Moctezuma, Markus Keller, Rashawn Knapp, Andy Ko, Seonah Lee, Peng Li, Chuan-kai Lin, Ralph London, Gail Murphy, Immad Naseer, Fini Nitschke, Jinwgen Owen Ou, Sarah Rastakar, Claudia Rocha, Suresh Singh, Petcharat Viriyakattiyaporn, and Bryant York for assistance, as well as the National Science Foundation for partially funding this research under CCF-0520346.

How We Refactor, and How We Know It

Embed Size (px)

DESCRIPTION

How We Refactor, and How We Know It. Emerson Murphy-Hill Portland State (now UBC) Chris Parnin Georgia Tech Andrew Black Portland State. - PowerPoint PPT Presentation

Citation preview

Page 1: How We  Refactor, and  How We Know It

1

How We Refactor, and How We Know It

Emerson Murphy-Hill Portland State

(now UBC)

Chris Parnin Georgia Tech

Andrew Black Portland State

Thanks to Ki-Yung Ahn, Barry Anderson, Lee Beckman, Brett Cannon, Tim Chevalier, Sara Dadizadeh, Sam Davis, Danny Dig, Rafael Fernandez-Moctezuma, Markus Keller, Rashawn Knapp, Andy Ko, Seonah Lee, Peng Li, Chuan-kai Lin, Ralph London, Gail Murphy, Immad Naseer, Fini Nitschke, Jinwgen Owen Ou, Sarah Rastakar, Claudia Rocha, Suresh Singh, Petcharat Viriyakattiyaporn, and Bryant York for assistance, as well as the National Science Foundation for partially funding this research under CCF-0520346.

Page 2: How We  Refactor, and  How We Know It

2

Page 3: How We  Refactor, and  How We Know It

Introduction to Refactoring

3

class Foo{

}

class Bar{ int a; public Bar(int anA){ this.a = anA; }}

class Bar{

}

class Bar{ int a; private Bar(int anA){ this.a = anA; } public static Bar create(int anA){ return new Bar(anA); }}

Page 4: How We  Refactor, and  How We Know It

Introduction to Refactoring

4

class Foo{

}

class Bar{ int a; public Bar(int anA){ this.a = anA; }}

class Bar{

}

class Bar{ int a; private Bar(int anA){ this.a = anA; } public static Bar create(int anA){ return new Bar(anA); }}

Correctness

&

Speed

Page 5: How We  Refactor, and  How We Know It

Introduction to Refactoring

5

R R

class Foo{

}

class Bar{ int a; public Bar(int anA){ this.a = anA; }}

class Bar{

}

class Bar{ int a; private Bar(int anA){ this.a = anA; } public static Bar create(int anA){ return new Bar(anA); }}

Time

Page 6: How We  Refactor, and  How We Know It

6

3 Research Questions

6

R RRRRRR

R RRRRRR RRRRR

Do Programmers Refactor Often?

R RRRRR R RRRRR

root-canal refactoringversus

versus

versus

Do Programmers Usually Floss Refactor?

Do Programmers Use Refactoring Tools Often?

Page 7: How We  Refactor, and  How We Know It

7

Do Programmers Usually Floss Refactor?

Page 8: How We  Refactor, and  How We Know It

8

Do Programmers Usually Floss Refactor?

If floss refactoring is more common, then tools should support that strategy

8

Importance

A tool user interfaceoptimized for “flossings”

A tool user interfaceoptimized for “root canals”

Page 9: How We  Refactor, and  How We Know It

9

Do Programmers Usually Floss Refactor?

Floss refactoring better by prescription:In almost all cases, I'm opposed to setting aside time for refactoring. In my view refactoring is not an activity you set aside time to do. Refactoring is something you do all the time in little bursts. – Martin Fowler

Avoid the temptation to stop work and refactor for several weeks… Have your team get used to refactoring as part of their daily work. – James Shore

Case studies describe root canal refactorings:Pizka [2004]Bourqun and Keller [2007]

9

What We Already Know

Page 10: How We  Refactor, and  How We Know It

10

Do Programmers Usually Floss Refactor?

10

What We Did and Results

Floss (Mixed)

Refactoring

Root Canal (Pure)

Refactoring0 01 1

Repeated Process For 17 Randomly Selected Commits

To a Large Open-Source Project

6 11

65% of Commits were Floss Refactoring

R

RRR

R

R

RRR

R

R

RRR

R

R

RRR

R

R

RRR

R

R

R

R

R

R

R

RRR

R

R

R

RRRR

RRR

RRR

RRRRR

RRR

RRR

R R

RRR

R

R

RRR

R

R

RRR

R

R

RRR

R

R

RRR

R

R

RR

R

R

R

RRR

R

R

RRR

R

R

RRR

R

R

RRR

R

R

R

R

R

RRR

R

R

RRR

R

R

RRR

R

R

R

R

RRR

R

R

RRR

R

R

RR

R

R

R

RRR

R

R

RR

R

R

R

R

RRR

R

R

RR

R

R

R

R

RRR

R

R

R

R

R

91% of refactorings occurred during floss

refactoring

Page 11: How We  Refactor, and  How We Know It

11

Do Programmers Usually Floss Refactor?

Page 12: How We  Refactor, and  How We Know It

12

3 Research Questions

12

R RRRRRR

R RRRRRR RRRRR

R RRRRR R RRRRRversus

versus

versus

Do Programmers Usually Floss Refactor?

Do Programmers Refactor Often?

Do Programmers Use Refactoring Tools Often?

Yes

Page 13: How We  Refactor, and  How We Know It

13

Do Programmers Refactor Often?

Page 14: How We  Refactor, and  How We Know It

14

Do Programmers Refactor Often?

If programmers refactor often

then refactoring research matters

then refactoring tools may significantly speed up and improve the correctness of programming

14

Importance

Page 15: How We  Refactor, and  How We Know It

15

Do Programmers Refactor Often?

15

What We Already Know

According to Xing and Stroulia [2006]:

Refactoring is frequent, in the Eclipse project

But their use of an automated detection tool means the results are only a rough estimate

Page 16: How We  Refactor, and  How We Know It

16

Do Programmers Refactor Often?What We Did + Results

16

R RRRRR

Feb.1Dev. 1

Feb.1Dev. 2

Feb.3Dev. 4

Feb.4Dev. 3

Feb. 8Dev. 3

Feb.11Dev. 4

…Refactoring Tool Logs in 2006/2007

Week 1 Week 2

4 Developers on

the Same Open

Source Project

But this is tool-based refactoring.If many refactorings are done without tools,

then refactoring is even more frequent.

2006

2007

Page 17: How We  Refactor, and  How We Know It

17

Do Programmers Refactor Often?

Page 18: How We  Refactor, and  How We Know It

18

3 Research Questions

18

R RRRRRR

R RRRRRR RRRRR

R RRRRR

versus

versus

Do Programmers Usually Floss Refactor?

Do Programmers Refactor Often?

Do Programmers Use Refactoring Tools Often?

Yes

Yes

Page 19: How We  Refactor, and  How We Know It

19

Do Programmers Use Refactoring Tools Often?

Page 20: How We  Refactor, and  How We Know It

20

Do Programmers Use Refactoring Tools Often?

If programmers underuse refactoring tools:

then there’s potential for tool improvements

then programmers are needlessly introducing errors or refactoring slowly

20

Importance

Page 21: How We  Refactor, and  How We Know It

21

Do Programmers Use Refactoring Tools Often?

From our previous work

2 in 16 programming students used them (and even then, 20% and 60% of the time)

Agile developers (in 2007, n=112) estimate that they use them only 68% of the time

6 of 42 people who used Eclipse on networked PSU computers used refactoring tools

21

What We Already Know

Page 22: How We  Refactor, and  How We Know It

22

Do Programmers Use Refactoring Tools Often?What We Did

22

Dev. 1 CommitFeb. 1, 15:23

R

Feb. 1, 15:11Dev. 1

Dev. 1 CommitFeb. 1, 15:01

R

Feb.1, 16:00Dev. 2

R

Jan. 29, 08:40Dev. 2

R

Feb.1, 15:59Dev. 1

R

Feb.1, 12:23Dev. 1

R ?=

Page 23: How We  Refactor, and  How We Know It

23

Do Programmers Use Refactoring Tools Often?What We Did

23

Page 24: How We  Refactor, and  How We Know It

24

24

R RRRR R RRRR

R RRRR R RRRR R RRRR

R RRRR R RRRR R RRRR

R RRRR R RRRR R RRRR

R RRRR R RRRR R RRRR

R RRRR R RRRR R RRRR

R RRRR R RRRR R RRRR

R RRRR R RRRR R RRRR

R RRRR R RRRR R RRR

R RRRR R RRRR R RRR R

R

Do Programmers Use Refactoring Tools Often?The Results

89% of refactorings were done without a tool

… among toolsmiths.

Page 25: How We  Refactor, and  How We Know It

25

Do Programmers Use Refactoring Tools Often?

Page 26: How We  Refactor, and  How We Know It

26

3 Research Questions

26

R RRRRR

R RRRRRR RRRRR

R RRRRR

versus

Do Programmers Usually Floss Refactor?

Do Programmers Refactor Often?

Do Programmers Use Refactoring Tools Often?

Yes

Yes

No

3 Research Findings

Page 27: How We  Refactor, and  How We Know It

27

6 More Findings

The kind of refactoring performed with tools differs from the kind performed manually

Toolsmiths use a wider array of refactoring tools than tool users

About 40% of tool-initiated refactorings occur in batches

About 90% of tool-initiated refactorings do not require configuration of the tool

Messages written by programmers in version histories are unreliable indicators of refactoring

About 40% of refactorings will not be detected by most mining tools that detect refactoring from version histories

27

Page 28: How We  Refactor, and  How We Know It

28

28

Conclusion

The more ways we look at how people refactor, the more confidence we have that we understand how people refactor

In studying refactoring from new perspectives, our findings have confirmed – and refuted – previous knowledge about how people refactor