Do It Right the Second Time

TDD uses concrete examples to define behavior. Driving development from concrete examples is easier than thinking abstractly. It helps build more stable interfaces, and when we have two or three examples it’s far easier to generalize in the code than if we have a single example. I have a favorite saying:

Do it right the second time.

Developers sometimes look at me like I’m crazy when I say this. We’ve always been told to do it right the first time.

But when you do it right the first time—or think you’ve done it right the first time—you’re setting yourself up for a lot of extra work. It’s very hard to generalize with one example. Write concretely the first time if you only have one example, but when you get the second ...

Get Beyond Legacy Code now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.