SlideShare ist ein Scribd-Unternehmen logo
1 von 42
Clean JavaScript
Code
only dream or reality?
Sebastian Łaciak
• Clean Code
• Node.js
• Environment
• Tests Support
• Design Patterns
Agenda
Clean Code
C1: Inappropriate Information
/** ------------------------------- REVISION HISTORY -------------
dd-mmm-yyyy <name> <problem number> <description>
06/01/99 Kowalski Andy initial
*/
C2: Obsolete Comments
/* return sum of arguments */
function multiply(a, b) { return a * b; }
C3: Redundant Comments
/* multiply two numbers */
function multiply(a, b) { return a * b; }
C4: Poorly Written Comments
/* I had to write this comment due to checkstyle */
function add(a, b) { return a + b; }
C5: Commented-Out Code
/* function devide(a, b) { return a / b; } */
Comments
E1: Build Requires More Than One Step
mvn install
E2: Tests Require More Than One Step
karma start
Environment
G2: Obvious Behavior Is Unimplemented
function getValue() {
this.otherValue = null;
counter = counter + 1;
return counter;
}
G3: Incorrect Behavior at the Boundaries
function getLastName() {
return firstName;
}
G4: Overridden Safeties
/** QUnit.test("should return sum of 1 and 3", function(assert) {
assert.equal(this.calculator.add(1, 3), 4);
});
}*/
General
G5: Duplication
DRY – Don’t repeat yourself
G9: Dead Code
G10: Vertical Separation
function add(a, b) {
AssertArg.notUndefined(a);
AssertArg.notUndefined(b);
return a + b;
}
G11: Inconsistency
function setLastName(lName) {
surName = lName;
}
General
G20: Function Names Should Say What
They Do
function getValue() {
this.otherValue = null;
counter = counter + 1;
return counter;
}
G25: Replace Magic Numbers with Named
Constants
var MONTH_APRIL = 3;
General
F1: Too Many Arguments
function doSth(a,b,c,d,e,f,g,h) {
…
}
F3: Flag Arguments
function sort(ascOrder) {…}
F4: Dead Function
Functions
N1: Choose Descriptive Names
function doSth(a,b,c,d,e,f,g,h) {…}
N5: Use Long Names for Long Scopes
var pageDisplayCounter = 1;
N7: Names Should Describe Side-Effects
function getOrCreate() {…}
Names
T1: Insufficient Tests
it("should return sum of 1 and 3", function() {
var result = calculator.add(1, 3);
});
T2: Use a Coverage Tool!
T3: Don’t Skip Trivial Tests
function setLastName(lName) {
firstName = lName;
}
T6: Exhaustively Test Near Bugs
T9: Tests Should Be Fast
Tests
Node.js
Node.js® is a platform built on Chrome's JavaScript runtime for easily building
fast, scalable network applications. Node.js uses an event-driven, non-blocking
I/O model that makes it lightweight and efficient, perfect for data-intensive
real-time applications that run across distributed devices.
Node.js
Node.js
Node.js
Java Platform
Node.js – Single Thread
npm is a package manager for JavaScript, and is the default for Node.js.
npm is bundled and installed automatically with the Node.js environment. npm
runs through the command line and manages dependencies for an application.
It also allows users to install Node.js applications that are available on the npm
registry.
Node Package Manager
Environment
Development Environment
Development Environment
JSHint
Tests Support
Unit tests
QUnit
Jasmine
Mocks
Mocks – QUnit with Sinon
Mocks – Jasmine
Karma runner
Karma configuration
QUnit - browser
QUnit - browser
Karma Coverage with QUnit
PhantomJS
Design Patterns
Namespaces
Class with encapsulation
Singleton
Inheritance
Factory
4Developers 2015: Clean JavaScript code - only dream or reality - Sebastian Łaciak

Weitere ähnliche Inhalte

Was ist angesagt?

