Our journey to F#: Learning the basics of F#

To start our experiment with F#, we first needed to learn to write code in F#.

Read a little

I knew about the site https://fsharpforfunandprofit.com/ for quite some time, but finally, I took the time to read some posts there until I thought I’m fit enough to code something real.

Code a little

Once upon a time, I wrote a report generator for xBehave.net in C#. The report generator generates a markdown report from the results of a test run of xBehave.net tests/specs. The code was old and lacked some features.

So I started to write a new version in F#. Because most functionalities were already in place, I could focus on the syntax of F# and how to design the generator in a more functional-programming way.

A lot of googling later, this was the result https://github.com/ursenzler/xBehaveReportGenerator.

So I learned the basics of F# and how to deal with immutable data structures. 

Read some more

As a very experienced C# developer, I struggled to get my head around some functional-programming concepts in F#. So I decided to read a book about F# for C# developers. I found a perfect one at https://www.manning.com/books/get-programming-with-f-sharp. Thanks, Isaac! This book takes your hand and introduces functional-programming concepts step by step. While it contains everything you need to get started, there is no scary functional-programming lingo and therefore, easy to follow.

Play a little

Then I wrote some useless F# code to fiddle with all the concepts that I read about and to get familiar with the tooling, or better, how the IDE displays function signatures. That’s the thing that is hard in the beginning: reading function signatures. I primarily use JetBrains Rider for programming because I like the IDE as a whole. But VisualStudio does a better job at displaying function signatures (hello syntax highlighting). It would be nice if Rider would improve how function-signatures are shown because this is something, that I still struggle with a bit (issue). I’ll write more about the things I struggled with in later blog posts.

Domenic – my team peer – used exercism.io to play around with F# and the samples in Isaac’ book.

See the bigger picture.

At this point, I understood how to write some algorithms and console apps in F#. Probably not perfectly idiomatic to functional-first-programming in F#, but working. So it was time to learn how to build more significant systems with F#. The book Domain Modelling made functional (https://pragprog.com/book/swdddf/domain-modeling-made-functional) helped me a lot in this regard.

If you are more of a learn-by-watching person than check out the great videos by Scott Wlaschin (like https://www.youtube.com/watch?v=Up7LcbGZFuo).

Read much more

Then I switched back to F# for fun and profit and read the downloadable version “cover to cover”. A lot of things were repetition and helped me strengthen my understanding, and a lot of things were new – like writing your own computational expressions. By the way, I have to re-read that because I still don’t fully get it 🙂 But I think that I understood enough to see when I have to build my own computational expression builder to solve a problem.

Get real

Then I felt confident enough to start the next step of our experiment: porting a part of our system from C# to F#. There is still a lot to learn, but I thought I got the basics. In hindsight, that was correct – more or less 🙂

The following blog posts will be about the things I struggled with, learned and found awesome.

Learning plan

If I’d start over, I would do the following, to begin with learning F#:

  1. Read https://www.manning.com/books/get-programming-with-f-sharp to get started.
  2. Play with F# on excercism.io
  3. Find a pet project to write in F#. Google one problem at a time.
  4. Find a mentor who can help if you get stuck and reviews your code to get it to look like F# is meant to (it is sometimes hard to let go of OO-style and see the new possibilities).
  5. Read https://pragprog.com/book/swdddf/domain-modeling-made-functional to get an understanding of how to build a bigger system in a functional-programming way.
  6. Read https://fsharpforfunandprofit.com to expand your knowledge.
  7. Find places to use F# in your commercial work.

You can find all blog posts about our journey to F# here.

Find the next post in this series here.

Find all blog posts about our journey to F# here.

This blog post is made possible with the support of Time Rocket, the product this journey is all about. Take a look (German only).

About the author

Urs Enzler

1 comment

By Urs Enzler

Recent Posts