TomHarris.co.uk >> Blog

Sunday 13 December 2015

Functional Programming and a journey to F#

Hopefully this blog will help anyone considering functional programming understand some routes to skill up. This is in fact a brief history of my year journey to Functional Programming and F#.

My first project

During a company hackathon I wanted to see if we could address customer queries with a set of key responses. The idea was to analyse customer queries and respond appropriately. The key behind this was to do sentiment analysis on the text of the query.

I approached this in a way of categorising words and terms. I was able to do this fairly easily by using Stanford Universtity NLP and a training set created by me. In addition to this I had to correct spelling and learn new slang or alternative words this was possible using NHunspell, The end result was a flow similar to this.



This was a fairly linear process until the validation of sentiment begins. When you begin to look at sentiment you have lots of variations (Sad, Anger, Happy, Fun). Working in imperative code at this point I ended up with lots of interfaces and different implementations of validation. The code started to get messy and complicated I thought there must be a better way?

By the way I won the hackathon ;)

Scala

After some research on my project I found that many developers were using Functional programming to achieve machine learning projects. To give myself an introduction in 2014 I attended a course at City University in London focused on Functional Programming and Scala. Whilst this course was well priced and  and informative for a beginner as a full time developer I found the pace a little slow. That said it was still enough to interest me and continue me research.

Coursera 
To recall the reason for my interest in functional programming was to solve machine learning problems. During this journey I took a free course on Coursera run by Stanford university.

Challenges

Sadly the journey of learning a new language or in this case paradigm isn't always easy. While languages can create interest being able to apply them in your regular career can be a challenge. Working for a .NET house the introduction of Scala would always be hard also from experience introducing new languages can often result in poor code bases for all.

F#

Never one to give up along comes F# a .NET language that lets me build on skills I already have and in addition it interops seamlessly with my C# code. This allows me to start writing code in F# without starting new projects.

I read "Functional Programming for the Real World"  which I highly recommend. The language used in this book makes it easy to understand coming from a C# background.


This book taught me the basics but in the last month I was lucky enough to get the opportunity to take part in Tomas Petricek and Phil Trelford's  Fast track to FSharp. This has really concreted my understand with lots of real world style applications and examples. The course is expensive but if you are a .NET developer and want to introduce functional programming it is worth it.

Journey Continues

My journey continues with F# as I start to attempt to introduce it in Testing and Domain modelling first.

But for some of you the journey might not have ended at F# and you might want to consider other languages for your functional needs. if that's the case I highly recommend investigating Haskell and Erlang.