SlideShare a Scribd company logo
IDENTIFICATION OF
JAVASCRIPT CLASSES
Shahriar Rostami
Master’sThesis
Supervisor: Dr. NikolaosTsantalis
August 2016
Outline
■ Context of the study (goal, background)
■ Contribution
■ Approach
■ Evaluation of precision and recall
■ Case study
■ Tool features
■ Future work
2
Goal
■ To study existence of classes in JavaScript
■ Try to improve program comprehension
■ Long-term goal: Impact of OOP on maintenance of
JavaScript applications
3
Why JavaScript
■ The most used language on Github (2013-2015)
■ Everywhere: client-side, server-side (Node.JS), libraries, IOT
and databases
■ Dynamic, untyped and interpreted programming language
■ No syntactical support for Classes, Namespaces, and
import/export packages (prior to ES2015)
■ It needs better tooling
4
Class Emulation
f unct i on TheCl ass( ) {
t hi s. f oo = 0;
t hi s. bar = f unct i on( ) {
consol e. l og( t hi s. f oo) ;
}
}
var TheCl ass = f unct i on( ) {
t hi s. f oo = 0;
t hi s. bar = f unct i on( ) {
consol e. l og( t hi s. f oo) ;
}
}
var t heI nst ance = new TheCl ass( ) ;
t heI nst ance. f oo = 2;
t heI nst ance. bar ( ) ; / / 2
A B
C
1
2
3
4
5
6
1
2
3
4
5
6
1
2
3
5
Class Emulation
f unct i on TheCl ass ( ) {
t hi s. f oo = 0;
}
TheCl ass. pr ot ot ype. bar = f unct i on( ) {
consol e. l og( t hi s. f oo) ;
}
var TheCl ass = f unct i on( ) {
t hi s. f oo = 0;
}
TheCl ass. pr ot ot ype. bar = f unct i on( ) {
consol e. l og( t hi s. f oo) ;
}
var t heI nst ance = new TheCl ass ( ) ;
t heI nst ance. f oo = 2;
t heI nst ance. bar ( ) ; / / 2
A B
C
1
2
3
4
5
6
1
2
3
4
5
6
1
2
3
6
Namespace
(IIFE with return)
var t heCl assI nst ance = new namespace. Publ i cCl ass( ) ; / / I am a cl ass
A B
C
var namespace = ( f unct i on( ) {
var t empl at e = { } ;
t empl at e. myPr oper t y = 0;
t empl at e. Publ i cCl ass = f unct i on( ) {
consol e. l og( ' I am a cl ass' ) ;
}
r et ur n t empl at e;
} ) ( ) ;
var namespace = ( f unct i on( ) {
var cl assDecl ar at i on = f unct i on( ) {
consol e. l og( ' I am a cl ass' ) ;
}
r et ur n {
myPr oper t y : 0,
Publ i cCl ass : cl assDecl ar at i on
} ;
} ) ( ) ;
1
2
3
4
5
6
7
8
1
2
3
4
5
6
7
8
9
1
7
■ To prevent collision
■ To better organize code
Namespace
(IIFE with parameter)
var t heCl assI nst ance = new namespace. Publ i c Cl ass( ) ; / / I am a cl ass
A B
C
var namespace = { } ;
( f unct i on( ns) {
ns. myPr oper t y = 0;
ns. Publ i cCl ass = f unct i on( ) {
consol e. l og( ' I am a cl ass ' ) ;
}
} ) ( namespace) ;
var namespace = { } ;
( f unct i on( ) {
t hi s. myPr oper t y = 0;
t hi s. Publ i cCl ass = f unct i on( ) {
consol e. l og( ' I am a cl ass ' ) ;
}
} ) . appl y( namespace) ;
1
2
3
4
5
6
7
1
2
3
4
5
6
7
1
8
Namespace
(Nested object literals)
var namespace = {
modul e: {
subModul e: {
TheCl ass: f unct i on( ) {
t hi s. f oo = 0;
t hi s. pr i nt I t = f unct i on( ) {
consol e. l og( t hi s. f oo) ;
}
} ,
Anot her Cl ass: f unct i on( ) {
/ / Body of anot her cl ass
}
}
}
} ;
var t heI nst ance = new namespace. modul e. subModul e. TheCl ass( ) ;
t heI nst ance. f oo = 7;
t heI nst ance. pr i nt I t ( ) ;
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
9
Class and Namespace
■ Class emulation techniques: 4
■ Namespace emulation techniques: 5
■ Total: combination of 20 styles or more…
10
Contributions
■ A technique for identifying class emulations (JSDeodorant)
■ Build an oracle
■ Comparison with the state-of-the-art tool, JSClassFinder
■ Quantitative and Qualitative evaluation of the results to
identify limitations
■ Case study on open source JavaScript programs
11
Approach
12
Identifying Classes
■ Binding object creations: With a light weight data-flow analysis,
match instance creation with function constructor
– Simple Name Identifiers: i.e. new MockWindow()
– Composite Name Identifier: i.e. new namespace.PublicClass()
■ Inferring function constructors: Analyzing the body and
prototype object of functions
– Applies to unresolved functions
– Function with a method or an attribute is inferred as class
13
Unbiased Oracle for Evaluation
■ Using JSDoc Annotations
– @Constructor annotation on a function means that is a class
■ UsingTranspiled Code: automatically transpile projects to vanilla
JS
– TypeScript
– CoffeScript
14
Codes we analyze
15
Project Version
Size
(KLOC)
#JS Files
#Function
s
#Classes
Closure-
library
20160315 605 1,502 23,535 946
Doppio Rev:7229e7d 17.7 47 1,977 154
Atom V1.7.0.beta5 34 116 3,175 102
Precision and Recall
Program
Identified
function
constructors
TP FP FN Precision Recall
Closure-library 1,008 907 101 39 90% 96%
Doppio 154 153 1 1 99% 99%
Atom 106 101 5 1 95% 99%
16
Qualitative analysis
17
■ Two independent evaluators
– Classes that are not inOracle but we found (Extra)
– Classes that we can’t find, but are in Oracle (FN)
■ Limitations:
– Inheritance
– InterfaceVSClass
Comparison with the
State-of-the-art
■ Both tools have high precision on average, but JSDeodorant
greatly outperforms JSClassFinder for recall
18
Project
JSClassFinder[1] JSDeodorant
Precision Recall Precision Recall
Closure-
library
99% 76% 98% 96%
Doppio 96% 14% 99% 99%
Atom 100% 93% 95% 98%
Average 98% 61% 97% 98%
[1]: Silve et.al. Does JavaScript Software Embrace Classes? SANER’15
JSDeodorant is Accurate!
19
JSDeodorant
Precision: 97%
Recall: 98% >
JSClassFinder
Precision: 98%
Recall: 61%
Empirical Study
■ Build a dataset (NodeJS,Website and Library)
■ Preprocess (removal of test and document folder)
■ Any difference of class adaptation among these three groups?
■ Eyeball analysis:Yes
■ Statistically?
20
Analyzed Systems
21
Project #Classes
NodeJS Express 8
Forever 0
Less.js 77
Node-
browserify
2
NPM 35
PM2 11
Statsd 11
Yo 0
Project #Classes
Website Google 128
Facebook 312
Baidu 54
Yahoo! 15
Amazon 124
Twitter 147
Project #Classes Project #Classes
Libraries
Ace 5 Jquery 45
Angular 109 PDF 306
Backbone 18 Underscore 25
Ember 32
The Distribution of Data
■ Normalize number of #classes with #files
■ Appropriate statistical test
■ Shapiro Walk test to assess whether the distribution is normal or
not
■ P-values
– NodeJS: 0.02699
– Websites: 0.0468
– Libraries: 0.01349
22
AppropriateTest?
■ Wilcoxon rank sum test (MannWhitney U test)
■ Statistically significant difference between #Classes?
■ NodeJS <Websites (P-value: 0.0011)
■ Libraries <Websites (P-value: 0.006993)
■ NodeJS < Libraries (P-value: 0.02799)
23
NodeJS < Libraries <Websites
JSDeodorant
■ CLI Mode
– CSV
– Database
24
JSDeodorant
■ Eclipse plugin
– Navigation
– ModuleView
– ModuleVisualization
25
Conclusion
■ An approach for identifying JavaScript classes
– Supporting Namespace, Import/Export
– High precision and Recall
■ An unbiased oracle
■ NodeJS < Libraries <Websites
■ An infrastructure for other studies
■ Eclipse Plugin
26
Future work
■ Finding code smells
– God Class, Data Class, Feature Envy
■ Support for inheritance
■ Transform classes to new version of JavaScript
– ES2015 syntactically supports Class, Namespace and
Import/Export
27
To appear in ICSME’16 ERATrack
28
/sshishe/jsdeodorant

