Refactoring Tools that People Actually Usepeople.engr.ncsu.edu/ermurph3/presentations/pjug.pdf ·...

36
Refactoring Tools that People Actually Use Emerson Murphy-Hill Adviser: Andrew P. Black

Transcript of Refactoring Tools that People Actually Usepeople.engr.ncsu.edu/ermurph3/presentations/pjug.pdf ·...

Page 1: Refactoring Tools that People Actually Usepeople.engr.ncsu.edu/ermurph3/presentations/pjug.pdf · Refactoring Tool (Under) Usage • Murphy and Colleagues’41 Programmers –The

Refactoring Tools that People

Actually Use

Emerson Murphy-Hill

Adviser: Andrew P. Black

Page 2: Refactoring Tools that People Actually Usepeople.engr.ncsu.edu/ermurph3/presentations/pjug.pdf · Refactoring Tool (Under) Usage • Murphy and Colleagues’41 Programmers –The

Outline

•What’s Refactoring / Refactoring Tools

•Java Refactoring Tools

•Why Refactoring Tools are Underused

•What’s W

rong with Typical Tools

•Industrial Im

provements

•Research Improvements

Page 3: Refactoring Tools that People Actually Usepeople.engr.ncsu.edu/ermurph3/presentations/pjug.pdf · Refactoring Tool (Under) Usage • Murphy and Colleagues’41 Programmers –The

What’s Refactoring?

Changing the structure of

code without changing the

way it behaves.

We do it because no one has

perfect foresight.

Page 4: Refactoring Tools that People Actually Usepeople.engr.ncsu.edu/ermurph3/presentations/pjug.pdf · Refactoring Tool (Under) Usage • Murphy and Colleagues’41 Programmers –The

What’s a Refactoring Tool?

A tool that automates how you used to refactor by

hand.

-transform

s code quickly

-transform

s code without introducing new errors

Definitely a refactoring tool:

–Eclipse’s

–IDEA’s

–Visual Studio’s

Maybe a refactoring tool:

–JUnit

–SED / AWK

–Jackpot

Page 5: Refactoring Tools that People Actually Usepeople.engr.ncsu.edu/ermurph3/presentations/pjug.pdf · Refactoring Tool (Under) Usage • Murphy and Colleagues’41 Programmers –The

A typical tool interaction

Page 6: Refactoring Tools that People Actually Usepeople.engr.ncsu.edu/ermurph3/presentations/pjug.pdf · Refactoring Tool (Under) Usage • Murphy and Colleagues’41 Programmers –The
Page 7: Refactoring Tools that People Actually Usepeople.engr.ncsu.edu/ermurph3/presentations/pjug.pdf · Refactoring Tool (Under) Usage • Murphy and Colleagues’41 Programmers –The
Page 8: Refactoring Tools that People Actually Usepeople.engr.ncsu.edu/ermurph3/presentations/pjug.pdf · Refactoring Tool (Under) Usage • Murphy and Colleagues’41 Programmers –The
Page 9: Refactoring Tools that People Actually Usepeople.engr.ncsu.edu/ermurph3/presentations/pjug.pdf · Refactoring Tool (Under) Usage • Murphy and Colleagues’41 Programmers –The
Page 10: Refactoring Tools that People Actually Usepeople.engr.ncsu.edu/ermurph3/presentations/pjug.pdf · Refactoring Tool (Under) Usage • Murphy and Colleagues’41 Programmers –The

Java Tools

Eclipse

JBuilder

Netbeans

IntilliJIDEA

RefactorIT

X-Develop / CodeGuide

X-Refactory*

JFactor*

JRefactory

*

Transmogrify*

JavaRefactor*

Page 11: Refactoring Tools that People Actually Usepeople.engr.ncsu.edu/ermurph3/presentations/pjug.pdf · Refactoring Tool (Under) Usage • Murphy and Colleagues’41 Programmers –The

Refactoring Tool (Under) Usage

•16 Object-Oriented students

–Only 2 used Refactoring Tools

•37 users of Eclipse in PSU lab

–2 used Refactoring Tools

•112 participants at Agile Open NW 2007:

–Of 72 programmers, 63 have tools

available some of the tim

e

–They claim

edan average of 68% use of

the tools

–Why not 100%?