Michal Malohlava presents: Open Source H2O and Scala
Michal Malohlava presents: Open Source H2O and Scala Michal Malohlava presents: Open Source H2O and Scala
Michal Malohlava presents: Open Source H2O and Scala Sri Ambati
 
openCypher Technology Compatibility Kit (TCK)
openCypher Technology Compatibility Kit (TCK)openCypher Technology Compatibility Kit (TCK)
openCypher Technology Compatibility Kit (TCK)openCypher
 
BeepBeep 3: A declarative event stream query engine (EDOC 2015)
BeepBeep 3: A declarative event stream query engine (EDOC 2015)BeepBeep 3: A declarative event stream query engine (EDOC 2015)
BeepBeep 3: A declarative event stream query engine (EDOC 2015)Sylvain Hallé
 
FUNCTIONS IN c++ PPT
FUNCTIONS IN c++ PPTFUNCTIONS IN c++ PPT
FUNCTIONS IN c++ PPT03062679929
 
Implementation of 'go-like' language constructions in scala [english version]
Implementation of 'go-like' language constructions in scala [english version] Implementation of 'go-like' language constructions in scala [english version]
Implementation of 'go-like' language constructions in scala [english version] Ruslan Shevchenko
 
When RV Meets CEP (RV 2016 Tutorial)
When RV Meets CEP (RV 2016 Tutorial)When RV Meets CEP (RV 2016 Tutorial)
When RV Meets CEP (RV 2016 Tutorial)Sylvain Hallé
 
A formalization of complex event stream processing
A formalization of complex event stream processingA formalization of complex event stream processing
A formalization of complex event stream processingSylvain Hallé
 
New microsoft office word document (2)
New microsoft office word document (2)New microsoft office word document (2)
New microsoft office word document (2)Syed Umair
 
A "Do-It-Yourself" Specification Language with BeepBeep 3 (Talk @ Dagstuhl 2017)
A "Do-It-Yourself" Specification Language with BeepBeep 3 (Talk @ Dagstuhl 2017)A "Do-It-Yourself" Specification Language with BeepBeep 3 (Talk @ Dagstuhl 2017)
A "Do-It-Yourself" Specification Language with BeepBeep 3 (Talk @ Dagstuhl 2017)Sylvain Hallé
 
c plus plus programsSlide
c plus plus programsSlidec plus plus programsSlide
c plus plus programsSlideharman kaur
 

Was ist angesagt? (20)

Pratik Bakane C++
Pratik Bakane C++Pratik Bakane C++
Pratik Bakane C++
 
Pratik Bakane C++
Pratik Bakane C++Pratik Bakane C++
Pratik Bakane C++
 
Pratik Bakane C++
Pratik Bakane C++Pratik Bakane C++
Pratik Bakane C++
 
Michal Malohlava presents: Open Source H2O and Scala
Michal Malohlava presents: Open Source H2O and Scala Michal Malohlava presents: Open Source H2O and Scala
Michal Malohlava presents: Open Source H2O and Scala
 
Pratik Bakane C++
Pratik Bakane C++Pratik Bakane C++
Pratik Bakane C++
 
Labsheet_3
Labsheet_3Labsheet_3
Labsheet_3
 
openCypher Technology Compatibility Kit (TCK)
openCypher Technology Compatibility Kit (TCK)openCypher Technology Compatibility Kit (TCK)
openCypher Technology Compatibility Kit (TCK)
 
BeepBeep 3: A declarative event stream query engine (EDOC 2015)
BeepBeep 3: A declarative event stream query engine (EDOC 2015)BeepBeep 3: A declarative event stream query engine (EDOC 2015)
BeepBeep 3: A declarative event stream query engine (EDOC 2015)
 
FUNCTIONS IN c++ PPT
FUNCTIONS IN c++ PPTFUNCTIONS IN c++ PPT
FUNCTIONS IN c++ PPT
 
