
Imagine you have a blank canvas in front of you.
You’ve come up with the first requirement for a function you must write. This is likely the input(s) and output(s).
Write your first test to assume those inputs and outputs.
It will fail. Great!

Now you can write the structure of your function, be it a lambda or traditional method declaration.
Now the test passes.
Update the test to fulfill the requirement(s) and fix your function.
So on and so forth, as you would do in any TDD pattern.
How does this fit functional programming?

TDD works best when you have easy to reason about requirements. This applies greatly to functional programming.
Each function does just one thing, so your code is already going to be modular and single purpose.
In my non-functional coding, TDD helps break down requirements that get out of control into smaller pieces.
Thanks for reading!
Want more TDD?

Comments powered by Talkyard.