Page 12: Refactoring Tools that People Actually Usepeople.engr.ncsu.edu/ermurph3/presentations/pjug.pdf · Refactoring Tool (Under) Usage • Murphy and Colleagues’41 Programmers –The

Refactoring Tool (Under) Usage

•Murphy and Colleagues’41 Programmers

–The only two refactoring tools used by

“most”programmers; Rename and Move

–Median number of refactoring hotkeys

used by programmers is 2; max. is 5

•Disagreements in refactoring needs vs. tool

usage

–According to Mantayla, programmers

overwhelm

ingly want to do Extract

Method

–But according to Murphy, programmers

overwhelm

ingly perform

Rename

Page 13: Refactoring Tools that People Actually Usepeople.engr.ncsu.edu/ermurph3/presentations/pjug.pdf · Refactoring Tool (Under) Usage • Murphy and Colleagues’41 Programmers –The

Data from Murphy and Colleagues

Page 14: Refactoring Tools that People Actually Usepeople.engr.ncsu.edu/ermurph3/presentations/pjug.pdf · Refactoring Tool (Under) Usage • Murphy and Colleagues’41 Programmers –The

Two kinds of Refactoring

Floss Refactoring

–Programmers refactoring

constantly to m

aintain

healthy software

–Refactoring is interleaved

with programming

Root Canal Refactoring

–Programmers refactoring

in clumps to fix unhealthy

software.

–Programming and

refactoring are distinct

activities.

0

20

40

60

80

100

131

61

91

121

151

181

Days

% of day spent refactoring

0

20

40

60

80

100

131

61

91

121

151

181

Days

% of day spent refactoring

Page 15: Refactoring Tools that People Actually Usepeople.engr.ncsu.edu/ermurph3/presentations/pjug.pdf · Refactoring Tool (Under) Usage • Murphy and Colleagues’41 Programmers –The

Floss vs. Root Canal

Floss Impromptu: refactor whenever you

think the code needs it

You know exactly what code you’re

going to refactor, because you’re

working on it

In Fowler (1999), Parnin+ (2006),

Hayashi+ (2006)

Root Canal

Planned: set aside time for refactoring

You don’t know what needs to be

refactored, but past experience

indicates future changes will be

difficult

In Van Emden+ (2002), Pizka(2004),

Kataoka+ (2002)

Page 16: Refactoring Tools that People Actually Usepeople.engr.ncsu.edu/ermurph3/presentations/pjug.pdf · Refactoring Tool (Under) Usage • Murphy and Colleagues’41 Programmers –The

Why you should Floss rather

than waiting for a Root Canal

Your dentist says so:

“Refactoring is som

ething you do all the time in little bursts. You

don’t decide to refactor, you refactor because you want to do

something else, and refactoring helps you do that other thing.”

Martin Fowler, Refactoring

“Avoid the temptation to stop work and refactor for several

weeks. E

ven the most disciplined team

inadvertently takes on

design debt, so eliminating debt needs to be an ongoing

activity. H

ave your team

get used to refactoring as part of their

daily work.”

James Shore, “Design Debt”

Page 17: Refactoring Tools that People Actually Usepeople.engr.ncsu.edu/ermurph3/presentations/pjug.pdf · Refactoring Tool (Under) Usage • Murphy and Colleagues’41 Programmers –The

Why you should Floss rather

than waiting for a Root Canal

Your friends are doing it!

Weißgerberand Diehl (M

SR 2006)

looked at JUnit, ArgoUMLand

JEdit:

Murphy et al. observed 41 Eclipse

developers:

•2672 repository commits

•At most 9 out of 283 iterations

were pure refactoring

“It turned out that in all three projects,

there are no days which only contain

refactorings. T

his is quite surprising, as

we would expect that at least in small

projects like JUnitthere are phases in a

project w

hen only refactorings have been

done to enhance the program structure.”

Page 18: Refactoring Tools that People Actually Usepeople.engr.ncsu.edu/ermurph3/presentations/pjug.pdf · Refactoring Tool (Under) Usage • Murphy and Colleagues’41 Programmers –The

Why you should Floss rather

than waiting for a Root Canal

You are becoming Agile!

Continuous design and continuous

refactoring are key practices for Agile

programmers

“We keep the code simple at all times. This minimizes the

investment in excess fram

ework and support code. W

