Reliable Javascript: How to Code Safely in The World's Most Dangerous Language

In stock
Author : Lawrence D. Spencer, Seth H. Richards
Price : INR 699
ISBN 13 : 9788126557646
Pages : 528
Type : Paperbound

Reliable JavaScript, How to Code Safely in the World's Most Dangerous Language demonstrates how to create test-driven development for large-scale JavaScript applications that will stand the test of time and stay accurate through long-term use and maintenance. Taking a test-first approach to software architecture, this book walks you through several patterns and practices and explains what they are supposed to do by having you write unit tests. Write the code to pass the unit tests, so you not only develop your technique for structuring large-scale applications, but you also learn how to test your work.

Introduction

 

Part I: Laying A Solid Foundation

Chapter 1: Practicing Skillful Software

  • Writing Code that Starts Correct
  • Mastering the Features of JavaScript
  • Case Study: D3.js
  • JavaScript is Single-Threaded
  • Avoiding JavaScript's Pitfalls in Larger Systems
  • Scripts are not Modules
  • Nested Functions Control Scope
  • Coding by Contract
  • Applying the Principles of Software Engineering
  • The SOLID Principles
  • The DRY Principle
  • Writing Code that Stays Correct
  • Investing for the Future with Unit Tests
  • Practicing Test-Driven Development
  • Engineering Your Code to be Easy to Test

 

Chapter 2: Tooling Up

  • Using a Testing Framework
  • Identifying Incorrect Code
  • Designing for Testability
  • Writing the Minimum Required Code
  • Safe Maintenance and Refactoring
  • Runnable Specification
  • Current Open-Source and Commercial Frameworks
  • QUnit
  • D.O.H.
  • Introducing Jasmine
  • Suites and Specs
  • Expectations and Matchers
  • Spies
  • Using a Dependency-Injection Framework
  • What Is Dependency Injection?
  • Making Your Code More Reliable with Dependency Injection
  • Mastering Dependency Injection
  • Case Study: Writing a Lightweight Dependency-Injection Framework
  • Using a Dependency-Injection Framework
  • Current Dependency-Injection Frameworks
  • RequireJS
  • AngularJS
  • Using an Aspect Toolkit
  • Case Study: Caching with and without AOP
  • Implementing Caching without AOP
  • Making Your Code More Reliable with AOP
  • Case Study: Building the Aop.js Module
  • Other AOP Libraries
  • AspectJS
  • AopJS jQuery Plugin
  • YUI's Do Class
  • Conclusion
  • Using a Code-Checking Tool
  • Making Your Code More Reliable with Linting Tools
  • Introducing JSHint
  • Using JSHint
  • If You Don't Run It, Bugs will come
  • Alternatives to JSHint
  • JSLint
  • ESLint
  • Strict Mode

 

Chapter 3: Constructing Reliable Objects

  • Using Primitives
  • Using Object Literals
  • Using the Module Pattern
  • Creating Modules at Will
  • Creating Immediate Execution Modules
  • Creating Reliable Modules
  • Using Object Prototypes and Prototypal Inheritance
  • The Default Object Prototype
  • Prototypal Inheritance
  • Prototype Chains
  • Creating Objects with New
  • The new Object Creation Pattern
  • Potential for Bad Things to Happen
  • Enforcing the Use of new
  • Using Classical Inheritance
  • Emulating Classical Inheritance
  • Repetition Killed the Kangaroo
  • Using Functional Inheritance
  • Monkey Patching

 

Part II: Testing Pattern-Based Code

Chapter 4: Reviewing The Benefits of Patterns

  • Case Study
  • Producing More Elegant Code by Using a Broader Vocabulary
  • Producing Reliable Code with Well-Engineered, Well-Tested Building Blocks

 

Chapter 5: Ensuring Correct use of The Callback Pattern

  • Understanding the Pattern through Unit Tests
  • Writing and Testing Code that Uses Callback Functions
  • Writing and Testing Callback Functions
  • Avoiding Problems
  • Flattening the Callback Arrow
  • Minding this

 

Chapter 6: Ensuring Correct use of the Promise Pattern

  • Understanding Promises Through Unit Tests
  • Using a Promise
  • Constructing and Returning a Promise
  • Testing an XMLHttpRequest
  • Chaining Promises
  • Using a Promise Wrapper
  • Understanding States and Fates
  • Distinguishing Standard Promises from jQuery Promises

 

Chapter 7: Ensuring Correct use of Partial Function Application

  • Unit-Testing a Partial Function Application
  • Creating an Aspect for Partial Function Application
  • Distinguishing Between Partial Function Application and Currying
  • Currying
  • Partial Function Application

 

Chapter 8: Ensuring Correct use of The Memoization Pattern

  • Understanding the Pattern Through Unit Tests
  • Adding Memoization with AOP
  • Creating the Memoization Aspect
  • Applying the return Value Cache Aspect to restaurant API

 

