Upload
sailqu
View
95
Download
0
Embed Size (px)
Citation preview
An Empirical Study of Goto in C Code from GitHub Repositories
Mei Nagappan, Romain Robbes, Yasutaka Kamei, Eric Tanter, Shane McIntosh, Audris Mockus, Ahmed E. Hassan
Go-to statement considered
harmful (1968)
A Case against the GO TO Statement
(1968)
Do Practitioners care?
Do Practitioners care?
https://xkcd.com/292/
Do Practitioners care?
Do Practitioners care?
Do Practitioners care?
Impact of Article on Research Community
Impact of Article on Research Community
Impact of Article on Research Community
Impact of Article
Koenig: Dijkstra provides strong logical evidence for why goto statements can introduce problems in software.
Well informed and often well argued opinions
Shift from opinion to facts
Our Goal: Empirically Examine the use of goto
Shift from opinion to facts
Example
Label
Goto Statement
PRELIMINARY ANALYSIS
Do developers use goto statements in their source code?
Experiment
11,627 Projects Goto Miner
11,627 Projects Goto Miner 3,093
Projects
Despite the popularity of Dijkstra’s case against goto…
11,627 Projects Goto Miner 3,093
Projects
246,657 out of the 2,150,387 files (11.47%)
Extent of use of goto statements by Developers is non-trivial
Two Research Questions
Two Research Questions
RQ1: What are goto statements used for?
Two Research Questions
RQ1: What are goto statements used for?
RQ2: Do developers remove/modify goto statements?
Qualitative Analysis
246,669 C files
384files
Properties and Purposesof Goto
IterativeTagging
Sample Selection
Basic Bean Counting
Num of Goto Statements per Function
Num of Goto Labels per Function
Not many goto statements per function
Num of Goto Statements per Function
Num of Goto Labels per Function
Not many goto statements per function
Very few lines of code in label blocksMedian = 4 LOC
Properties
Context
Why did Dijkstra think goto statements would have ‘disastrous effects’?
‘The go to statement as it stands is just too primitive; it is too much an invitation to make a mess of one’s program.’
Desire to make programs verifiable
Desire to make programs verifiable
3 ways to reach the code under the label “back”
First way: Top down execution
Second way: condition2 == true
Third way: done == false
Difficult to know what has been executed so far.
Hence go to statements must be avoided!
Our Findings
Multiple goto jumps to the same label
This is what Dijkstra feared about!
62%
Single point of entry into label block!
9%
But not all use of goto is like what Dijkstra feared!
Stacking labels at the bottom of functions is prevalent
27%
Spaghetti code is uncommon
6%
Most of the jumps are forward, not backwards
90%
14%
Purposes
Most goto usage is for error handling and cleanup
Error Handling = 80%Cleanup = 40%
Most goto usage is for error handling and cleanup
Error Handling = 80%
Goto and labels used to emulate a try/catch or finally mechanism
Cleanup = 40%
Less intuitive usages such as control-exit and loop-create are less common
10%
Less intuitive usages such as control-exit and loop-create are less common
9%Most usages of goto statements appear to be for
error handling and cleanup
Quantitative Analysis
Mine Commits
6 OSS Projects
Quantitative Analysis
Mine Commits
6 OSS Projects
Link to Bugs
180 Days Of Commit History
Quantitative Analysis
Mine Commits
6 OSS Projects
Link to Bugs
180 Days Of Commit History
Bug Fix Commits
Extract Goto
Almost no Gotos are removed/modified in the post-release phase of a project
clamav-d
evel
ghostp
dlgim
p
openldap
postgresq
lVTK
02468
10121416
RemovedModified
Even fewer Gotos are removed/modified in the post-release bug fixes
clamav-d
evel
ghostp
dlgim
p
openldap
postgresq
lVTK
0
1
2
3
4
5
6
RemovedModified
Even fewer Gotos are removed/modified in the post-release bug fixes
clamav-d
evel
ghostp
dlgim
p
openldap
postgresq
lVTK
0
1
2
3
4
5
6
RemovedModified
Developers did not remove/modify goto statements in the post-release phase.
Summary