More Related Content

What's hot

APMG juni 2014 - Regular Expression
APMG juni 2014 - Regular ExpressionAPMG juni 2014 - Regular Expression
APMG juni 2014 - Regular ExpressionByte
 
Internship - Final Presentation (26-08-2015)
Internship - Final Presentation (26-08-2015)Internship - Final Presentation (26-08-2015)
Internship - Final Presentation (26-08-2015)Sean Krail
 
building global software/earthcube->sciencecloud
building global software/earthcube->sciencecloudbuilding global software/earthcube->sciencecloud
building global software/earthcube->sciencecloudIan Foster
 
GTAC 2014: What lurks in test suites?
GTAC 2014: What lurks in test suites?GTAC 2014: What lurks in test suites?
GTAC 2014: What lurks in test suites?Patrick Lam
 
Object Detection with Tensorflow
Object Detection with TensorflowObject Detection with Tensorflow
Object Detection with TensorflowElifTech
 
Chapter 6: stack data structure
Chapter 6:  stack data structureChapter 6:  stack data structure
Chapter 6: stack data structureMahmoud Alfarra
 
DConf 2016: Keynote by Walter Bright
DConf 2016: Keynote by Walter Bright DConf 2016: Keynote by Walter Bright
DConf 2016: Keynote by Walter Bright Andrei Alexandrescu
 
