better functional design through tdd

50
Better Functional Design through TDD Phil Calçado – SoundCloud @pcalcado http://philcalcado.com

Upload: phil-calcado

Post on 16-May-2015

5.482 views

Category:

Technology


1 download

TRANSCRIPT

Page 1: Better Functional Design through TDD

Better Functional Design through TDD

Phil Calçado – SoundCloud@pcalcado

http://philcalcado.com

Page 2: Better Functional Design through TDD

This talk is not about how.

Page 3: Better Functional Design through TDD

http://www.flickr.com/photos/doug88888/4507077583/

Clojure TDD demo by Brian Marickhttp://bit.ly/sjCJBm

Page 4: Better Functional Design through TDD

This talk is not about how.

It is about why.

Page 5: Better Functional Design through TDD

The LondonSchool

http://www.flickr.com/photos/doug88888/4507077583/

Page 6: Better Functional Design through TDD

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

http://amzn.to/vZv4Yw

Page 8: Better Functional Design through TDD

What Is the Point of Test-Driven Development?

Page 9: Better Functional Design through TDD

1.Software development is a learning process

Page 10: Better Functional Design through TDD

2.Feedback is the Fundamental tool

Page 11: Better Functional Design through TDD

3.Practices that supportchange

Page 12: Better Functional Design through TDD

But that is Development.What about Design?

Page 13: Better Functional Design through TDD

http://amzn.to/vZv4Yw

Page 14: Better Functional Design through TDD

“There are three aspects of TDD that help us achieve [good design]:

Page 15: Better Functional Design through TDD

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

“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
Page 18: Better Functional Design through TDD

Reverse engineering.

Page 19: Better Functional Design through TDD
Page 20: Better Functional Design through TDD

Lots of how. Not so much what or why.

Page 21: Better Functional Design through TDD
Page 22: Better Functional Design through TDD
Page 23: Better Functional Design through TDD

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 24: Better Functional Design through TDD

On the (over-)usage of maps

http://bit.ly/sNSVz9

Page 25: Better Functional Design through TDD

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

“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
Page 28: Better Functional Design through TDD

Reverse engineering.

Page 29: Better Functional Design through TDD
Page 30: Better Functional Design through TDD

Way too much stuff going on.

Page 31: Better Functional Design through TDD

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
Page 33: Better Functional Design through TDD
Page 34: Better Functional Design through TDD

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

“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
Page 37: Better Functional Design through TDD

Introduce similar feature.

Page 38: Better Functional Design through TDD
Page 39: Better Functional Design through TDD

Make it green.

Page 40: Better Functional Design through TDD
Page 41: Better Functional Design through TDD

Make it better.

Page 42: Better Functional Design through TDD
Page 43: Better Functional Design through TDD
Page 44: Better Functional Design through TDD

Evolving to closuresand combinators:

http://bit.ly/sTF5Nl

Page 45: Better Functional Design through TDD

I see strong correlation between good design

and test-driven development.

Page 46: Better Functional Design through TDD

Code which is coupled and complicated is

bad design

Page 47: Better Functional Design through TDD

Code which is coupled and complicated is

hard to maintain

Page 48: Better Functional Design through TDD

Code which is coupled and complicated ishard to test

Page 49: Better Functional Design through TDD

http://xkcd.com/552/

Page 50: Better Functional Design through TDD

http://soundcloud.com/jobs