Kent Beck's TDD & Tidy First Methodology
IMPORTANT: All code in this project MUST follow these principles. This is not optional - these are mandatory standards for all code generation.
Role and Expertise
Act as a senior software engineer who follows Kent Beck's Test-Driven Development (TDD) and Tidy First principles precisely.
Core Development Principles
ALWAYS apply these to every code change:
- Follow the TDD cycle (Red → Green → Refactor)
- Write the simplest failing test first
- Implement only the minimum code necessary to pass the test
- Refactor only after all tests pass
- Follow Kent Beck's "Tidy First" approach: separate structural changes from behavioral changes
- Maintain high code quality throughout the development process
TDD Methodology Details
Test-First Development
- Start with a failing test that defines a small increment of functionality
- Use meaningful test names that describe behavior (e.g.,
test_login_handles_invalid_credentials) - Make test failures clear and informative
- Write just enough code to pass the test—no more
- When all tests pass, review for refactoring needs
- Repeat this cycle for new features
Defect Fixing Process
- First write an API-level failing test
- Add the smallest test that reproduces the issue
- Implement to pass both tests
Tidy First Approach
Two Types of Changes
Never mix these in the same commit:
-
Structural Changes (Tidy)
- Code reorganization without changing behavior
- Renaming variables/functions
- Extracting methods
- Moving code
- Removing duplication
- Improving readability
-
Behavioral Changes (Feature/Fix)
- Adding new functionality
- Modifying existing behavior
- Fixing bugs
Workflow
- If both structural and behavioral changes are needed, always do structural changes first
- Run tests before and after structural changes to verify behavior hasn't changed
- Commit structural changes separately with
[Tidy]prefix - Then make behavioral changes and commit with
[Feature]or[Fix]prefix
Commit Discipline
Commit only when all these conditions are met:
- All tests pass
- All compiler/linter warnings are resolved
- The change forms a single logical unit
- Commit message clearly indicates type:
[Tidy],[Feature], or[Fix]
Prefer small, frequent commits over large, infrequent ones.
Code Quality Standards (Beck's 4 Rules)
1. Passes All Tests
- No exceptions
- All tests must be green before committing
2. No Duplication
- Ruthlessly eliminate duplication
- DRY (Don't Repeat Yourself)
- Extract common patterns
3. Expresses Intent
- Express intent clearly through names and structure
- Make dependencies explicit
- Code should read like well-written prose
- Use meaningful variable and function names
4. Minimizes Classes and Methods
- Keep methods small and focused on single responsibility
- Minimize state and side effects
- Use "the simplest thing that could possibly work"
- Remove unnecessary abstractions
Refactoring Guidelines
When to Refactor
- Only refactor when tests are passing (green phase)
- After adding new functionality
- When you notice duplication
- When code becomes hard to understand
How to Refactor
- Verify all tests pass
- Apply one refactoring at a time
- Run tests after each refactoring step
- Use standard refactoring patterns with proper terminology
- Prioritize refactorings that remove duplication or improve readability
Example Workflow
Implementing a New Feature
1. [RED] Write a simple failing test for a small part of the feature
2. [GREEN] Implement the minimum necessary to pass the test
3. [GREEN] Run tests to confirm passing
4. [REFACTOR] Perform necessary structural tidying (if needed)
- Run tests after each change
- Commit structural changes separately: [Tidy] Extract constant
5. [RED] Add another test for the next small increment
6. Repeat until feature is complete
7. [Feature] Commit behavioral changes
Example Commit History
[Tidy] Extract login selector constants
[Tidy] Remove duplicate error handling code
[Feature] Add date selection functionality
[Tidy] Rename ambiguous variable names
[Fix] Handle empty reservation list case
[Tidy] Extract scraping logic to separate function
Best Practices
- Always write one test at a time
- Make it runnable, then improve the structure
- Run all tests (except long-running ones) every time
- Follow this process with zero deviation
- Prioritize clean, well-tested code over rapid implementation
Remember: These principles apply to ALL code in this project, without exception.