SlideShare una empresa de Scribd logo
1 de 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

Más contenido relacionado

La actualidad más candente

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
 

La actualidad más candente (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
 

Destacado

πίστη και επιστήμη B ΛΥΚΕΙΟΥ
πίστη και επιστήμη B ΛΥΚΕΙΟΥπίστη και επιστήμη B ΛΥΚΕΙΟΥ
πίστη και επιστήμη B ΛΥΚΕΙΟΥ
mariastou
 
Q3 fy15 earnings deck final
Q3 fy15 earnings deck finalQ3 fy15 earnings deck final
Q3 fy15 earnings deck final
Cardinal_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
 

Destacado (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
 

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

Visual studio 2008
Visual studio 2008Visual studio 2008
Visual studio 2008
Luis Enrique
 
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
 

Similar a 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
 

Último

+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
Health
 
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
The title is not connected to what is inside
The title is not connected to what is insideThe title is not connected to what is inside
The title is not connected to what is inside
shinachiaurasa2
 
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
masabamasaba
 
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
masabamasaba
 
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
masabamasaba
 

Último (20)

Architecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the pastArchitecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the past
 
WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?
 
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park %in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
 
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
 
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
 
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park %in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
 
The title is not connected to what is inside
The title is not connected to what is insideThe title is not connected to what is inside
The title is not connected to what is inside
 
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-...
 
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
 
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
Microsoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdfMicrosoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdf
 
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
 
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
 
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
Direct Style Effect Systems -The Print[A] Example- A Comprehension AidDirect Style Effect Systems -The Print[A] Example- A Comprehension Aid
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
 
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
 
AI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplateAI & Machine Learning Presentation Template
AI & Machine Learning Presentation Template
 

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