TMPA-2017: Vellvm - Verifying the LLVM
TMPA-2017: Vellvm - Verifying the LLVMTMPA-2017: Vellvm - Verifying the LLVM
TMPA-2017: Vellvm - Verifying the LLVMIosif Itkin
 
Streams or Loops? Java 8 Stream API by Niki Petkov - Proxiad Bulgaria
Streams or Loops? Java 8 Stream API by Niki Petkov - Proxiad BulgariaStreams or Loops? Java 8 Stream API by Niki Petkov - Proxiad Bulgaria
Streams or Loops? Java 8 Stream API by Niki Petkov - Proxiad BulgariaHackBulgaria
 
Halogen: Past, Present, and Future
Halogen: Past, Present, and FutureHalogen: Past, Present, and Future
Halogen: Past, Present, and FutureJohn De Goes
 
Ponies and Unicorns With Scala
Ponies and Unicorns With ScalaPonies and Unicorns With Scala
Ponies and Unicorns With ScalaTomer Gabel
 
Extend R with Rcpp!!!
Extend R with Rcpp!!!Extend R with Rcpp!!!
Extend R with Rcpp!!!mickey24
 
Genomic Analysis in Scala
Genomic Analysis in ScalaGenomic Analysis in Scala
Genomic Analysis in ScalaRyan Williams
 
D422 ex-4-2 python
D422 ex-4-2 pythonD422 ex-4-2 python
D422 ex-4-2 pythonOmkar Rane
 
Rainer Grimm, “Functional Programming in C++11”
Rainer Grimm, “Functional Programming in C++11”Rainer Grimm, “Functional Programming in C++11”
Rainer Grimm, “Functional Programming in C++11”Platonov Sergey
 

What's hot (20)

Vim Registers
Vim RegistersVim Registers
Vim Registers
 
Clojure+ClojureScript Webapps
Clojure+ClojureScript WebappsClojure+ClojureScript Webapps
Clojure+ClojureScript Webapps
 
APMG juni 2014 - Regular Expression
APMG juni 2014 - Regular ExpressionAPMG juni 2014 - Regular Expression
APMG juni 2014 - Regular Expression
 
Internship - Final Presentation (26-08-2015)
Internship - Final Presentation (26-08-2015)Internship - Final Presentation (26-08-2015)
Internship - Final Presentation (26-08-2015)
 
