Clean JavaScript. English Edition
Clean JavaScript. English Edition
A concise guide to learning Clean Code, SOLID and Unit Testing
About the Book
JavaScript is now one of the most popular programming languages in the world. It is used in the critical infrastructures of many very important companies like Facebook, Netflix or Uber.
This is why writing better, higher quality and clearly legible code has become essential. Normally, developers write code without the explicit intention of making it easily understood by other people because we are focused on finding a solution that works and solves the problem without thinking about people. Usually, trying to understand the code written by other programmers or even code that we wrote ourselves a few weeks ago, can be quite difficult.
This small e-book strives to be a concise reference of how to apply clean code, SOLID, unit testing and TDD, to be able to write more legible, maintainable and change tolerant JavaScript code. In this book you will find several references to other authors and simple examples that will help you to find the way to become a better developer.
Table of Contents
-
Preface
- What this book is not.
- About the author
- Introduction
-
Technical Debt
- Kinds of technical debt
- Refactoring, debts are paid
- Prevention is better than cure, the rules of simple design
- Section I: Clean Code
- What is Clean Code?
-
Variables, names and scope
- Correct use of var, let y const
- Pronounceable and expressive names
- Absence of technical information in the names
- Establish a ubiquitous language
- Names by data type
- Numbers
- Scope of the variables
-
Functions
- Function declaration
- Function Expression
- Function expression with the arrow function
- Immediately-invoked Function Expressions (IIFE)
- Parameters and arguments
- Indentation size and levels
- Declarative vs imperative style
- Anonymous functions
- Referential transparency
- DRY Principle
- Command–Query Separation (CQS)
- Efficient algorithms
-
Classes
- Prototype and modern ECMAScript
- Reduced size
- Organization
- Prioritize composition over inheritance
-
Comments and format
- Avoid using comments
- Consistent format
- Section II: SOLID Principles
- Introduction to SOLID
-
From STUPID to SOLID
- What is code smell?
- Singleton pattern
- Tight Coupling
- Premature optimization
- Indescriptive Naming
- Duplication
- SOLID principles to the rescue
-
Single responsibility principle (SRP)
- What do we understand by responsibility?
- Applying the SRP
- Detecting violations of SRP
-
OCP - Open/Closed principle
- Applying OCP
- Adapter pattern
- Detect violations of OCP
-
LSP - Liskov Substitution Principle
- Applying LSP
- Detect violations of LSP
-
ISP - Interface segregation principle
- Applying the ISP
- Detect violation of ISP
-
DIP - Dependency Inversion Principle
- High-level modules and low-level modules
- Depending on Abstractions
- Dependency Injection
- Applying DIP
- Detecting violations of DIP
- Section III: Testing & TDD
- Introduction to testing
-
Types of software tests
- What do we understand by testing?
- Manual tests vs automatic tests
- Functional vs non-functional tests
- Non-functional tests
- The Pyramid of testing
- Ice Cream cone anti-pattern
-
Unit testing
- Characteristics of the unit tests
- Anatomy of a unit test
-
Jest, the definitive JavaScript testing framework
- Features
- Installation and configuration
- Our first test
- Asserts
- Organisation and structure
- State management: before and after
- Code coverage
-
TDD - Test Driven Development
- The three laws of TDD
- Red-Green-Refactor cycle
- TDD as a design tool
- Implementation strategies, from red to green
- TDD Limitations
-
Practical TDD: The FizzBuzz Kata
- The code katas
- The Fizzbuzz kata
- Exercise statement
- Designing the first test
- We run and… red!
- We go green
- Adding new tests
- Refactoring the solution, applying pattern matching.
- References
The Leanpub 60 Day 100% Happiness Guarantee
Within 60 days of purchase you can get a 100% refund on any Leanpub purchase, in two clicks.
Now, this is technically risky for us, since you'll have the book or course files either way. But we're so confident in our products and services, and in our authors and readers, that we're happy to offer a full money back guarantee for everything we sell.
You can only find out how good something is by trying it, and because of our 100% money back guarantee there's literally no risk to do so!
So, there's no reason not to click the Add to Cart button, is there?
See full terms...
Earn $8 on a $10 Purchase, and $16 on a $20 Purchase
We pay 80% royalties on purchases of $7.99 or more, and 80% royalties minus a 50 cent flat fee on purchases between $0.99 and $7.98. You earn $8 on a $10 sale, and $16 on a $20 sale. So, if we sell 5000 non-refunded copies of your book for $20, you'll earn $80,000.
(Yes, some authors have already earned much more than that on Leanpub.)
In fact, authors have earnedover $14 millionwriting, publishing and selling on Leanpub.
Learn more about writing on Leanpub
Free Updates. DRM Free.
If you buy a Leanpub book, you get free updates for as long as the author updates the book! Many authors use Leanpub to publish their books in-progress, while they are writing them. All readers get free updates, regardless of when they bought the book or how much they paid (including free).
Most Leanpub books are available in PDF (for computers) and EPUB (for phones, tablets and Kindle). The formats that a book includes are shown at the top right corner of this page.
Finally, Leanpub books don't have any DRM copy-protection nonsense, so you can easily read them on any supported device.
Learn more about Leanpub's ebook formats and where to read them