My early struggles with F#

 

I love F#.  I wish that I could tell you that everything went smooth when I started learning it, but it did not.  Here are some of the the things that I struggled with in my quest to learn F#.

Lack of Web Project Templates

Writing my first “Hello World” app in F# was quick and easy using the F# Interactive (FSI). FSI is like LINQpad for C#, but within Visual Studio.  I used it all the time while learning new things in F#.  After some time playing around though, I wanted to do something useful, something that is relevant to my work.  I am a C# developer and primarily work on web applications.  We use Web MVC and Web Api at work, so I decided to create a simple CRUD application using Web MVC and F#.  I was really disappointed when I found out that, unlike C# and VB.Net, there are no web templates for F# in Visual Studio. It was not a deal breaker for me, but it did dampen my enthusiasm after a really great experience with the FSI.

Learning F#

It was a while back, but I don’t remember struggling like this when I learned C# coming from VB.Net. Maybe because I only had to deal with getting familiar with the C# syntax, since both VB.Net and C# are OO (Object Oriented).  With F#,  I have to deal with the syntax and learn functional programming all together.

Syntax

Its funny that while learning C# from VB.Net, I had to get used to using curly brackets.  This time, it’s the other way around.   I have to get use to reading and writing without them.  Somehow,  It feels like coming back to VB. Overall, learning the syntax is not that bad at all.

Organizing Code

In C#, its usually one class per file and you organized files by folder.  In F#,  file order matters.  Also,  it is common to see multiple class/types in a file.  Also, even if I wanted to organize my code files in folders,  adding folders in F# is not as easy as right click –> Add –> New folder.

Thinking Functionally

This is where I struggle the most.  By default, my brain thinks OO.  I always catch my self trying to find the equivalent of doing something in F# from C#.  Scott Waslin by the way,  has this advise:

When learning F#, you should not try to bring your old imperative concepts with you. In a pure functional language there are no variables, there are no loops, and there are no objects!  – Scott Waslin

And then, there’s the others things to learn.  Higher order functions, currying, partial application, discriminated union, recursion and others.  Sometimes, my head feels that its going to explode.  If not for the excellent resources in the web like F# for Fun and Profit, I would have given up a long time ago. 

Finally

Many things have happened in  F#  since I started back in 2012.   The  F# ASP.Net  MVC  5 and Web API 2  Project Templates is now available to help you create Web MVC or WebApi apps.. There are lots of excellent web resources too, like F# for Fun and Profit which is my go to resource.  If you are just getting started with F#,  I highly recommend this post from Scott Waslin.  Learning F# and Troubleshooting F#.

A C# developer by day and F# developer by night with JavaScript sprinkled in between. I am a Catholic, proudly Filipino and married to my beautiful classmate from college with 3 kids. I am currently a Senior Software Developer at Epitec.

Leave a Reply

Your email address will not be published. Required fields are marked *