Implementation of 'go-like' language constructions in scala [english version]
Implementation of 'go-like' language constructions in scala [english version] Implementation of 'go-like' language constructions in scala [english version]
Implementation of 'go-like' language constructions in scala [english version]
 
Rcpp11 useR2014
Rcpp11 useR2014Rcpp11 useR2014
Rcpp11 useR2014
 
When RV Meets CEP (RV 2016 Tutorial)
When RV Meets CEP (RV 2016 Tutorial)When RV Meets CEP (RV 2016 Tutorial)
When RV Meets CEP (RV 2016 Tutorial)
 
A formalization of complex event stream processing
A formalization of complex event stream processingA formalization of complex event stream processing
A formalization of complex event stream processing
 
Profiling in python
Profiling in pythonProfiling in python
Profiling in python
 
New microsoft office word document (2)
New microsoft office word document (2)New microsoft office word document (2)
New microsoft office word document (2)
 
A "Do-It-Yourself" Specification Language with BeepBeep 3 (Talk @ Dagstuhl 2017)
A "Do-It-Yourself" Specification Language with BeepBeep 3 (Talk @ Dagstuhl 2017)A "Do-It-Yourself" Specification Language with BeepBeep 3 (Talk @ Dagstuhl 2017)
A "Do-It-Yourself" Specification Language with BeepBeep 3 (Talk @ Dagstuhl 2017)
 
c plus plus programsSlide
c plus plus programsSlidec plus plus programsSlide
c plus plus programsSlide
 
week-11x
week-11xweek-11x
week-11x
 
week-4x
week-4xweek-4x
week-4x
 
P2
P2P2
P2
 

Andere mochten auch

How To Relieve Flying Anxiety
How To Relieve Flying AnxietyHow To Relieve Flying Anxiety
How To Relieve Flying Anxietypowellcalvinss
 
קדושים 2
קדושים 2קדושים 2
קדושים 2el9360
 
Presentacion ing. industrial
Presentacion ing. industrialPresentacion ing. industrial
Presentacion ing. industrialOscar Villeneuve
 
News Story 2 Interview Prep Sheet
News Story 2 Interview Prep SheetNews Story 2 Interview Prep Sheet
News Story 2 Interview Prep Sheetryansharman
 
SS6PU100 6A 100V Schottky Rectifier on backlight
SS6PU100 6A 100V Schottky Rectifier on backlightSS6PU100 6A 100V Schottky Rectifier on backlight
SS6PU100 6A 100V Schottky Rectifier on backlightBruckewell Technology Corp.
 
πίστη και επιστήμη B ΛΥΚΕΙΟΥ
πίστη και επιστήμη B ΛΥΚΕΙΟΥπίστη και επιστήμη B ΛΥΚΕΙΟΥ
πίστη και επιστήμη B ΛΥΚΕΙΟΥmariastou
 
Q3 fy15 earnings deck final
Q3 fy15 earnings deck finalQ3 fy15 earnings deck final
Q3 fy15 earnings deck finalCardinal_Health
 
WORKSHEET Nature Activities "Places to do nature physical activities" THIS S...
WORKSHEET  Nature Activities "Places to do nature physical activities" THIS S...WORKSHEET  Nature Activities "Places to do nature physical activities" THIS S...
WORKSHEET Nature Activities "Places to do nature physical activities" THIS S...Ciclos Formativos
 
Prediction of Consumer Purchase Decision using Demographic Variables: A Study...
Prediction of Consumer Purchase Decision using Demographic Variables: A Study...Prediction of Consumer Purchase Decision using Demographic Variables: A Study...
Prediction of Consumer Purchase Decision using Demographic Variables: A Study...IOSR Journals
 
Revisiting A Panicked Securitization Market
Revisiting A Panicked Securitization MarketRevisiting A Panicked Securitization Market
Revisiting A Panicked Securitization MarketIOSR Journals
 
Digital Marketing Guide for Hotels
Digital Marketing Guide for HotelsDigital Marketing Guide for Hotels
Digital Marketing Guide for HotelsPracticeNext
 
