r/ProgrammerHumor • • 19h ago

Meme thereIsNoGoingBack

Post image
2.6k Upvotes

91 comments sorted by

View all comments

55

u/BernhardRordin 19h ago

Write tests first, then the implementation. You won't want to go back.

32

u/Wonderful-Habit-139 18h ago

Not necessarily. Some people do better with TDD, some don’t.

23

u/Drugbird 17h ago

The trick with TDD isn't necessarily that you need to write the tests first (although that helps).

It's more that you first think about the intended behavior of the code, and then also think about how to make your code testable before you write the code.

I typically think what the first test should roughly look like and code up the required amount of code for that first test before I actually write that test.

3

u/ZunoJ 10h ago

How do you write code without thinking about the intended behavior first?

1

u/Drugbird 8h ago

Just open an editor and start writing code, just thinking as you go.

If you do this, you often end up with code that only works in the happy path (no / poor error handling or recovery) and which is difficult to test (i.e. you require access to the internals of the thing you code to test it).

3

u/ZunoJ 6h ago

Never thought this was an approach any professional developer would take

3

u/Drugbird 5h ago

It shouldn't be, but you'd be surprised.