Impressions of using F# (with a little bit of Xamarin.Forms)

In the last days I completed the first version of FFRAB-Mobile (see here). I used F# and Xamarin.Forms to gain more experience in a bigger project than a simple example app. You can find the sources here:

Here are my impressions:

.) Writing stateless could be hard, but it is worth the trouble

Coming from a C# background, now writing code that is near complete stateless is new and unusual. So the first code I wrote was a lot of object oriented stuff with too much access to shared state. Especially the access to the database connection was at the beginning a little bit painful.

But after some refactoring it got more and more in a functional style. At least I hope so.

Before refactoring: Line 52 – 140

After refactoring:

At the end it was worth the trouble. It is more readable and simpler code.

.) If it looks ugly, make a function

When you have pure F# code and libraries, it is complete in your hands to write nice code. But when you are using C# libraries, i can quickly get ugly because of the library. This is because the parameters of the C# methods are represented as tuples. With them, you have a lot of brackets and can not use the forward pipe operator ‘|>’.

But simply wrap the C# method call in a small function and voila.

Here is an example when using NodaTime (the “let startTime”- line is the important one):
Direct call to C#:

let dateTimeFormat = OffsetDateTimePattern.CreateWithInvariantCulture("yyyy'-'MM'-'dd'T'HH':'mm':'sso<G>")
let startTime = common.Formatting.dateTimeFormat.Parse(dayNode.["day_start"].Value<string>()).Value

With F# wrapper function:

let parseNodaTime<'T> (pattern : NodaTime.Text.IPattern<'T>) rawValue =
        let result = pattern.Parse(rawValue)

let dateTimeFormat = OffsetDateTimePattern.CreateWithInvariantCulture("yyyy'-'MM'-'dd'T'HH':'mm':'sso<G>")
let startTime = (json.GetProperty "day_start").AsString() |> parseNodaTime common.Formatting.dateTimeFormat

For one usage it might be not that bad, but when you have multiple calls, it is more readable. Particularly you get the nice left- to- right readability back!

.) Left- to- right readability combined with railway oriented programming (ROP) rocks!

Look at this example:

let synchronizeData conference =
            match conference with
            | Some conference ->
                |> checkForTimeout
                |> getDataLocation
                |> fetchJson 
                |> Parser.parseJson conference
                |> Synchronization.sync conference
            | _ ->

All parts of the synchronization are nice one after one step easy readable and extendable. So adding the additional timeout check was easy to add to this pipeline.

.) MVVM is more fun with FSharp.ViewModule than with C#

With FSharp.ViewModule and F# you have so much less boilerplate code in your viewmodels. Without the curly brackets of C# you can reduce the line count again.

So the 8 viewmodels are about 260 lines (with empty lines and boilder plate functions/type). In C# 3 of the viewmodels would have this code size.

.) Tooling? Enough, but some rough edges

When you code in Visual Studio, you need the Visual F# Power Tools. And the first thing you have to do is to enable Folder organization. You do not need the folders for your F# code, but to organize other files like images or json-Files. No idea why it is disabled by default.

On the Xamarin side there is sadly one bug, that prevents to use Xamarin.Forms on Android with F#. It looks like the F# CodeDom does not escape F# keywords.
For details is here the Bugzilla entry:
Hopefully the bug is fixed soon.

For the C# developers with Resharper: First you think you will miss it, but you do not need it. The Power Tools have a Rename function. Other refactoring features like extracting or adding namespaces I didn’t miss.


So for me is F# a really fun and productive language. Not everything is easy and clear when you are using it the first time, but the fog will lift with the time. When you are working some days concentrated with F#, you will learn and understand a lot. And it will be awesome. 😉

Upcoming Talks

In the next week, I will give some talks in Vienna.

1.) Cross Mobile Testautomation mit XAMARIN & SPECFLOW

It is a talk about using SpecFlow ( to test your mobile applications.

It is held for the Vienna Mobile Quality Crew at Bena Business Services GmbH
(Herrengasse 1-3, Vienna) at the 23. April 2015.

More information:


2.) .Net & OpenSource – current status

The talk is about the current status of the “open sourcing” of the .Net Framework.

It is held within the Linuxwochen Vienna ( somewhen on 7. – 9. May 2015.


3.) iOS und Android Entwicklung mit Xamarin

In this talk I show how you use Xamarin for developing mobile applications on Android and iOS.

It is also held within the Linuxwochen Vienna.

Android Memory Monitor

At my current project I am searching current some memory leaks.
Always searching GC_ messages in logcat and executing endless adb shell dumpsys meminfo are boring after some time, so I created the Android Memory Monitor.

Chrome memory graph in Android Memory Montor

Chrome memory graph in Android Memory Monitor

It’s a simple application, where you choose your device, the running app and press “Start”.
You can choose which memory values you want to see and in which interval they should be updated.
After some time, you have beautiful memory graphs.

Download Binaries: AndroidMemoryMonitor_1.0

Download Sources: GitHub Project / GitHup Sources Zip

Technical background stuff:

The application calls in the background the “adb shell dumpsys meminfo <packagename>” command and parses it’s output.
For that I use the library Managed Android Debug Bridge (Mad Bee).

To display the graphs I use the library OxyPlot.

For the UI it uses WPF with a little bit of MVVM Light.

Limitation: ADB has to be at following location: C:\android\platform-tools\adb.exe

It you have questions, suggestions or found bugs, please leave a comment or send me a mail.