A Personal Exercise in Empirical Software Design
Kent Beck

#Tidy_First
#Software_Design
Messy code is a nuisance. "Tidying" code, to make it more readable, requires breaking it up into manageable sections. In this practical guide, author Kent Beck, creator of Extreme Programming and pioneer of software patterns, suggests when and where you might apply tidyings to improve your code while keeping the overall structure of the system in mind.
Instead of trying to master tidying all at once, this book lets you try out a few examples that make sense for your problem. If you have a big function containing many lines of code, you'll learn how to logically divide it into smaller chunks. Along the way, you'll learn the theory behind software design: coupling, cohesion, discounted cash flows, and optionality.
This book helps you:
Understand the basic theory of how software design works and the forces that act on it
Explore the difference between changes to a system's behavior and changes to its structure
Improve your programming experience by sometimes tidying first and sometimes tidying after
Learn how to make large changes in small, safe steps
Approach software design as an exercise in human relationships
Table of Contents
Part I. Tidyings
Chapter 1. Guard Clauses
Chapter 2. Dead Code
Chapter 3. Normalize Symmetries
Chapter 4. New Interface, Old Implementation
Chapter 5. Reading Order
Chapter 6. Cohesion Order
Chapter 7. Move Declaration and Initialization Together
Chapter 8. Explaining Variables
Chapter 9. Explaining Constants
Chapter 10. Explicit Parameters
Chapter 11 . Chunk Statements
Chapter 12. Extract Helper
Chapter 13. One Pile
Chapter 14. Explaining Comments
Chapter 15. Delete Redundant Comments
Part II. Managing
Chapter 16. Separate Tidying
Chapter 17. Chaining
Chapter 18. Batch Sizes
Chapter 19. Rhythm
Chapter 20. Getting Untangled
Chapter 21. First, After, Later, Never
Part Ill. Theory
Chapter 22. Beneficially Relating Elements
Chapter 23. Structure and Behavior
Chapter 24. Economics: Time Value and Optionality
Chapter 25. A Dollar Today> A Dollar Tomorrow
Chapter 26. Options
Chapter 27. Options Versus Cash Flows
Chapter 28. Reversible Structure Changes
Chapter 29. Coupling
Chapter 30. Constantine's Equivalence
Chapter 31 . Coupling Versus Decoupling
Chapter 32. Cohesion
Chapter 33. Conclusion
What is Tidy First?
“I have to change this code but it’s messy. What should I do next?”
“Maybe I should tidy the code before I make the change. Maybe. Some. Or maybe not.” These are questions you might ask yourself, and if there were an easy answer, I wouldn’t have to write a book to cover it.
Tidy First? describes:
When to tidy messy code before changing what it computes.
How to tidy messy code safely and efficiently.
How to stop tidying messy code.
Why tidying works.
Software design is an exercise in human relationships. In Tidy First? we start with the proverbial person in the mirror—with the programmer’s relationship with themself. Why don’t we take time to care for ourselves? Take time to make our work easier? Why do we go down the rabbithole of cleaning code to the exclusion of work that would help our users?
Tidy First? is the next step in my mission to help geeks feel safe in the world. It’s also the first step to take when addressing the common question posed above. Software design is a powerful tool to ease pain in the world—if it is used well. Used badly, it becomes just another instrument of oppression and becomes a drag on the effectiveness of software development.
By the end of this book, you will understand:
The fundamental difference between changes to the behavior of a system and changes to its structure.
The enabling magic of alternating investment in structure and investment in behavior, as a lone programmer changing code.
The basics of the theory of how software design works and the forces that act on it.
And you will be able to:
Improve your own experience of programming by sometimes tidying first (and sometimes tidy after).
Begin to make large changes in small, safe steps.
Approach software design as an exercise in human relationships
Audience
This book is meant for programmers, lead developers, hands-on software architects, and technical managers. It is not tied to any programming languages and all developers will also be able to read and apply the concepts in this book to their own projects. This book assumes that the reader is not new to programming in general.
About the Author
Kent Beck is a programmer, creator of Extreme Programming, pioneer of software patterns, coauthor of JUnit, rediscoverer of Test-Driven Development, and observer of 3X: Explore/Expand/Extract. Beck is also alphabetically the first signatory of the Agile Manifesto. He lives in San Francisco, California, and he is Chief Scientist at Mechanical Orchard, teaching skills to help geeks feel safe in the world.