building global software/earthcube->sciencecloud
building global software/earthcube->sciencecloudbuilding global software/earthcube->sciencecloud
building global software/earthcube->sciencecloud
 
GTAC 2014: What lurks in test suites?
GTAC 2014: What lurks in test suites?GTAC 2014: What lurks in test suites?
GTAC 2014: What lurks in test suites?
 
Object Detection with Tensorflow
Object Detection with TensorflowObject Detection with Tensorflow
Object Detection with Tensorflow
 
Chapter 6: stack data structure
Chapter 6:  stack data structureChapter 6:  stack data structure
Chapter 6: stack data structure
 
Java 7
Java 7Java 7
Java 7
 
DConf 2016: Keynote by Walter Bright
DConf 2016: Keynote by Walter Bright DConf 2016: Keynote by Walter Bright
DConf 2016: Keynote by Walter Bright
 
TMPA-2017: Vellvm - Verifying the LLVM
TMPA-2017: Vellvm - Verifying the LLVMTMPA-2017: Vellvm - Verifying the LLVM
TMPA-2017: Vellvm - Verifying the LLVM
 
Streams or Loops? Java 8 Stream API by Niki Petkov - Proxiad Bulgaria
Streams or Loops? Java 8 Stream API by Niki Petkov - Proxiad BulgariaStreams or Loops? Java 8 Stream API by Niki Petkov - Proxiad Bulgaria
Streams or Loops? Java 8 Stream API by Niki Petkov - Proxiad Bulgaria
 
Halogen: Past, Present, and Future
Halogen: Past, Present, and FutureHalogen: Past, Present, and Future
Halogen: Past, Present, and Future
 
Ponies and Unicorns With Scala
Ponies and Unicorns With ScalaPonies and Unicorns With Scala
Ponies and Unicorns With Scala
 
Extend R with Rcpp!!!
Extend R with Rcpp!!!Extend R with Rcpp!!!
Extend R with Rcpp!!!
 
Java 8 Lambda Expressions
Java 8 Lambda ExpressionsJava 8 Lambda Expressions
Java 8 Lambda Expressions
 
Genomic Analysis in Scala
Genomic Analysis in ScalaGenomic Analysis in Scala
Genomic Analysis in Scala
 
Lrz kurse: r as superglue
Lrz kurse: r as superglueLrz kurse: r as superglue
Lrz kurse: r as superglue
 
D422 ex-4-2 python
D422 ex-4-2 pythonD422 ex-4-2 python
D422 ex-4-2 python
 
Rainer Grimm, “Functional Programming in C++11”
Rainer Grimm, “Functional Programming in C++11”Rainer Grimm, “Functional Programming in C++11”
Rainer Grimm, “Functional Programming in C++11”
 

Similar to Slides

Scala uma poderosa linguagem para a jvm
Scala   uma poderosa linguagem para a jvmScala   uma poderosa linguagem para a jvm
Scala uma poderosa linguagem para a jvmIsaias Barroso
 
Introduction to Scala for JCConf Taiwan
Introduction to Scala for JCConf TaiwanIntroduction to Scala for JCConf Taiwan
Introduction to Scala for JCConf TaiwanJimin Hsieh
 
ScalaDays 2013 Keynote Speech by Martin Odersky
ScalaDays 2013 Keynote Speech by Martin OderskyScalaDays 2013 Keynote Speech by Martin Odersky
ScalaDays 2013 Keynote Speech by Martin OderskyTypesafe
 
Object Oriented Programming in Matlab
Object Oriented Programming in Matlab Object Oriented Programming in Matlab
Object Oriented Programming in Matlab AlbanLevy
 
Develop realtime web with Scala and Xitrum
Develop realtime web with Scala and XitrumDevelop realtime web with Scala and Xitrum
Develop realtime web with Scala and XitrumNgoc Dao
 
JavaScript(Es5) Interview Questions & Answers
JavaScript(Es5)  Interview Questions & AnswersJavaScript(Es5)  Interview Questions & Answers
JavaScript(Es5) Interview Questions & AnswersRatnala Charan kumar
 
Java 2 chapter 10 - basic oop in java
Java 2   chapter 10 - basic oop in javaJava 2   chapter 10 - basic oop in java
Java 2 chapter 10 - basic oop in javalet's go to study
 