e retain the necessary flexibility through refactoring.”

Jeffries, Anderson & Hendrickson

Extreme Programming Installed, 2000.

Page 19: Refactoring Tools that People Actually Usepeople.engr.ncsu.edu/ermurph3/presentations/pjug.pdf · Refactoring Tool (Under) Usage • Murphy and Colleagues’41 Programmers –The

Root Canal: Ineffective

Pizka(2004) describes a root canal

refactoring over 5 m

onths;

concludes that the tim

e was

mostly wasted.

Bourquin

and Keller (2007)

describe a root canal refactoring

over 7 m

onths; showed few

objectively positive results, but

did note a dramatic increase in

duplicated code.

Page 20: Refactoring Tools that People Actually Usepeople.engr.ncsu.edu/ermurph3/presentations/pjug.pdf · Refactoring Tool (Under) Usage • Murphy and Colleagues’41 Programmers –The

Why the Distinction Matters

I claim

that a tool

built for root canal

refactoring will not

be very usable for

floss refactoring,

and to a lesser

degree, vice versa.

Van Emden’s+ smell

detector (2002)

Hayashi’s smell

detector (2006)

Root Canal Tool

Floss Tool

Page 21: Refactoring Tools that People Actually Usepeople.engr.ncsu.edu/ermurph3/presentations/pjug.pdf · Refactoring Tool (Under) Usage • Murphy and Colleagues’41 Programmers –The

44 responses. The tool isn’t flexible enough—it doesn’t

do quite what I want.

26 responses.I never really learned how to use that

particular refactoring tool / I don’t know what tool to

use.

24 responses. I can do it faster by hand.

13 responses. I don’t trust the tool to be correct.

7 responses. The tool will probably m

utilate m

y code.

2 responses. M

y code base is so large that the

refactoring tool takes too long.

Other:Habit. M

enu too big. Avoid GUIs—Keybindings

only! Prefer to be aware of the changes m

yself. Hard

to trust the refactored code, even if it applies. Usually

I do m

ultisteprefactoring—tools do one step at a tim

e.

Agile Open Northwest 2007: When performing a

refactoring where a tool is available but you choose not

to use it, what usually prevents you?

Page 22: Refactoring Tools that People Actually Usepeople.engr.ncsu.edu/ermurph3/presentations/pjug.pdf · Refactoring Tool (Under) Usage • Murphy and Colleagues’41 Programmers –The

So What’s Really Wrong with

Refactoring Tools?

Tools don’t always fit with the

way programmers want to

refactor…

…so programmers snub the

tools and refactor by hand.

Page 23: Refactoring Tools that People Actually Usepeople.engr.ncsu.edu/ermurph3/presentations/pjug.pdf · Refactoring Tool (Under) Usage • Murphy and Colleagues’41 Programmers –The
Page 24: Refactoring Tools that People Actually Usepeople.engr.ncsu.edu/ermurph3/presentations/pjug.pdf · Refactoring Tool (Under) Usage • Murphy and Colleagues’41 Programmers –The

Industrial Improvements

(Code Identification)

•Automated smell detection

–Eclipse’s Test and Perform

ance Tools

–IntelliJ’scode inspections

Page 25: Refactoring Tools that People Actually Usepeople.engr.ncsu.edu/ermurph3/presentations/pjug.pdf · Refactoring Tool (Under) Usage • Murphy and Colleagues’41 Programmers –The

Research Improvements

(Code Identification)

JCosmo

Hayashi and Colleagues

Page 26: Refactoring Tools that People Actually Usepeople.engr.ncsu.edu/ermurph3/presentations/pjug.pdf · Refactoring Tool (Under) Usage • Murphy and Colleagues’41 Programmers –The

Industrial Improvements

(Selection)

Page 27: Refactoring Tools that People Actually Usepeople.engr.ncsu.edu/ermurph3/presentations/pjug.pdf · Refactoring Tool (Under) Usage • Murphy and Colleagues’41 Programmers –The

Research Improvements

(Selection)

Box View

Page 28: Refactoring Tools that People Actually Usepeople.engr.ncsu.edu/ermurph3/presentations/pjug.pdf · Refactoring Tool (Under) Usage • Murphy and Colleagues’41 Programmers –The

Research Improvements

(Selection)

Selection Assist

