I am a C# developer and I have nurtured a wish to start developing in F#. I have read some books on F# and written some test, demo and lab code, but I want to write a real program that solves a real problem. Last week I got a chance to finally do this. This blog post describes my experience with switching from C# to F#. I will not talk much about the languages per se, but more about other things involved in developing.
- Writing code in F# makes you think about how you write C# code.
When I write some F# code I think “could I write this in C#?”, and the answer is often, yes. I will definitely write my C# code in a more functional style from now on.
- Unit testing F# code is easier than unit testing C# code.
Testing code that has data in, data out and no side effects is often very simple. Now, of course there are F# code with side effects, but that is more the exception than the rule, and it is very clear when it is side effects you are testing. I recommend using FsUnit, https://github.com/fsharp/fsunit, for your tests.
- The F# Interactive window (FSI) is great!
Ever wondered things like “what will the result be if I call this function with this parameter?” or “Will I get the correct result if I write the code this way?”. Just write the code in the FSI and run it. No need to start up the debugger, set breakpoints and modify values. The FSI is like unit testing on a micro level, it really saves you time. More info about FSI here: http://sachabarbs.wordpress.com/2014/02/25/f2-fsi-environment/ and here: http://msdn.microsoft.com/en-us/library/dd233175.aspx
- No ReSharper support!
I use almost every ReSharper feature there is when I write C# code. ReSharper does not support F# and I feel handicaped. As a substitute I use “Visual F# Power Tools” https://visualstudiogallery.msdn.microsoft.com/136b942e-9f2c-4c0b-8bac-86d774189cff. It is a very good plugin to Visual Studio and has some, but far from all, of the ReShaper features.
- No code snippets!
I use code snippets quite often when I write C#. Visual Studio does not support code snippets for F#, and I really miss that feature.
- Type inference.
In F# you often don’t have to write the type of your variables. The compiler can figure it out. This works great most of the time, but it can be very confusing when it doesn’t. Especially as IntelliSense and the compiler uses different methods to determine the type and might come to different conclusions.
- Syntax check while you type.
This is a nice feature, but it doesn’t work between projects. You have to recompile to make it correct.
The good parts about developing F# is that it makes you Think about code in new ways.
The bad parts is in the tooling. With the increasing popularity of F#, the tooling will soon get better.
The different parts are actually good, you just have to get used to them.