Chapter 9: Ensuring Correct Implementation of The Singleton Pattern

  • Understanding the Pattern Through Unit Tests
  • Implementing a Singleton Shared Cache with an Object Literal
  • Implementing a Singleton Shared Cache with a Module

 

Chapter 10: Ensuring Correct Implementation of The Factory Pattern

  • Writing Unit Tests for a Factory
  • Implementing the Factory Pattern
  • Considering Other Factory Types

 

Chapter 11: Ensuring Correct Implementation and use of The Sandbox Pattern

  • Understanding the Pattern through Unit Tests
  • Creating a Widget Sandbox
  • Instantiating a Widget Sandbox
  • Providing Tools to the Widget via the Sandbox
  • Creating and Testing Sandbox Tools
  • Creating Functions for Use with a Sandbox

 

Chapter 12: Ensuring Correct Implementation of The Decorator Pattern

  • Developing a Decorator the Test Driven Way
  • Writing a Fake for the Decorated Object
  • Writing Tests for Pass Through of Errors
  • Writing a Do Nothing Decorator
  • Adding Pass Through Functionality to the Decorator
  • Verifying Pass Through of Successes
  • Adding the Decorator's Features
  • Generalizing the Decorator

 

Chapter 13: Ensuring Correct Implementation of The Strategy Pattern

  • Understanding the Pattern through Unit Tests
  • Implementing the transport scheduler Without the Strategy Pattern
  • Implementing the transport scheduler Using the Strategy Pattern  
  • Creating transport scheduler using Test Driven Development
  • Creating a Strategy for use with transport scheduler

 

Chapter 14: Ensuring Correct Implementation of The Proxy Pattern

  • Developing a Proxy the Test Driven Way

 

Chapter 15: Ensuring Correct Implementation of Chainable Methods

  • Understanding the Pattern Through Unit Tests
  • Chaining then

 

Part III: Testing and Writing with Advanced Javascript Features

Chapter 16: Conforming to Interfaces in An Interface-Free Language

  • Understanding the Benefits of Interfaces
  • Understanding the Interface Segregation Principle
  • Using Test-Driven Development to Create a Contract Registry
  • Defining a Contract
  • Determining Whether a Contract is Fulfilled
  • Asserting That a Contract is Fulfilled
  • Bypassing Contract Enforcement
  • Creating an Aspect to Enforce a Contract on a Returned (Created) Object

 

Chapter 17: Ensuring Correct Argument Types

  • Introduction
  • Understanding the Opportunities and Risks Posed by JavaScript's Type-Free Parameters
  • Extending the Contract Registry to Check Arguments
  • Scoping Out the Task
  • Determining Whether Every Variable in a Set Fulfills Its Contract
  • Asserting That Every Variable in a Set Fulfills Its Contract
  • Packaging Argument-Checking in an Aspect
  • Supporting Contract Libraries
  • Putting It All Together
  • Creating the Contracts Modules
  • Creating the Application's Contract Registry
  • Bypassing Contracts for Production  
  • Comparing the Aspect-Oriented Solution to a Static Solution
  • Considering the Advantages of Type Script
  • Considering the Advantages of Aspects

 

Chapter 18: Ensuring Correct Use of Call, Apply and Bind

  • Exploring How this is Bound
  • Default Binding
  • Default Binding and strict Mode
  • Implicit Binding
  • New Binding  
  • Explicit Binding
  • Creating and Testing Code That Uses call, apply and bind
  • Using call and apply
  • Creating an Array.prototype.forEach Polyfill Using Test-Driven Development
  • Using bind

 

Chapter 19: Ensuring The Correct use of Method borrowing

  • Ensuring the Borrowing Object is Suitable
  • Making the Borrowed Function Qualify the Borrower
  • Attaching an Aspect to the Borrowed Object
  • Using a borrow() Method
  • Adding an Object Validator to the Contract Registry
  • Anticipating Side Effects on the Borrower
  • Considering Side Effects from an Isolated Function
  • Considering Side Effects from a Function That Calls Other Functions
  • Anticipating Side Effects on the Donor Object

 

Chapter 20: Ensuring Correct use of Mixins

  • Creating and Using Mixins
  • Creating and Using a Traditional Mixin
  • Creating the extend Function Using Test driven Development
  • Creating a Traditional Mixin Using Test driven Development  
  • Creating and Using a Functional Mixin

 

Chapter 21: Testing Advanced Program Architectures

  • Ensuring Reliable Use of the Observer Pattern  
  • Examining the Observer Pattern
  • Enhancing the Reliability of the Observer Pattern
  • Ensuring Reliable Use of the Mediator Pattern
  • Examining the Mediator Pattern
  • Enhancing the Reliability of Mediator-Based Code
  • Developing a Colleague
  • Testing a Colleague
  • Segregating the Mediator's Interfaces
  • Deciding Where to Put the Contracts  
  • Ensuring the Colleague Gets a Mediator with the Expected Interface
  • Developing a Mediator
  • Testing the Mediator  

 