2015-04-29 research seminar
2015-04-29 research seminar2015-04-29 research seminar
2015-04-29 research seminarifi8106tlu
 
Health Care Delivery in Public Health Institutions in Contemporary Nigeria: A...
Health Care Delivery in Public Health Institutions in Contemporary Nigeria: A...Health Care Delivery in Public Health Institutions in Contemporary Nigeria: A...
Health Care Delivery in Public Health Institutions in Contemporary Nigeria: A...inventionjournals
 

Andere mochten auch (19)

How To Relieve Flying Anxiety
How To Relieve Flying AnxietyHow To Relieve Flying Anxiety
How To Relieve Flying Anxiety
 
קדושים 2
קדושים 2קדושים 2
קדושים 2
 
Nata
NataNata
Nata
 
Presentacion ing. industrial
Presentacion ing. industrialPresentacion ing. industrial
Presentacion ing. industrial
 
News Story 2 Interview Prep Sheet
News Story 2 Interview Prep SheetNews Story 2 Interview Prep Sheet
News Story 2 Interview Prep Sheet
 
SS6PU100 6A 100V Schottky Rectifier on backlight
SS6PU100 6A 100V Schottky Rectifier on backlightSS6PU100 6A 100V Schottky Rectifier on backlight
SS6PU100 6A 100V Schottky Rectifier on backlight
 
πίστη και επιστήμη B ΛΥΚΕΙΟΥ
πίστη και επιστήμη B ΛΥΚΕΙΟΥπίστη και επιστήμη B ΛΥΚΕΙΟΥ
πίστη και επιστήμη B ΛΥΚΕΙΟΥ
 
Informe encuestas
Informe encuestasInforme encuestas
Informe encuestas
 
Q3 fy15 earnings deck final
Q3 fy15 earnings deck finalQ3 fy15 earnings deck final
Q3 fy15 earnings deck final
 
A0610105
A0610105A0610105
A0610105
 
WORKSHEET Nature Activities "Places to do nature physical activities" THIS S...
WORKSHEET  Nature Activities "Places to do nature physical activities" THIS S...WORKSHEET  Nature Activities "Places to do nature physical activities" THIS S...
WORKSHEET Nature Activities "Places to do nature physical activities" THIS S...
 
Prediction of Consumer Purchase Decision using Demographic Variables: A Study...
Prediction of Consumer Purchase Decision using Demographic Variables: A Study...Prediction of Consumer Purchase Decision using Demographic Variables: A Study...
Prediction of Consumer Purchase Decision using Demographic Variables: A Study...
 
Revisiting A Panicked Securitization Market
Revisiting A Panicked Securitization MarketRevisiting A Panicked Securitization Market
Revisiting A Panicked Securitization Market
 
Digital Marketing Guide for Hotels
Digital Marketing Guide for HotelsDigital Marketing Guide for Hotels
Digital Marketing Guide for Hotels
 
Informatica
InformaticaInformatica
Informatica
 
King Of Buns
King Of BunsKing Of Buns
King Of Buns
 
2015-04-29 research seminar
2015-04-29 research seminar2015-04-29 research seminar
2015-04-29 research seminar
 
Health Care Delivery in Public Health Institutions in Contemporary Nigeria: A...
Health Care Delivery in Public Health Institutions in Contemporary Nigeria: A...Health Care Delivery in Public Health Institutions in Contemporary Nigeria: A...
Health Care Delivery in Public Health Institutions in Contemporary Nigeria: A...
 
Surge protection for LED Appliaction
Surge protection for LED AppliactionSurge protection for LED Appliaction
Surge protection for LED Appliaction
 

Ähnlich wie 4Developers 2015: Clean JavaScript code - only dream or reality - Sebastian Łaciak

Visual studio 2008
Visual studio 2008Visual studio 2008
Visual studio 2008Luis Enrique
 