EdSketch: Execution-Driven Sketching for Java
EdSketch: Execution-Driven Sketching for JavaEdSketch: Execution-Driven Sketching for Java
EdSketch: Execution-Driven Sketching for JavaLisa Hua
 
The use of the code analysis library OpenC++: modifications, improvements, er...
The use of the code analysis library OpenC++: modifications, improvements, er...The use of the code analysis library OpenC++: modifications, improvements, er...
The use of the code analysis library OpenC++: modifications, improvements, er...PVS-Studio
 
Real Time Big Data Management
Real Time Big Data ManagementReal Time Big Data Management
Real Time Big Data ManagementAlbert Bifet
 
Scala Talk at FOSDEM 2009
Scala Talk at FOSDEM 2009Scala Talk at FOSDEM 2009
Scala Talk at FOSDEM 2009Martin Odersky
 
Scala for Java Programmers
Scala for Java ProgrammersScala for Java Programmers
Scala for Java ProgrammersEric Pederson
 
Uncovering Performance Problems in Java Applications with Reference Propagati...
Uncovering Performance Problems in Java Applications with Reference Propagati...Uncovering Performance Problems in Java Applications with Reference Propagati...
Uncovering Performance Problems in Java Applications with Reference Propagati...Dacong (Tony) Yan
 
Clean Code for East Bay .NET User Group
Clean Code for East Bay .NET User GroupClean Code for East Bay .NET User Group
Clean Code for East Bay .NET User GroupTheo Jungeblut
 
What can be done with Java, but should better be done with Erlang (@pavlobaron)
What can be done with Java, but should better be done with Erlang (@pavlobaron)What can be done with Java, but should better be done with Erlang (@pavlobaron)
What can be done with Java, but should better be done with Erlang (@pavlobaron)Pavlo Baron
 
Twins: Object Oriented Programming and Functional Programming
Twins: Object Oriented Programming and Functional ProgrammingTwins: Object Oriented Programming and Functional Programming
Twins: Object Oriented Programming and Functional ProgrammingRichardWarburton
 

Similar to Slides (20)

Scala uma poderosa linguagem para a jvm
Scala   uma poderosa linguagem para a jvmScala   uma poderosa linguagem para a jvm
Scala uma poderosa linguagem para a jvm
 
Introduction to Scala for JCConf Taiwan
Introduction to Scala for JCConf TaiwanIntroduction to Scala for JCConf Taiwan
Introduction to Scala for JCConf Taiwan
 
ScalaDays 2013 Keynote Speech by Martin Odersky
ScalaDays 2013 Keynote Speech by Martin OderskyScalaDays 2013 Keynote Speech by Martin Odersky
ScalaDays 2013 Keynote Speech by Martin Odersky
 
Object Oriented Programming in Matlab
Object Oriented Programming in Matlab Object Oriented Programming in Matlab
Object Oriented Programming in Matlab
 
Develop realtime web with Scala and Xitrum
Develop realtime web with Scala and XitrumDevelop realtime web with Scala and Xitrum
Develop realtime web with Scala and Xitrum
 
JavaScript(Es5) Interview Questions & Answers
JavaScript(Es5)  Interview Questions & AnswersJavaScript(Es5)  Interview Questions & Answers
JavaScript(Es5) Interview Questions & Answers
 
Java 2 chapter 10 - basic oop in java
Java 2   chapter 10 - basic oop in javaJava 2   chapter 10 - basic oop in java
Java 2 chapter 10 - basic oop in java
 
Scala ntnu
Scala ntnuScala ntnu
Scala ntnu
 
Angular Schematics
Angular SchematicsAngular Schematics
Angular Schematics
 
EdSketch: Execution-Driven Sketching for Java
EdSketch: Execution-Driven Sketching for JavaEdSketch: Execution-Driven Sketching for Java
EdSketch: Execution-Driven Sketching for Java
 
The use of the code analysis library OpenC++: modifications, improvements, er...
The use of the code analysis library OpenC++: modifications, improvements, er...The use of the code analysis library OpenC++: modifications, improvements, er...
The use of the code analysis library OpenC++: modifications, improvements, er...
 