Part IV: Special Subjects In Testing

Chapter 22: Testing Advanced Program Architectures

  • Ensuring Reliable Use of the Observer Pattern  
  • Examining the Observer Pattern
  • Enhancing the Reliability of the Observer Pattern
  • Ensuring Reliable Use of the Mediator Pattern
  • Examining the Mediator Pattern
  • Enhancing the Reliability of Mediator-Based Code
  • Developing a Colleague
  • Testing a Colleague
  • Segregating the Mediator's Interfaces
  • Deciding Where to Put the Contracts  
  • Ensuring the Colleague Gets a Mediator with the Expected Interface
  • Developing a Mediator
  • Testing the Mediator

 

Chapter 23: Ensuring Conformance to Standards

  • Using ESLint
  • Installing ESLint  
  • Installing Node and npm
  • Installing ESLint using npm  
  • Running ESLint
  • Executing ESLint on a Single File
  • Executing ESLint on All the JavaScript Files in a Directory
  • Enforcing Coding Standards with ESLint
  • Creating a Custom ESLint Rule
  • Running ESLint with Custom Rules
  • Enforcing Architectural Divisions
  • The Family-Secret Technique  
  • The Imprinting Technique  
  • The Mission Impossible Technique
  • The Magic Wand Technique
  • Do Not Use the Call Stack Technique
  • Other Techniques
  • Other Architectures

 

Part V: Summary

Chapter 24: Summary Of The Principles of Test-Driven Development

  • Recalling Why Test-Driven Development is Worthwhile
  • Practicing Test-Driven Development
  • Writing Unit-Testable Code
  • Mastering the Mechanics of Test-Driven Development
  • Writing the Test Before the Code
  • Keeping Your Tests DRY
  • Testing Error Conditions First
  • Testing the Simple before the Complex
  • Being Specific
  • Testing Just One Thing
  • Your Test Data are Just as Important as the Test
  • Using Jasmine Effectively
  • Testing the Patterns in This Book
  • Testing Aspect-Oriented Programming
  • Testing Object Construction
  • Testing Callbacks
  • Testing Promise-Based Code
  • Testing a Partial Function Application
  • Testing Memoization
  • Testing a Singleton
  • Testing a Factory Method
  • Testing a Sandbox
  • Testing the Decorator Pattern
  • Testing the Strategy Pattern
  • Testing the Proxy Pattern
  • Testing Chainable Methods
  • Testing Conformance to an Interface
  • Testing the Use of call and apply
  • Testing the Method-Borrowing Pattern
  • Testing Mixins
  • Testing Mediators and Observers
  • Testing DOM Access
  • Tests to Enforce Architectural Divisions

 

Chapter 25: Summary of Javascript Idioms in this Book

  • Reviewing Objects
  • Object Properties May Be Added and Removed
  • Objects May Be used as a Dictionary
  • Reviewing Variables
  • Variable Declarations are Hoisted
  • Variables Have Function Scope
  • Reviewing Functions
  • Functions are Objects
  • Functions Declarations are Hoisted
  • Functions Don't Have Return Types
  • Functions May Be Anonymous
  • Functions May Be Nested
  • Functions May Be Invoked with Any Number of Arguments
  • Functions May Be Invoked Immediately
  • Reviewing Boolean Operations
  • Types May Be Coerced When Testing Equality
  • Values May Be Truthy or Falsy

 

Summary

Index

Larry Spencer is VP of ScerIS, Inc. a technology consulting company and has been developing on Microsoft platforms since 1986, as a programmer, manager, consultant and teacher. An engaging speaker, he has presented at New England Code Camp 16, The Architect Factory 3 and Tech Briefs. He has also taught programming, math, biology and chemistry in academic settings.

 

Seth Richards is lead software engineer at ScerIS and has been crafting software professionally since 2002. He got his start programming embedded devices for the bar and nightclub industry and transitioned to web application development in 2007. In the past he has worked on web-based, enterprise-class geographic information system applications. Seth graduated from Plymouth State College (now University) in Plymouth, NH, with a degree in Computer Science. 

 

Primary audience: developers who are using or want to use JavaScript for more than the traditional field validation and other snippets. Most of these developers will have years of experience in classical languages like C# or Java and are lately entering the JavaScript world. They may know about sound software-engineering principles (although it's surprising how many do not), but have no clue how to implement them in JavaScript.

Secondary audience: Development managers, even if they no longer code, should be familiar with the principles in this book in order to guide their teams; students.

 

Write Your Own Review
You're reviewing:Reliable Javascript: How to Code Safely in The World's Most Dangerous Language
"Prices are subject to change without prior notice" © 2017 Wiley India Pvt. Ltd. Wiley India editions are for sale in Indian subcontinent only.