Advance C++notes
Advance C++notesAdvance C++notes
Advance C++notesRajiv Gupta
 
Chapter i(introduction to java)
Chapter i(introduction to java)Chapter i(introduction to java)
Chapter i(introduction to java)Chhom Karath
 
Debugging and Profiling C++ Template Metaprograms
Debugging and Profiling C++ Template MetaprogramsDebugging and Profiling C++ Template Metaprograms
Debugging and Profiling C++ Template MetaprogramsPlatonov Sergey
 
Value Objects, Full Throttle (to be updated for spring TC39 meetings)
Value Objects, Full Throttle (to be updated for spring TC39 meetings)Value Objects, Full Throttle (to be updated for spring TC39 meetings)
Value Objects, Full Throttle (to be updated for spring TC39 meetings)Brendan Eich
 
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
 
"Optimization of a .NET application- is it simple ! / ?", Yevhen Tatarynov
"Optimization of a .NET application- is it simple ! / ?",  Yevhen Tatarynov"Optimization of a .NET application- is it simple ! / ?",  Yevhen Tatarynov
"Optimization of a .NET application- is it simple ! / ?", Yevhen TatarynovFwdays
 
2. Data, Operators, IO (5).ppt
2. Data, Operators, IO (5).ppt2. Data, Operators, IO (5).ppt
2. Data, Operators, IO (5).pptElisée Ndjabu
 
Kotlin Developer Starter in Android projects
Kotlin Developer Starter in Android projectsKotlin Developer Starter in Android projects
Kotlin Developer Starter in Android projectsBartosz Kosarzycki
 
Kotlin Developer Starter in Android - STX Next Lightning Talks - Feb 12, 2016
Kotlin Developer Starter in Android - STX Next Lightning Talks - Feb 12, 2016Kotlin Developer Starter in Android - STX Next Lightning Talks - Feb 12, 2016
Kotlin Developer Starter in Android - STX Next Lightning Talks - Feb 12, 2016STX Next
 
Node.js behind: V8 and its optimizations
Node.js behind: V8 and its optimizationsNode.js behind: V8 and its optimizations
Node.js behind: V8 and its optimizationsDawid Rusnak
 
OOP in C - Before GObject (Chinese Version)
OOP in C - Before GObject (Chinese Version)OOP in C - Before GObject (Chinese Version)
OOP in C - Before GObject (Chinese Version)Kai-Feng Chou
 
GSP 125 Entire Course NEW
GSP 125 Entire Course NEWGSP 125 Entire Course NEW
GSP 125 Entire Course NEWshyamuopten
 
Node Boot Camp
Node Boot CampNode Boot Camp
Node Boot CampTroy Miles
 

Ähnlich wie 4Developers 2015: Clean JavaScript code - only dream or reality - Sebastian Łaciak (20)

C++ idioms.pptx
C++ idioms.pptxC++ idioms.pptx
C++ idioms.pptx
 
Visual studio 2008
Visual studio 2008Visual studio 2008
Visual studio 2008
 
Advance C++notes
Advance C++notesAdvance C++notes
Advance C++notes
 
Chapter i(introduction to java)
Chapter i(introduction to java)Chapter i(introduction to java)
Chapter i(introduction to java)
 
Debugging and Profiling C++ Template Metaprograms
Debugging and Profiling C++ Template MetaprogramsDebugging and Profiling C++ Template Metaprograms
Debugging and Profiling C++ Template Metaprograms
 
Value Objects, Full Throttle (to be updated for spring TC39 meetings)
Value Objects, Full Throttle (to be updated for spring TC39 meetings)Value Objects, Full Throttle (to be updated for spring TC39 meetings)
Value Objects, Full Throttle (to be updated for spring TC39 meetings)
 
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”
 
2. data, operators, io
2. data, operators, io2. data, operators, io
2. data, operators, io
 
