Phillip Trelford's Array

POKE 36879,255

DDD North 2013

I’m heading home on the geek train back from a cracking DDD North, this year held in Sunderland and attracting 430 attendees and three well attended F# talks.

I managed to deliver the first pony of the day in F# eye for the C# Guy:


Starting with live samples of immutable classes in C# and then in F# using the class and record syntax. Then instantiating the classes via the F# interactive (REPL) window and from C# which simply requires a reference to the F# library project, it’s all .Net IL underneath.

Then we moved on to unit testing in F# using a selection of libraries from Nuget including NUnit, FsUnit and Unquote. On the unit testing theme Ian Cooper gave a talk on TDD, where did it all go wrong at the same time which was well received.

Leading on from unit testing we took a look at automated acceptance testing with TickSpec, and how this was used in the open source spreadsheet Cellz.

Finally for fun I showed a couple of FunScript samples including the Mario Tutorial (only working in IE at the moment) and a Pacman Sample. FunScript is an open source F# to JavaScript compiler with a Type Provider to TypeScript type definition files which provides typed access to common JavaScript libraries.

If you’re interested in picking up F# I’d recommend trying the F# Koans (where you can pick up the syntax while making a set of tests pass), the online Try F# site, and the F# Tutorial project in Visual Studio.

Hadoop Kickstarter

Next up in the same room Gary Short gave a great introduction to Hadoop and some of the related tools like Pig.

If you’re interested in trying out Hadoop with F# check out the Hadoop Type Provider online on the Try F# site which gives you typed access with intellisense:

Hadoop 

WTFP?! Functional Programming and why you should care, with examples in F#

Before lunch Grant Crofton gave a great introduction to functional programming with F# using lots of live code snippets in Visual Studio


 

Grant also managed to slip some ASCII art into his scripts :)

WTF ASCII Art

Lightning talks

Lunch time saw a selection of lightning talks including Ben Nunney on Twillio and Anthony Steele on Feature Folders which emphasised the importance of focusing on the problem domain in your architecture.

The Joy of Wires: an introduction to Netduino

After lunch I popped over to see Iain Angus’s lively talk on Netduino which showed how much fun it can be playing with electronics.

You've learnt the basics of F#: What's next?

The last session of the day for me was Ian Russell’s fun talk which covered a selection of F# Type Providers for typed data access and F# Agents for taming concurrency.

Audience at Ian's talk at DDD North

Ian demonstrated the SQL, CSV, JSON and World Bank type providers all available either bundled with F# or via Nuget. For F# agents he showed a simple chat server that he ran from F# interactive using a local web server.

You can get the samples from Ian’s github repository: DDDNorth F# Presentation

Testing Crap in Web Applications Like ASP.Net MVC

The last pony of the day was spotted in Rob Ashton’s talk/rant which unfortunately I missed as it was on at the same time as Ian’s:


Close

Hanging out at the close with my fellow F#ers, Ian and Grant:

FSharpers

 

A big thanks to the DDD North team especially Andy Westgarth for hosting a great event!

5 lesser known F# testing tools & techniques

Most common .Net testing tools work in F#, but that’s not the end of the story. F# adds many more tools and techniques besides, lets take a look at a few of them:

1) Back tick methods

F# lets you write method names with whitespace by escaping the name in back-ticks:

let [<Fact>] ``2 + 2 should equal 4`` () =
    Assert.Equal(4, 2+2)

This is also handy when writing step definitions for acceptance tests:

let [<Then>] ``I should have (.*) black jumpers in stock`` (n:int) =     
    let passed = (stockItem.Count = n)
    Assert.True(passed)

TickSpec provides a lightweight library for automating acceptance tests in F# along with SpecFlow which now supports back-tick methods (although for SpecFlow you’ll need a C# project too).

2) Mocking

In F# you can easily create mock objects without frameworks using object expressions:

let [<Test>] ``at 15:00 the sun image should be expected`` () =
    let time = { new ITime with member __.GetHour () = 15 }
    // ...

Along with all the standard .Net mocking frameworks like Moq, F# also has Foq:

let [<Test>] ``at 01:00 the moon image should be expected`` () =
    let time = Mock<ITime>.With(fun mock -> <@ mock.GetHour() --> 01 @>)
    // ...

And now there’s AutoFixture support in the form of AutoFixture.AutoFoq.

3) Fluent Assertions

FsUnit lets you write your assertions very close to how you might write your test names:

let [<Test>] ``2 + 2 should equal 4`` () =
    2 + 2 |> should equal 4

While unquote lets you write tests like code:

let [<Test>] ``2 + 2 = 4`` () = 
    test <@ 2 + 2 = 4 @>

4) FsCheck

FsCheck is a random testing framework based on Haskell’s QuickCheck that lets you assert properties on functions:

let revRevIsOrig (xs:list<int>) = List.rev(List.rev xs) = xs
Check.Quick revRevIsOrig

In the check above FsCheck will randomly create lists of integers to test that the property holds (reversing a list twice should take you back to the original list). If it fails it pares back the input to the shortest list that would make the property fail.

5) Code Coverage

Not F# specific per se, but full fat Visual Studio 2012 comes with a test runner and code coverage tools built-in, it even highlights code that isn’t covered by tests for you:

Code Coverage Facts

Happy testing!

Autumn F# Events 2013

It’s coming up conference season again, also know as autumn, and there’s a bumper harvest of F# related events around the UK and Europe, here’s a not so short roundup:

October

DDD North 12th (Sunderland, England)

FP Days 24th-25th (Cambridge, England)

Progressive F# Tutorials 31st-1st (London, England)

November

Øredev 4th-8th (Malmö, Sweden)

DunDDD 23rd (submitted) (Dundee, Scotland)

F# in Finance 25th (London, England)

  • Functional Finance (Don Syme)
  • Why functional? Why F#? Why in finance? (Andrew Sheppard)
  • A tour of F#, with applications in finance (moi)
  • F# and Financial Big Data: challenges and opportunities (Tomas Petricek)
  • F# and GPUs speed, speed, speed! (Daniel Egloff)
  • F# in the Cloud: running F# at scale (Yan Cui)
  • Using F# with Excel (Adam Mlocek)
  • Quantitive finance using F#; pricing financial assets (Antoaneta Serguieva)
  • Using F# on the trading desk: better, faster, quicker (Andrew Sheppard)
  • Moving risk and compliance to real-time with F# (awaiting confirmation)
  • Use code TRELFORD for a 33% discount when you register!

December

NDC London 2nd-6th (London, England)

F#unctional Londoners

There’s also a free event every 2 weeks at the F#unctional Londoners meetup at Skills Matter in London. The next event is Programming with Cells delivered by Andrew Phillips, head of the Bio Computational group at Microsoft Research in Cambridge.

Check out the F# Foundation map for events in your area, including new user groups in Athens, Detroit, Minsk, Paris, Sydney and Washington!

progfsharp-2013-800x300px1