Lambda The Extreme: Test-Driving a Functional Language

50
Copyright © 2014 SolutionsIQ Inc. All rights reserved. 6801 185th Ave NE, Suite 200 Redmond, WA 98052 solutionsiq.com 1.800.235.4091 λ the eχtreme test-driving a functional language 07/30/2014 PREPARED BY Tim Myer Programmer [email protected]
  • date post

    14-Sep-2014
  • Category

    Software

  • view

    111
  • download

    0

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

Page 1: 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 [email protected]

Page 2: Lambda The Extreme: Test-Driving a Functional Language

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

Page 3: Lambda The Extreme: 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

Page 4: Lambda The Extreme: Test-Driving a Functional Language

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….

Page 5: Lambda The Extreme: Test-Driving a Functional Language

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

Prelude

Page 6: Lambda The Extreme: Test-Driving a Functional Language

6

The Little Schemer

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

Page 7: Lambda The Extreme: 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

Page 8: Lambda The Extreme: Test-Driving a Functional Language

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

Tools

Λ Git

Λ Maven

Λ Scala IDE

Λ A Dropbox account

Page 9: Lambda The Extreme: Test-Driving a Functional Language

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!

Page 10: Lambda The Extreme: Test-Driving a Functional Language

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

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

Page 11: Lambda The Extreme: Test-Driving a Functional Language

11

TheBeginning

We got git, now do we get an elephant?

We get a canary instead.

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

Page 12: Lambda The Extreme: Test-Driving a Functional Language

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

Canary

Page 13: Lambda The Extreme: Test-Driving a Functional Language

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

Page 14: Lambda The Extreme: Test-Driving a Functional Language

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

$ git checkout tags/Canary

Page 15: Lambda The Extreme: Test-Driving a Functional Language

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

Interlude

Page 16: Lambda The Extreme: Test-Driving a Functional Language

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

Recap

Λ A Case Class

Λ An Object

Λ A FeatureSpec

Λ A FunSpec!

Page 17: Lambda The Extreme: Test-Driving a Functional Language

17

Canary

Can our canary getaccount info?

Only with aDropbox account.

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

Page 18: Lambda The Extreme: Test-Driving a Functional Language

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

Actors

Page 19: Lambda The Extreme: Test-Driving a Functional Language

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.

Page 20: Lambda The Extreme: Test-Driving a Functional Language

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.

Page 21: Lambda The Extreme: Test-Driving a Functional Language

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

$ git checkout tags/Actors

Page 22: Lambda The Extreme: Test-Driving a Functional Language

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.

Page 23: Lambda The Extreme: Test-Driving a Functional Language

23

Actors

When will we getour account info?

In the future!

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

Page 24: Lambda The Extreme: Test-Driving a Functional Language

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

Interlude

Page 25: Lambda The Extreme: Test-Driving a Functional Language

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

Recap

Λ Configuration Management

Λ Implicit conversions

Λ An Actor

Λ An Actor Testkit

Λ The Future!

Page 26: Lambda The Extreme: Test-Driving a Functional Language

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

Care and Feeding

Page 27: Lambda The Extreme: Test-Driving a Functional Language

27

MinedReading

What happens if wefail?

You tell me!

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

Do we catch anexception?

We intercept it.

Page 28: Lambda The Extreme: Test-Driving a Functional Language

28

MinedReading

Sprechen SieDeutsch?

Wenn Sie möchten

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

Page 29: Lambda The Extreme: Test-Driving a Functional Language

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

$ git checkout tags/MinedReading

Page 30: Lambda The Extreme: Test-Driving a Functional Language

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

Etude

Page 31: Lambda The Extreme: Test-Driving a Functional Language

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

Page 32: Lambda The Extreme: Test-Driving a Functional Language

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

Putting it out there

Page 33: Lambda The Extreme: Test-Driving a Functional Language

33

Zed

May I sharesomething withyou?

Of course!

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

I would rather youput than post.

Page 34: Lambda The Extreme: Test-Driving a Functional Language

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?

Page 35: Lambda The Extreme: Test-Driving a Functional Language

35

Zed

Who’s Zed?

Maybe Zed canhelp.

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

Scalaz!

Page 36: Lambda The Extreme: Test-Driving a Functional Language

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

$ git checkout tags/Zed

Page 37: Lambda The Extreme: Test-Driving a Functional Language

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

Interlude

Page 38: Lambda The Extreme: Test-Driving a Functional Language

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

Page 40: Lambda The Extreme: Test-Driving a Functional Language

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

Recap

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

Page 41: Lambda The Extreme: Test-Driving a Functional Language

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

Birds of a feather

Page 42: Lambda The Extreme: Test-Driving a Functional Language

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

Page 43: Lambda The Extreme: 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

Page 44: Lambda The Extreme: Test-Driving a Functional Language

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

$ git checkout tags/Bof

Page 45: Lambda The Extreme: Test-Driving a Functional Language

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

Interlude

Page 46: Lambda The Extreme: Test-Driving a Functional Language

46

CallCC

And on and on?

But what happensif the recursiongoes on and on?

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

Page 47: Lambda The Extreme: 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

Page 48: Lambda The Extreme: Test-Driving a Functional Language

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

Recap

Λ Changing recursive traversal to iterative using continuations

Page 49: Lambda The Extreme: Test-Driving a Functional Language

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

To be continued….

Page 50: Lambda The Extreme: Test-Driving a Functional Language

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

Thank you!solutionsiq.com / 1.800.235.4091