Page 29: Refactoring Tools that People Actually Usepeople.engr.ncsu.edu/ermurph3/presentations/pjug.pdf · Refactoring Tool (Under) Usage • Murphy and Colleagues’41 Programmers –The

Research Improvements

(Selection)

Refactoring Cues

Page 30: Refactoring Tools that People Actually Usepeople.engr.ncsu.edu/ermurph3/presentations/pjug.pdf · Refactoring Tool (Under) Usage • Murphy and Colleagues’41 Programmers –The

Research Improvements

(Activation)

Refactoring Marking Menus

Page 31: Refactoring Tools that People Actually Usepeople.engr.ncsu.edu/ermurph3/presentations/pjug.pdf · Refactoring Tool (Under) Usage • Murphy and Colleagues’41 Programmers –The

Industrial Improvements

(Configuration)

X-Develop in-line extract method

Page 32: Refactoring Tools that People Actually Usepeople.engr.ncsu.edu/ermurph3/presentations/pjug.pdf · Refactoring Tool (Under) Usage • Murphy and Colleagues’41 Programmers –The

Research Improvements

(Configuration)

Refactoring Cues

Page 33: Refactoring Tools that People Actually Usepeople.engr.ncsu.edu/ermurph3/presentations/pjug.pdf · Refactoring Tool (Under) Usage • Murphy and Colleagues’41 Programmers –The

Research Improvements

(Understanding Errors)

Refactoring Annotations

Page 34: Refactoring Tools that People Actually Usepeople.engr.ncsu.edu/ermurph3/presentations/pjug.pdf · Refactoring Tool (Under) Usage • Murphy and Colleagues’41 Programmers –The

Summary

Using Refactoring tools is a

good thing

But people don’t use

refactoring tools m

uch

because they don’t fit with

how programmers work

So research and industry is

attempting to m

ake better

refactoring tools!

Page 35: Refactoring Tools that People Actually Usepeople.engr.ncsu.edu/ermurph3/presentations/pjug.pdf · Refactoring Tool (Under) Usage • Murphy and Colleagues’41 Programmers –The

References

M. Fowler, K. Beck, J. Brant, W

. Opdyke, and D. Roberts, Refactoring: Im

proving the Design of

Existing Code: Addison-W

esley Professional, 1999.

J. Shore. “Design Debt.”Software Profitability Newsletter. February 2004.

G. Murphy, M. Kersten, and L. Findlater, "How Are Java Software Developers Using the Eclipse

IDE?," IEEE Software, 2006.

E. Van Emden and L. Moonen, "Java Quality Assurance by Detecting Code Smells," presented at

WCRE '02: Proceedings of the Ninth W

orking Conference on ReverseEngineering, 2002.

S. Hayashi, M. Saeki, and M. Kurihara, "Supporting Refactoring Activities Using Histories of Program

Modification," IEICE Transactions on Inform

ation and Systems, 2006.

Y. Kataoka, T. Im

ai, H. Andou, and T. Fukaya, "A quantitative evaluation of maintainability

enhancement by refactoring," presented at Software Maintenance, 2002. Proceedings.

International Conference on, 2002.

M. Pizka. “Straightening Spaghetti Code with Refactoring.”In Proc. of the Int. Conf. on Software

Engineering Research and Practice -SERP, pages 846-852, Las Vegas, NV, June 2004.

CSREA Press.

F. Bourquin

and R. Keller, “High-impact refactoring based on architecture violations,”Proceedings of

CSMR 2007.

M, Mäntylä, and C. Lassenius, "Drivers for software refactoring decisions," presented at ISESE '06:

Proceedings of the 2006 ACM/IEEE international symposium on International symposium on

empirical software engineering, 2006.

P. Weißgerber, and S. Diehl, "Are refactorings less error-prone than other changes?," presented at

MSR '06:Proceedings of the 2006 international workshop on Miningsoftware repositories,

2006.

X-Develop. Omnicore

Software. 2007.

Page 36: Refactoring Tools that People Actually Usepeople.engr.ncsu.edu/ermurph3/presentations/pjug.pdf · Refactoring Tool (Under) Usage • Murphy and Colleagues’41 Programmers –The

Endnotes

http://cs.pdx.edu/~

emerson

[email protected]

Parts of this presentation

contained slides from previous

presentations.