DEV Community

Discussion on: I'm Sandi Metz, Ask Me Anything! [Finished]

Collapse
 
restoreddev profile image
Andrew Davis

Hi Sandi, thanks for doing this AMA. When you code, do you follow TDD religiously? I like to write tests, but have a hard time writing tests before functionality, so I tend to write tests after the fact. What downsides do you see to writing tests second?

Collapse
 
sandimetz profile image
Sandi Metz • Edited

Andrew, this is my pleasure.
Ah, TDD. I find my code turns out better if I write tests first, but I am deeply sympathetic about how hard that can be. Writing tests first can help drive you to create decoupled code. If you write tests 2nd, and then find that the tests have complicated setup, this suggests that your code is too tightly coupled together. If you write tests first, and insist on having simple setup, you'll naturally end up with nicely decoupled code.

Collapse
 
restoreddev profile image
Andrew Davis

That makes sense, thanks!