Download - Better Functional Design through TDD
![Page 1: Better Functional Design through TDD](https://reader031.vdocuments.net/reader031/viewer/2022020217/55568374d8b42a182f8b48d7/html5/thumbnails/1.jpg)
Better Functional Design through TDD
Phil Calçado – SoundCloud@pcalcado
http://philcalcado.com
![Page 2: Better Functional Design through TDD](https://reader031.vdocuments.net/reader031/viewer/2022020217/55568374d8b42a182f8b48d7/html5/thumbnails/2.jpg)
This talk is not about how.
![Page 3: Better Functional Design through TDD](https://reader031.vdocuments.net/reader031/viewer/2022020217/55568374d8b42a182f8b48d7/html5/thumbnails/3.jpg)
http://www.flickr.com/photos/doug88888/4507077583/
Clojure TDD demo by Brian Marickhttp://bit.ly/sjCJBm
![Page 4: Better Functional Design through TDD](https://reader031.vdocuments.net/reader031/viewer/2022020217/55568374d8b42a182f8b48d7/html5/thumbnails/4.jpg)
This talk is not about how.
It is about why.
![Page 5: Better Functional Design through TDD](https://reader031.vdocuments.net/reader031/viewer/2022020217/55568374d8b42a182f8b48d7/html5/thumbnails/5.jpg)
The LondonSchool
http://www.flickr.com/photos/doug88888/4507077583/
![Page 6: Better Functional Design through TDD](https://reader031.vdocuments.net/reader031/viewer/2022020217/55568374d8b42a182f8b48d7/html5/thumbnails/6.jpg)
1.Write a failing functional test2.Mark it as Work-in-progress3.Write a failing unit or integration test4.Make it pass5.Refactor6.Repeat steps 3 to 5 until your functional test passes
http://www.flickr.com/photos/doug88888/4507077583/
The London School
![Page 7: Better Functional Design through TDD](https://reader031.vdocuments.net/reader031/viewer/2022020217/55568374d8b42a182f8b48d7/html5/thumbnails/7.jpg)
http://amzn.to/vZv4Yw
![Page 8: Better Functional Design through TDD](https://reader031.vdocuments.net/reader031/viewer/2022020217/55568374d8b42a182f8b48d7/html5/thumbnails/8.jpg)
What Is the Point of Test-Driven Development?
![Page 9: Better Functional Design through TDD](https://reader031.vdocuments.net/reader031/viewer/2022020217/55568374d8b42a182f8b48d7/html5/thumbnails/9.jpg)
1.Software development is a learning process
![Page 10: Better Functional Design through TDD](https://reader031.vdocuments.net/reader031/viewer/2022020217/55568374d8b42a182f8b48d7/html5/thumbnails/10.jpg)
2.Feedback is the Fundamental tool
![Page 11: Better Functional Design through TDD](https://reader031.vdocuments.net/reader031/viewer/2022020217/55568374d8b42a182f8b48d7/html5/thumbnails/11.jpg)
3.Practices that supportchange
![Page 12: Better Functional Design through TDD](https://reader031.vdocuments.net/reader031/viewer/2022020217/55568374d8b42a182f8b48d7/html5/thumbnails/12.jpg)
But that is Development.What about Design?
![Page 13: Better Functional Design through TDD](https://reader031.vdocuments.net/reader031/viewer/2022020217/55568374d8b42a182f8b48d7/html5/thumbnails/13.jpg)
http://amzn.to/vZv4Yw
![Page 14: Better Functional Design through TDD](https://reader031.vdocuments.net/reader031/viewer/2022020217/55568374d8b42a182f8b48d7/html5/thumbnails/14.jpg)
“There are three aspects of TDD that help us achieve [good design]:
![Page 15: Better Functional Design through TDD](https://reader031.vdocuments.net/reader031/viewer/2022020217/55568374d8b42a182f8b48d7/html5/thumbnails/15.jpg)
First, starting with a test means that we have to describe what we want to achieve before we consider how. This focus helps us maintain the right level of abstraction.
![Page 16: Better Functional Design through TDD](https://reader031.vdocuments.net/reader031/viewer/2022020217/55568374d8b42a182f8b48d7/html5/thumbnails/16.jpg)
“Write code in terms of the problem's data types, not the types
that happen to be in the implementation.”
Peter Norvig, Good Lisp Programming Style - http://bit.ly/u6JTPt
![Page 17: Better Functional Design through TDD](https://reader031.vdocuments.net/reader031/viewer/2022020217/55568374d8b42a182f8b48d7/html5/thumbnails/17.jpg)
![Page 18: Better Functional Design through TDD](https://reader031.vdocuments.net/reader031/viewer/2022020217/55568374d8b42a182f8b48d7/html5/thumbnails/18.jpg)
Reverse engineering.
![Page 19: Better Functional Design through TDD](https://reader031.vdocuments.net/reader031/viewer/2022020217/55568374d8b42a182f8b48d7/html5/thumbnails/19.jpg)
![Page 20: Better Functional Design through TDD](https://reader031.vdocuments.net/reader031/viewer/2022020217/55568374d8b42a182f8b48d7/html5/thumbnails/20.jpg)
Lots of how. Not so much what or why.
![Page 21: Better Functional Design through TDD](https://reader031.vdocuments.net/reader031/viewer/2022020217/55568374d8b42a182f8b48d7/html5/thumbnails/21.jpg)
![Page 22: Better Functional Design through TDD](https://reader031.vdocuments.net/reader031/viewer/2022020217/55568374d8b42a182f8b48d7/html5/thumbnails/22.jpg)
![Page 23: Better Functional Design through TDD](https://reader031.vdocuments.net/reader031/viewer/2022020217/55568374d8b42a182f8b48d7/html5/thumbnails/23.jpg)
To ensure that you say what you mean:1.Start with an English description of the algorithm2.Write the code from the description3.Translate the code back to English4.Compare 3 to 1
Peter Norvig, Good Lisp Programming Style - http://bit.ly/u6JTPt
![Page 25: Better Functional Design through TDD](https://reader031.vdocuments.net/reader031/viewer/2022020217/55568374d8b42a182f8b48d7/html5/thumbnails/25.jpg)
Second, to keep tests understandable and maintainable, we limit their scope. Tests that are dozens of lines long tell us that the component they’re testing is too large and needs breaking up into smaller components.
![Page 26: Better Functional Design through TDD](https://reader031.vdocuments.net/reader031/viewer/2022020217/55568374d8b42a182f8b48d7/html5/thumbnails/26.jpg)
“Break the problem into parts. Design useful subparts. Be
opportunistic.”
Peter Norvig, Good Lisp Programming Style - http://bit.ly/u6JTPt
![Page 27: Better Functional Design through TDD](https://reader031.vdocuments.net/reader031/viewer/2022020217/55568374d8b42a182f8b48d7/html5/thumbnails/27.jpg)
![Page 28: Better Functional Design through TDD](https://reader031.vdocuments.net/reader031/viewer/2022020217/55568374d8b42a182f8b48d7/html5/thumbnails/28.jpg)
Reverse engineering.
![Page 29: Better Functional Design through TDD](https://reader031.vdocuments.net/reader031/viewer/2022020217/55568374d8b42a182f8b48d7/html5/thumbnails/29.jpg)
![Page 30: Better Functional Design through TDD](https://reader031.vdocuments.net/reader031/viewer/2022020217/55568374d8b42a182f8b48d7/html5/thumbnails/30.jpg)
Way too much stuff going on.
![Page 31: Better Functional Design through TDD](https://reader031.vdocuments.net/reader031/viewer/2022020217/55568374d8b42a182f8b48d7/html5/thumbnails/31.jpg)
Every function should have:●A single specific purpose●If possible, a generally useful purpose●A meaningful name●A structure that is simple to understand●An interface that is simple yet general enough
Peter Norvig, Good Lisp Programming Style - http://bit.ly/u6JTPt
![Page 32: Better Functional Design through TDD](https://reader031.vdocuments.net/reader031/viewer/2022020217/55568374d8b42a182f8b48d7/html5/thumbnails/32.jpg)
![Page 33: Better Functional Design through TDD](https://reader031.vdocuments.net/reader031/viewer/2022020217/55568374d8b42a182f8b48d7/html5/thumbnails/33.jpg)
![Page 34: Better Functional Design through TDD](https://reader031.vdocuments.net/reader031/viewer/2022020217/55568374d8b42a182f8b48d7/html5/thumbnails/34.jpg)
Third, to prepare a component for a unit test, we have to pass its dependencies to it, which means that we have to know what they are. A component with implicit (or just too many) dependencies is painful to test.”
![Page 35: Better Functional Design through TDD](https://reader031.vdocuments.net/reader031/viewer/2022020217/55568374d8b42a182f8b48d7/html5/thumbnails/35.jpg)
“Determine dependencies. Re-modularise to reduce
dependencies. Design most dependent parts first.”
Peter Norvig, Good Lisp Programming Style - http://bit.ly/u6JTPt
![Page 36: Better Functional Design through TDD](https://reader031.vdocuments.net/reader031/viewer/2022020217/55568374d8b42a182f8b48d7/html5/thumbnails/36.jpg)
![Page 37: Better Functional Design through TDD](https://reader031.vdocuments.net/reader031/viewer/2022020217/55568374d8b42a182f8b48d7/html5/thumbnails/37.jpg)
Introduce similar feature.
![Page 38: Better Functional Design through TDD](https://reader031.vdocuments.net/reader031/viewer/2022020217/55568374d8b42a182f8b48d7/html5/thumbnails/38.jpg)
![Page 39: Better Functional Design through TDD](https://reader031.vdocuments.net/reader031/viewer/2022020217/55568374d8b42a182f8b48d7/html5/thumbnails/39.jpg)
Make it green.
![Page 40: Better Functional Design through TDD](https://reader031.vdocuments.net/reader031/viewer/2022020217/55568374d8b42a182f8b48d7/html5/thumbnails/40.jpg)
![Page 41: Better Functional Design through TDD](https://reader031.vdocuments.net/reader031/viewer/2022020217/55568374d8b42a182f8b48d7/html5/thumbnails/41.jpg)
Make it better.
![Page 42: Better Functional Design through TDD](https://reader031.vdocuments.net/reader031/viewer/2022020217/55568374d8b42a182f8b48d7/html5/thumbnails/42.jpg)
![Page 43: Better Functional Design through TDD](https://reader031.vdocuments.net/reader031/viewer/2022020217/55568374d8b42a182f8b48d7/html5/thumbnails/43.jpg)
![Page 44: Better Functional Design through TDD](https://reader031.vdocuments.net/reader031/viewer/2022020217/55568374d8b42a182f8b48d7/html5/thumbnails/44.jpg)
Evolving to closuresand combinators:
http://bit.ly/sTF5Nl
![Page 45: Better Functional Design through TDD](https://reader031.vdocuments.net/reader031/viewer/2022020217/55568374d8b42a182f8b48d7/html5/thumbnails/45.jpg)
I see strong correlation between good design
and test-driven development.
![Page 46: Better Functional Design through TDD](https://reader031.vdocuments.net/reader031/viewer/2022020217/55568374d8b42a182f8b48d7/html5/thumbnails/46.jpg)
Code which is coupled and complicated is
bad design
![Page 47: Better Functional Design through TDD](https://reader031.vdocuments.net/reader031/viewer/2022020217/55568374d8b42a182f8b48d7/html5/thumbnails/47.jpg)
Code which is coupled and complicated is
hard to maintain
![Page 48: Better Functional Design through TDD](https://reader031.vdocuments.net/reader031/viewer/2022020217/55568374d8b42a182f8b48d7/html5/thumbnails/48.jpg)
Code which is coupled and complicated ishard to test