Real Time Big Data Management
Real Time Big Data ManagementReal Time Big Data Management
Real Time Big Data Management
 
Day 2
Day 2Day 2
Day 2
 
Scala Talk at FOSDEM 2009
Scala Talk at FOSDEM 2009Scala Talk at FOSDEM 2009
Scala Talk at FOSDEM 2009
 
Scala for Java Programmers
Scala for Java ProgrammersScala for Java Programmers
Scala for Java Programmers
 
Uncovering Performance Problems in Java Applications with Reference Propagati...
Uncovering Performance Problems in Java Applications with Reference Propagati...Uncovering Performance Problems in Java Applications with Reference Propagati...
Uncovering Performance Problems in Java Applications with Reference Propagati...
 
Clean Code for East Bay .NET User Group
Clean Code for East Bay .NET User GroupClean Code for East Bay .NET User Group
Clean Code for East Bay .NET User Group
 
What can be done with Java, but should better be done with Erlang (@pavlobaron)
What can be done with Java, but should better be done with Erlang (@pavlobaron)What can be done with Java, but should better be done with Erlang (@pavlobaron)
What can be done with Java, but should better be done with Erlang (@pavlobaron)
 
Perl tutorial final
Perl tutorial finalPerl tutorial final
Perl tutorial final
 
Twins: Object Oriented Programming and Functional Programming
Twins: Object Oriented Programming and Functional ProgrammingTwins: Object Oriented Programming and Functional Programming
Twins: Object Oriented Programming and Functional Programming
 

