Amir Saboury, Pooya Musavi, Foutse Khomh and Giulio Antoniol
February 2017
Li and Shatnawi
The relationships between code smells and the occurrence of errors in Eclipse.
Code smells are positively associated with higher error probability.
Khomh et al.
The relationship between code smells and the change- and fault-proneness of 54 releases of four Java open source systems.
Classes with code smells tend to be more change- and fault-prone than other classes.
Fard et al.
JSNOSE: a tool to detect 13 different types of code smells in JavaScript systems.
“lazy object” and “long method/function” are the most frequent code smells.
Little is known on the impact of code smells in JavaScript server code
http://stackoverflow.com/research/developer-survey-2016
*https://siftery.com/nodejs
More than 4500 companies*
Netflix / NY Times / PayPal / Medium
LinkedIn / Uber / Walmart
Mozilla / Pinterest
...
function parse(url) {
url = url.split('/');
// ...
}
var download = function (url) {
var self = this;
var callback = function (err, data) {
self.error = err;
self.data = data;
}
$get(url, callback);
}
if (element = stack.pop()){
element.addClass("last");
}
Studied Systems, Data Extraction, Analysis
var a = 42;
var b = 5;
function addA(d) {
return a + d;
}
var c = addA(2) + b;
File
comit
comit
comit
comit
comit
bug inducing
bug fixing
Boolean
Number
Metrics
Code Smells
grunt - nested callbacks
Models how long subjects under observation can survive before the occurrence of an event of interest.
Die
Live
Die
Live
The number of hours between the previous revision and the revision r.
For each file f and revision r:
The presence of a code smell in the file f in the revision r.
Is the revision r a fault-fixing change?
Cox Proportional Hazard Model
Request
Less.js
Grunt
Express
Bower
Log-rank Test
(which compares the survival distributions of two samples)
p-value < 0.05
JavaScript files without code smells have hazard rates 65% lower than JavaScript files with code smells and this difference is statistically significant. |
---|
Time, Event
Smelly i
If the file has the code smell type i
LOC, Code Churn, and the number of past bugs
The hazard ratios of the studied code smells vary across the systems
Express
Chained Methods, This Assign, Variable Re-assign, and #Past-bugs
Grunt
Nested Callbacks, Assignment in Conditional Statements, and Variable Re-assign
Bower
Depth, #Past-bugs, and LOC
Less.js
Assignment in Conditional Statements, and #Past-bugs
Request
Variable Re-assign, and #Past-bugs
JavaScript files containing different types of code smells are not equally fault-prone. |
---|
Refactor files containing "Variable Re-assign" and "Assignment in Conditional Statements" code smell in priority.
https://srvy.online
Shared in HackerNews & EchoJS
1484
Participants
92% used JS for client-side applications
51% used JS for server-side applications
68% 3+ years of experience with JavaScript
Nested Callbacks (8.1/10)
Variable Re-assign (6.5/10)
Long Parameter List (6.2/10)
Findings bug-fixing commits ("bug", "fix", "defect" etc)
SZZ heuristic
Presence of the smell in the file as a whole
AST provided by ESLint
5 JS Systems
Quantitative study of 5 JavaScript systems
JS files without code smells have hazard rates 65% lower than JavaScript files with code smells
"Variable Re-assign" and "Assignment in Cond. Statements" have the highest hazard rates
Qualitative study with 1484 JS developers
Nested Callbacks, Variable Re-assign, Long Parameter List
"Variable Re-assign" and "Assignment in Conditional Statements"
Different types of code smells are not equally fault-prone.
Files without code smells have 65% lower hazard rates.
"Nested Callbacks", "Variable Re-assign", "Long Parameter List"
Thank you
10 years of research has provided evidence that code smells negatively affects fault-proneness, program comprehension and the effort required for certain maintenance activities, but recent studies show that developers still don't refactor code smells. What are we doing wrong?
move(x1, y1, x2, y2, direction, speed, steps, onFinish)
* https://sourcemaking.com/refactoring
cyclomatic complexity
* https://sourcemaking.com/refactoring
$('a').find('span').attr('id', 'title').end().click();
var download = function (url) {
if (url) {
$get(url, function(err, data) {
if (!err) {
if (data.includes('http')) {
//...
}
}
});
}
}