"Optimization of a .NET application- is it simple ! / ?", Yevhen Tatarynov
"Optimization of a .NET application- is it simple ! / ?",  Yevhen Tatarynov"Optimization of a .NET application- is it simple ! / ?",  Yevhen Tatarynov
"Optimization of a .NET application- is it simple ! / ?", Yevhen Tatarynov
 
2. Data, Operators, IO (5).ppt
2. Data, Operators, IO (5).ppt2. Data, Operators, IO (5).ppt
2. Data, Operators, IO (5).ppt
 
14 operator overloading
14 operator overloading14 operator overloading
14 operator overloading
 
Golang dot-testing-lite
Golang dot-testing-liteGolang dot-testing-lite
Golang dot-testing-lite
 
Kotlin Developer Starter in Android projects
Kotlin Developer Starter in Android projectsKotlin Developer Starter in Android projects
Kotlin Developer Starter in Android projects
 
Kotlin Developer Starter in Android - STX Next Lightning Talks - Feb 12, 2016
Kotlin Developer Starter in Android - STX Next Lightning Talks - Feb 12, 2016Kotlin Developer Starter in Android - STX Next Lightning Talks - Feb 12, 2016
Kotlin Developer Starter in Android - STX Next Lightning Talks - Feb 12, 2016
 
Node.js behind: V8 and its optimizations
Node.js behind: V8 and its optimizationsNode.js behind: V8 and its optimizations
Node.js behind: V8 and its optimizations
 
OOP in C - Before GObject (Chinese Version)
OOP in C - Before GObject (Chinese Version)OOP in C - Before GObject (Chinese Version)
OOP in C - Before GObject (Chinese Version)
 
C++ Question
C++ QuestionC++ Question
C++ Question
 
GSP 125 Entire Course NEW
GSP 125 Entire Course NEWGSP 125 Entire Course NEW
GSP 125 Entire Course NEW
 
C++ tutorials
C++ tutorialsC++ tutorials
C++ tutorials
 
Node Boot Camp
Node Boot CampNode Boot Camp
Node Boot Camp
 

Kürzlich hochgeladen

The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...
The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...
The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...kalichargn70th171
 
How to Choose the Right Laravel Development Partner in New York City_compress...
How to Choose the Right Laravel Development Partner in New York City_compress...How to Choose the Right Laravel Development Partner in New York City_compress...
How to Choose the Right Laravel Development Partner in New York City_compress...software pro Development
 
Diamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionDiamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionSolGuruz
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsArshad QA
 
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...OnePlan Solutions
 
Exploring the Best Video Editing App.pdf
Exploring the Best Video Editing App.pdfExploring the Best Video Editing App.pdf
Exploring the Best Video Editing App.pdfproinshot.com
 
10 Trends Likely to Shape Enterprise Technology in 2024
10 Trends Likely to Shape Enterprise Technology in 202410 Trends Likely to Shape Enterprise Technology in 2024
10 Trends Likely to Shape Enterprise Technology in 2024Mind IT Systems
 
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdfintroduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdfVishalKumarJha10
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVshikhaohhpro
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfkalichargn70th171
 
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) SolutionIntroducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) SolutionOnePlan Solutions
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Steffen Staab
 
8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech studentsHimanshiGarg82
 
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM TechniquesAI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM TechniquesVictorSzoltysek
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdfWave PLM
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comFatema Valibhai
 
AI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplateAI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplatePresentation.STUDIO
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfkalichargn70th171
 

Kürzlich hochgeladen (20)

The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...
The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...
The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...
 
How to Choose the Right Laravel Development Partner in New York City_compress...
How to Choose the Right Laravel Development Partner in New York City_compress...How to Choose the Right Laravel Development Partner in New York City_compress...
How to Choose the Right Laravel Development Partner in New York City_compress...
 
Diamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionDiamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with Precision
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview Questions
 
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
 