Slides

  • 1. IDENTIFICATION OF JAVASCRIPT CLASSES Shahriar Rostami Master’sThesis Supervisor: Dr. NikolaosTsantalis August 2016
  • 2. Outline ■ Context of the study (goal, background) ■ Contribution ■ Approach ■ Evaluation of precision and recall ■ Case study ■ Tool features ■ Future work 2
  • 3. Goal ■ To study existence of classes in JavaScript ■ Try to improve program comprehension ■ Long-term goal: Impact of OOP on maintenance of JavaScript applications 3
  • 4. Why JavaScript ■ The most used language on Github (2013-2015) ■ Everywhere: client-side, server-side (Node.JS), libraries, IOT and databases ■ Dynamic, untyped and interpreted programming language ■ No syntactical support for Classes, Namespaces, and import/export packages (prior to ES2015) ■ It needs better tooling 4
  • 5. Class Emulation f unct i on TheCl ass( ) { t hi s. f oo = 0; t hi s. bar = f unct i on( ) { consol e. l og( t hi s. f oo) ; } } var TheCl ass = f unct i on( ) { t hi s. f oo = 0; t hi s. bar = f unct i on( ) { consol e. l og( t hi s. f oo) ; } } var t heI nst ance = new TheCl ass( ) ; t heI nst ance. f oo = 2; t heI nst ance. bar ( ) ; / / 2 A B C 1 2 3 4 5 6 1 2 3 4 5 6 1 2 3 5
  • 6. Class Emulation f unct i on TheCl ass ( ) { t hi s. f oo = 0; } TheCl ass. pr ot ot ype. bar = f unct i on( ) { consol e. l og( t hi s. f oo) ; } var TheCl ass = f unct i on( ) { t hi s. f oo = 0; } TheCl ass. pr ot ot ype. bar = f unct i on( ) { consol e. l og( t hi s. f oo) ; } var t heI nst ance = new TheCl ass ( ) ; t heI nst ance. f oo = 2; t heI nst ance. bar ( ) ; / / 2 A B C 1 2 3 4 5 6 1 2 3 4 5 6 1 2 3 6
  • 7. Namespace (IIFE with return) var t heCl assI nst ance = new namespace. Publ i cCl ass( ) ; / / I am a cl ass A B C var namespace = ( f unct i on( ) { var t empl at e = { } ; t empl at e. myPr oper t y = 0; t empl at e. Publ i cCl ass = f unct i on( ) { consol e. l og( ' I am a cl ass' ) ; } r et ur n t empl at e; } ) ( ) ; var namespace = ( f unct i on( ) { var cl assDecl ar at i on = f unct i on( ) { consol e. l og( ' I am a cl ass' ) ; } r et ur n { myPr oper t y : 0, Publ i cCl ass : cl assDecl ar at i on } ; } ) ( ) ; 1 2 3 4 5 6 7 8 1 2 3 4 5 6 7 8 9 1 7 ■ To prevent collision ■ To better organize code
  • 8. Namespace (IIFE with parameter) var t heCl assI nst ance = new namespace. Publ i c Cl ass( ) ; / / I am a cl ass A B C var namespace = { } ; ( f unct i on( ns) { ns. myPr oper t y = 0; ns. Publ i cCl ass = f unct i on( ) { consol e. l og( ' I am a cl ass ' ) ; } } ) ( namespace) ; var namespace = { } ; ( f unct i on( ) { t hi s. myPr oper t y = 0; t hi s. Publ i cCl ass = f unct i on( ) { consol e. l og( ' I am a cl ass ' ) ; } } ) . appl y( namespace) ; 1 2 3 4 5 6 7 1 2 3 4 5 6 7 1 8
  • 9. Namespace (Nested object literals) var namespace = { modul e: { subModul e: { TheCl ass: f unct i on( ) { t hi s. f oo = 0; t hi s. pr i nt I t = f unct i on( ) { consol e. l og( t hi s. f oo) ; } } , Anot her Cl ass: f unct i on( ) { / / Body of anot her cl ass } } } } ; var t heI nst ance = new namespace. modul e. subModul e. TheCl ass( ) ; t heI nst ance. f oo = 7; t heI nst ance. pr i nt I t ( ) ; 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 9
  • 10. Class and Namespace ■ Class emulation techniques: 4 ■ Namespace emulation techniques: 5 ■ Total: combination of 20 styles or more… 10
  • 11. Contributions ■ A technique for identifying class emulations (JSDeodorant) ■ Build an oracle ■ Comparison with the state-of-the-art tool, JSClassFinder ■ Quantitative and Qualitative evaluation of the results to identify limitations ■ Case study on open source JavaScript programs 11
  • 13. Identifying Classes ■ Binding object creations: With a light weight data-flow analysis, match instance creation with function constructor – Simple Name Identifiers: i.e. new MockWindow() – Composite Name Identifier: i.e. new namespace.PublicClass() ■ Inferring function constructors: Analyzing the body and prototype object of functions – Applies to unresolved functions – Function with a method or an attribute is inferred as class 13
  • 14. Unbiased Oracle for Evaluation ■ Using JSDoc Annotations – @Constructor annotation on a function means that is a class ■ UsingTranspiled Code: automatically transpile projects to vanilla JS – TypeScript – CoffeScript 14
  • 15. Codes we analyze 15 Project Version Size (KLOC) #JS Files #Function s #Classes Closure- library 20160315 605 1,502 23,535 946 Doppio Rev:7229e7d 17.7 47 1,977 154 Atom V1.7.0.beta5 34 116 3,175 102
  • 16. Precision and Recall Program Identified function constructors TP FP FN Precision Recall Closure-library 1,008 907 101 39 90% 96% Doppio 154 153 1 1 99% 99% Atom 106 101 5 1 95% 99% 16
  • 17. Qualitative analysis 17 ■ Two independent evaluators – Classes that are not inOracle but we found (Extra) – Classes that we can’t find, but are in Oracle (FN) ■ Limitations: – Inheritance – InterfaceVSClass
  • 18. Comparison with the State-of-the-art ■ Both tools have high precision on average, but JSDeodorant greatly outperforms JSClassFinder for recall 18 Project JSClassFinder[1] JSDeodorant Precision Recall Precision Recall Closure- library 99% 76% 98% 96% Doppio 96% 14% 99% 99% Atom 100% 93% 95% 98% Average 98% 61% 97% 98% [1]: Silve et.al. Does JavaScript Software Embrace Classes? SANER’15
  • 19. JSDeodorant is Accurate! 19 JSDeodorant Precision: 97% Recall: 98% > JSClassFinder Precision: 98% Recall: 61%
  • 20. Empirical Study ■ Build a dataset (NodeJS,Website and Library) ■ Preprocess (removal of test and document folder) ■ Any difference of class adaptation among these three groups? ■ Eyeball analysis:Yes ■ Statistically? 20
  • 21. Analyzed Systems 21 Project #Classes NodeJS Express 8 Forever 0 Less.js 77 Node- browserify 2 NPM 35 PM2 11 Statsd 11 Yo 0 Project #Classes Website Google 128 Facebook 312 Baidu 54 Yahoo! 15 Amazon 124 Twitter 147 Project #Classes Project #Classes Libraries Ace 5 Jquery 45 Angular 109 PDF 306 Backbone 18 Underscore 25 Ember 32
  • 22. The Distribution of Data ■ Normalize number of #classes with #files ■ Appropriate statistical test ■ Shapiro Walk test to assess whether the distribution is normal or not ■ P-values – NodeJS: 0.02699 – Websites: 0.0468 – Libraries: 0.01349 22
  • 23. AppropriateTest? ■ Wilcoxon rank sum test (MannWhitney U test) ■ Statistically significant difference between #Classes? ■ NodeJS <Websites (P-value: 0.0011) ■ Libraries <Websites (P-value: 0.006993) ■ NodeJS < Libraries (P-value: 0.02799) 23 NodeJS < Libraries <Websites
  • 24. JSDeodorant ■ CLI Mode – CSV – Database 24
  • 25. JSDeodorant ■ Eclipse plugin – Navigation – ModuleView – ModuleVisualization 25
  • 26. Conclusion ■ An approach for identifying JavaScript classes – Supporting Namespace, Import/Export – High precision and Recall ■ An unbiased oracle ■ NodeJS < Libraries <Websites ■ An infrastructure for other studies ■ Eclipse Plugin 26
  • 27. Future work ■ Finding code smells – God Class, Data Class, Feature Envy ■ Support for inheritance ■ Transform classes to new version of JavaScript – ES2015 syntactically supports Class, Namespace and Import/Export 27
  • 28. To appear in ICSME’16 ERATrack 28 /sshishe/jsdeodorant

