Lambda The Extreme: Test-Driving a Functional Language

Post on 14-Sep-2014

111 views 0 download

Tags:

description

Functional languages like Scala can reduce the complexity of writing high-concurrency, high-throughput systems, but growing software with TDD in Scala presents challenges unfamiliar to those of us who spend most of our time in the JavaScript, Java, and .NET worlds. In this session at Agile2014, Tim Myer explained how to avoid the pitfalls of testing a functional language and offered some new techniques that you can apply to development in other languages, even if you have never written software using Scala before.

Transcript of Lambda The Extreme: Test-Driving a Functional Language

Copyright © 2014 SolutionsIQ Inc. All rights reserved.

6801 185th Ave NE, Suite 200Redmond, WA 98052solutionsiq.com1.800.235.4091

λ the eχtremetest-driving a functional language

07/30/2014

PREPARED BYTim MyerProgrammertmyer@solutionsiq.com

2

SolutionsIQ

Λ Join a great team of developers, consultants and Agile experts at a company that is Agile through and through.

Λ We are hiring XP developers and coaches.

Λ Swing by our booth or talk to me afterwards for more information.

λ the eχtreme: test-driving a functional language

3

λ the eχtreme: test-driving a functional language

Scala: you stare at your foot for 3 days without any sleep, you then figrue [sic] out how to shoot yourself in the foot with one line of code… recursively.

Comment from Roberto Leibman on How to Shoot Yourself in the Foot in Any Programming Language

by Mike Walker

4λ the eχtreme: test-driving a functional language

AgendaΛ Tools of the TradeΛ First testΛ A synchronicityΛ Network independenceΛ More of the sameΛ Changing StationΛ And so on and so forth and so on….

5λ the eχtreme: test-driving a functional language

Prelude

6

The Little Schemer

λ the eχtreme: test-driving a functional language

7

”λ the eχtreme: test-driving a functional language

if you look at the features Scala provides, it is substantially a

functional language, but on the surface it does not always look

like one, and it does not force you to adopt the functional style.

For many of its users, the functional programming constructs in

Scala are the most important set of tools it has to offer but they

are not the only tools. In fact, great care has been spent in the

Scala design to make functional constructs, imperative

constructs, and objects all play well together. I think

postfunctional is a good term for that blend.

- Martin OderskyA Postfunctional Language

8λ the eχtreme: test-driving a functional language

Tools

Λ Git

Λ Maven

Λ Scala IDE

Λ A Dropbox account

9

TheBeginning

Where do we start?

We can start atTheBeginning.

λ the eχtreme: test-driving a functional language

How can we dothat?

Check it out!

10λ the eχtreme: test-driving a functional language

$ git clone https://github.com/timezra/LambdaTheExtreme.git && cd LambdaTheExtreme $ git checkout tags/TheBeginning

11

TheBeginning

We got git, now do we get an elephant?

We get a canary instead.

λ the eχtreme: test-driving a functional language

12λ the eχtreme: test-driving a functional language

Canary

13

Canary

What does a canaryhave to do with this?

It’s an earlyindication thatsomething has gone very wrong.

λ the eχtreme: test-driving a functional language

14λ the eχtreme: test-driving a functional language

$ git checkout tags/Canary

15λ the eχtreme: test-driving a functional language

Interlude

16λ the eχtreme: test-driving a functional language

Recap

Λ A Case Class

Λ An Object

Λ A FeatureSpec

Λ A FunSpec!

17

Canary

Can our canary getaccount info?

Only with aDropbox account.

λ the eχtreme: test-driving a functional language

18λ the eχtreme: test-driving a functional language

Actors

19

Actors

What happenswhen our accountinfo changes?

Our expectation is wrong.

λ the eχtreme: test-driving a functional language

What happenswhen we changeour expectation?

Our test fails.

20

Actors

Why does it fail?

Ourimplementation is wrong.

λ the eχtreme: test-driving a functional language

Where do we findthe rightimplementation?

Look in the upperleft.

21λ the eχtreme: test-driving a functional language

$ git checkout tags/Actors

22

Actors

How can we callDropbox?

Using HTTP

λ the eχtreme: test-driving a functional language

How will Dropbox know us?

We’ll give it atoken.

23

Actors

When will we getour account info?

In the future!

λ the eχtreme: test-driving a functional language

24λ the eχtreme: test-driving a functional language

Interlude

25λ the eχtreme: test-driving a functional language

Recap

Λ Configuration Management

Λ Implicit conversions

Λ An Actor

Λ An Actor Testkit

Λ The Future!

26λ the eχtreme: test-driving a functional language

Care and Feeding

27

MinedReading

What happens if wefail?

You tell me!

λ the eχtreme: test-driving a functional language

Do we catch anexception?

We intercept it.

28

MinedReading

Sprechen SieDeutsch?

Wenn Sie möchten

λ the eχtreme: test-driving a functional language

29λ the eχtreme: test-driving a functional language

$ git checkout tags/MinedReading

30λ the eχtreme: test-driving a functional language

Etude

31λ the eχtreme: test-driving a functional language

Recap

Λ Stubbing a probe’s return value

Λ Intercepting an expected exception

Λ Iterating over an optional value

<Footer Content: Presentation Title, Partner Name, Other> 32

Putting it out there

33

Zed

May I sharesomething withyou?

Of course!

λ the eχtreme: test-driving a functional language

I would rather youput than post.

34

Zed

What if I don’t havea file lying around?

You can shareanything you likeover the web.

λ the eχtreme: test-driving a functional language

But how will youknow what itshould look like onthe other side?

35

Zed

Who’s Zed?

Maybe Zed canhelp.

λ the eχtreme: test-driving a functional language

Scalaz!

36λ the eχtreme: test-driving a functional language

$ git checkout tags/Zed

37λ the eχtreme: test-driving a functional language

Interlude

38

Zed

Of course!

Does Zed useMonads?

λ the eχtreme: test-driving a functional language

Where’s a gooddefinition of whata Monad is? Anywhere but

urbandictionary.com

40λ the eχtreme: test-driving a functional language

Recap

Λ Implicit transformation from a File to an abstract representation of its contents

41λ the eχtreme: test-driving a functional language

Birds of a feather

42

Bof

We just need a littlecoordination.

What if I want toshare all mypictures ofcanaries withfriends at once?

λ the eχtreme: test-driving a functional language

43

Bof

Recursivetraversal fits a treelike a glove.

How about a littlerecursion?

λ the eχtreme: test-driving a functional language

44λ the eχtreme: test-driving a functional language

$ git checkout tags/Bof

45λ the eχtreme: test-driving a functional language

Interlude

46

CallCC

And on and on?

But what happensif the recursiongoes on and on?

λ the eχtreme: test-driving a functional language

47

CallCC

And on and on and on and on and on and on and on and on and on and on and on and on and on and on and on and on and on and on and on and on and on and on and on and on and on and on and on and on and on and on and on and on and on and on and on and on and on and on and on and on and on and on and on and on and on and on and on and on and on and on and on and on and on and on and on and on and on and on and on and on and on and on and on and on and on and on and on and on and on and on and on and on and on and on and on and on and on and on and on and on and on and on and on and on and on and on and on and on and on and on and on and on and on and on and on and on and on and on and on and on and on and on and on and on and on and on

λ the eχtreme: test-driving a functional language

48λ the eχtreme: test-driving a functional language

Recap

Λ Changing recursive traversal to iterative using continuations

<Footer Content: Presentation Title, Partner Name, Other> 49

To be continued….

<Footer Content: Presentation Title, Partner Name, Other> 50

Thank you!solutionsiq.com / 1.800.235.4091