Exploring the Best Video Editing App.pdf
Exploring the Best Video Editing App.pdfExploring the Best Video Editing App.pdf
Exploring the Best Video Editing App.pdf
 
10 Trends Likely to Shape Enterprise Technology in 2024
10 Trends Likely to Shape Enterprise Technology in 202410 Trends Likely to Shape Enterprise Technology in 2024
10 Trends Likely to Shape Enterprise Technology in 2024
 
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdfintroduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
 
Microsoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdfMicrosoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdf
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTV
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
 
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS LiveVip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
 
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) SolutionIntroducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
 
8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students
 
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM TechniquesAI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.com
 
AI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplateAI & Machine Learning Presentation Template
AI & Machine Learning Presentation Template
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
 

4Developers 2015: Clean JavaScript code - only dream or reality - Sebastian Łaciak

  • 1. Clean JavaScript Code only dream or reality? Sebastian Łaciak
  • 2. • Clean Code • Node.js • Environment • Tests Support • Design Patterns Agenda
  • 4. C1: Inappropriate Information /** ------------------------------- REVISION HISTORY ------------- dd-mmm-yyyy <name> <problem number> <description> 06/01/99 Kowalski Andy initial */ C2: Obsolete Comments /* return sum of arguments */ function multiply(a, b) { return a * b; } C3: Redundant Comments /* multiply two numbers */ function multiply(a, b) { return a * b; } C4: Poorly Written Comments /* I had to write this comment due to checkstyle */ function add(a, b) { return a + b; } C5: Commented-Out Code /* function devide(a, b) { return a / b; } */ Comments
  • 5. E1: Build Requires More Than One Step mvn install E2: Tests Require More Than One Step karma start Environment
  • 6. G2: Obvious Behavior Is Unimplemented function getValue() { this.otherValue = null; counter = counter + 1; return counter; } G3: Incorrect Behavior at the Boundaries function getLastName() { return firstName; } G4: Overridden Safeties /** QUnit.test("should return sum of 1 and 3", function(assert) { assert.equal(this.calculator.add(1, 3), 4); }); }*/ General
  • 7. G5: Duplication DRY – Don’t repeat yourself G9: Dead Code G10: Vertical Separation function add(a, b) { AssertArg.notUndefined(a); AssertArg.notUndefined(b); return a + b; } G11: Inconsistency function setLastName(lName) { surName = lName; } General
  • 8. G20: Function Names Should Say What They Do function getValue() { this.otherValue = null; counter = counter + 1; return counter; } G25: Replace Magic Numbers with Named Constants var MONTH_APRIL = 3; General
  • 9. F1: Too Many Arguments function doSth(a,b,c,d,e,f,g,h) { … } F3: Flag Arguments function sort(ascOrder) {…} F4: Dead Function Functions
  • 10. N1: Choose Descriptive Names function doSth(a,b,c,d,e,f,g,h) {…} N5: Use Long Names for Long Scopes var pageDisplayCounter = 1; N7: Names Should Describe Side-Effects function getOrCreate() {…} Names
  • 11. T1: Insufficient Tests it("should return sum of 1 and 3", function() { var result = calculator.add(1, 3); }); T2: Use a Coverage Tool! T3: Don’t Skip Trivial Tests function setLastName(lName) { firstName = lName; } T6: Exhaustively Test Near Bugs T9: Tests Should Be Fast Tests
  • 13. Node.js® is a platform built on Chrome's JavaScript runtime for easily building fast, scalable network applications. Node.js uses an event-driven, non-blocking I/O model that makes it lightweight and efficient, perfect for data-intensive real-time applications that run across distributed devices. Node.js
  • 18. npm is a package manager for JavaScript, and is the default for Node.js. npm is bundled and installed automatically with the Node.js environment. npm runs through the command line and manages dependencies for an application. It also allows users to install Node.js applications that are available on the npm registry. Node Package Manager
  • 25. QUnit
  • 27. Mocks
  • 28. Mocks – QUnit with Sinon