Share E-Book
Scan to open this page

Scan with your phone to open this page

Author: Saleem Siddiqui

Rating No ratings yet

Your code is a testament to your skills as a developer. No matter what language you use, code should be clean, elegant, and uncluttered. By using test-driven development (TDD), you'll write code that's easy to understand, retains its elegance, and works for months, even years, to come. With this indispensable guide, you'll learn how to use TDD with three different languages: Go, JavaScript, and Python. Author Saleem Siddiqui shows you how to tackle domain complexity using a unit test-driven approach. TDD partitions requirements into small, implementable features, enabling you to solve problems irrespective of the languages and frameworks you use. With Learning Test-Driven Development at your side, you'll learn how to incorporate TDD into your regular coding practice. This book helps you: • Use TDD's divide-and-conquer approach to tame domain complexity • Understand how TDD works across languages, testing frameworks, and domain concepts • Learn how TDD enables continuous integration • Support refactoring and redesign with TDD • Learn how to write a simple and effective unit test harness in JavaScript • Set up a continuous integration environment with the unit tests produced during TDD • Write clean, uncluttered code using TDD in Go, JavaScript, and Python

AI Reading Assistant

Whole-book reading guide from stratified index samples; jump to passages in the text

AI guide
# Learning Test-Driven Development: A Polyglot Guide to Writing Uncluttered Code ## 【One-Line Pitch】 A hands-on, three-language (Go, JavaScript, Python) guide to mastering test-driven development through a single, progressively complex money-management project—perfect for developers who know basic programming and want to internalize TDD as a daily practice rather than a theoretical concept. ## 【Book Arc】 - **Opening (~0%–10%)**: Establishes why TDD matters despite decades of evidence supporting it, addresses common objections (fear, lack of guidance, schedule pressure), and positions the book for developers who already know at least one language—this is not a programming primer. - **Early (~10%–23%)**: Sets up the project structure (tdd-project with go/, js/, py/ folders), compares the three languages' testing ecosystems (Go's built-in testing, JavaScript's assert package, Python's unittest), and walks through the first Red-Green-Refactor (RGR) cycle with a simple Dollar class. - **Early (~23%–32%)**: Deepens the RGR practice by tackling the "money problem"—building a multicurrency spreadsheet tool—and demonstrates how to handle the refactoring stage, including removing duplication and logical coupling between tests and code. - **Middle (~32%–48%)**: Expands the domain model with Money objects carrying both amount and currency, introduces Portfolio as an aggregation concept, and shows how TDD guides design decisions (like overriding Python's __eq__ for value-based comparison). - **Middle (~48%–end)**: Continues through advanced topics including hash maps for currency conversion, error handling, and redesign—all driven by tests, with each chapter ending in a commit and a "Where We Are" checkpoint. ## 【Key Takeaways】 - **TDD is a skill to be learned, not a talent** (Early): The book explicitly addresses why developers avoid TDD—lack of awareness, fear, schedule pressure—and argues that like any skill, it requires deliberate practice and external support to master. - **The Red-Green-Refactor cycle is the core discipline** (Early): Every feature starts with a failing test (red), moves to minimal passing code (green), then cleans up duplication and coupling (refactor)—a rhythm that becomes smoother with repetition but never disappears. - **Hardcoding is a legitimate first step** (Early): The book shows you can reach green by returning a hardcoded "10 USD" value; the refactoring stage then reveals the subtle duplication between test and code, teaching you to see coupling that isn't obvious at first glance. - **Language differences shape TDD practice** (Early): Go's static typing and built-in testing package, JavaScript's dynamic typing with the assert package, and Python's unittest with __eq__ overrides—each language requires slightly different TDD approaches, and the book demonstrates all three side by side. - **Domain knowledge drives implementation choices** (Middle): When Go's integer division fails for fractional amounts, the fix isn't just changing types—it's recognizing that multipliers are integers (share counts) while amounts can be fractional (prices), then converting accordingly. - **Tests guide design, not just verification** (Middle): The Portfolio class emerges naturally from writing tests for adding multiple Money objects, showing how TDD helps you discover the abstractions your domain actually needs. - **Continuous integration is a natural TDD companion** (Throughout): The folder structure (tdd-project with separate language folders) is designed to support CI adoption, and each chapter ends with committing changes—making TDD and version control inseparable practices. ## 【Reading Tips】 - **Skim the language comparison tables** (Early): The Go/JavaScript/Python feature comparison (Table P-2) gives you a quick reference for how each language handles typing, exceptions, and testing—useful for deciding which language to follow first. - **Deep-read the first RGR cycle** (Early ~29%–32%): The first full cycle with the Dollar class is the most detailed and slowest-paced; master this and subsequent chapters move faster with less hand-holding. - **Follow one language, then the others**: The book's structure lets you follow Go, JavaScript, or Python consistently; pick one for your first pass, then return for the others to see how TDD principles translate across ecosystems. - **Pay attention to the "Where We Are" checkpoints**: Each chapter ends with a summary of what's been built and what's next—use these to orient yourself if you get lost in the details. - **Set up the project structure exactly as described**: The tdd-project folder with go/, js/, py/ subfolders and the TDD_PROJECT_ROOT environment variable will save you countless command-line headaches throughout the book. ## 【Coverage Limits】 This guide covers the book's opening through the middle sections (approximately 0–48%), including setup, the first RGR cycles, Money and Portfolio classes, and early refactoring. The later chapters on hash maps, error handling, and redesign are mentioned but not detailed. ##
Page 10
Everywhere. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 105 Making a Hash(map) of Things 105 Go 107 JavaScript 109 Python...
View in text
Excerpt 2
rose in this book is in the font-type used in this sentence. It is meant to be read and not entered verbatim as code. When there are words used in prose that...
View in text
Excerpt 3
s a script. 16 | Chapter 1: The Money Problem class Dollar: def __init__(self, amount): self.amount = amount def times(self, multiplier): return Dollar(10) T...
View in text
Excerpt 4
SD") self.assertEqual(tenDollars, fiveDollars.times(2)) We initialize fiveDollars and tenDollars explicitly. We then verify that multiplying the former by 2...
View in text
Excerpt 5
} add(...moneys) { this.moneys = this.moneys.concat(moneys); 73 } return Money; // test_money.js (one example usage) const m = require('./money'); let fiveDo...
View in text
Excerpt 6
est suite again: AssertionError: ... USD 17.00 != USD 15.00 Ah, much better! Seventeen dollars certainly isn’t the same thing as 15 dollars! Python’s F-strin...
View in text
Excerpt 7
ption("Missing exchange rate(s):[" + failureMessage + "]") If there are no failures, a new Money object with the correct amount and currency is returned. If...
View in text
Excerpt 8
returns a Money pointer and an error, we have to change how we assign these return values to variables and how we assert them. Here’s how our TestAddition lo...
View in text
Tags
AI categories
ProgrammingGoJavaScript
ISBN: 1098106474
Publisher: O'Reilly Media
Publish Year: 2021
Language: English
Pages: 280
File Format: PDF
File Size: 9.7 MB
Text Preview (First 20 pages)
Registered users can read the full content for free

Register as a Gaohf Library member to read the complete e-book online for free and enjoy a better reading experience.

Generating text preview…