Editor's Notes

  1. Tell story about not having standard But people are using OOP in it And developers made their own patterns Motivation: Whether or not developers are using JavaScript OO practic the long term goalof this research is to see the impact of oop on maintenance
  2. Tell why we need namespace -> Collison and Organization
  3. Say somethings about object literal
  4. I show different way to create class now how should we detetc them
  5. Oracle: For precision and recall (evaluate) and comparison and then if it’s good -> case study
  6. explain the enhanced model
  7. What is a unbiased oracle, what is biased How you build it
  8. What is a unbiased oracle, what is biased How you build it
  9. TP: chizi ke bayad peyda mikardi, peyda ham kardi. FP: chizi ke nabayad peyda mikardi, vali peyda kardi. FN: chizi ke bayad peyda mikardi, peyda nakardi. TN: chizi ke nabayad peyda mikardi, peyda ham nakardi. Precision: az beine chizayi ke peyda kardi, chandtashoon dorostan? Recall: az beine chizayi ke bayad peyda mikardi chandta ro dorost peyda kardi? Explian the results, talk about qualitative, analysis + limitation (may be in next slide) FP: Az in 101 > 18 tash interface budan (our bug) 82 tash class budan annotation nadashtan FN : No instantiation , nor methods and attribtues
  10. For Extra: Consensus whether they are class or not (Some of them for test and lack of @constructor) For FN: lack of implementation like interface, inheritance, empty class
  11. JSClassFinder: 1) They can’t infer classes , 2) Because they don’t have dependency, they match each name once!
  12. Make a transition slide : Our tool is accurate and out perfom the state of the art so it is reliable to use it for empirical study Why you choose these categories? because other researchers also analyzed these categories [ali mesbah and kim work Also mention for websites which they minify code, JSDeodorant does not break
  13. Make a transition slide : Our tool is accurate and out perfom the state of the art so it is reliable to use it for empirical study Why you choose these categories? because other researchers also analyzed these categories [ali mesbah and kim work Also mention for websites which they minify code, JSDeodorant does not break
  14. Why NodeJS has less, Why Websites are top Try to normalize with number of statements
  15. Making CSVs Database Many flags and so on
  16. Explain we have code navigation
  17. Link to Github and dataset