I've recently joined Compositional IT, so now seemed like a good time to talk through how and why I switched from being a C# developer to being an F# developer. I'll discuss how I discovered F#, what I did to become more familiar with it and why I jumped at the chance to join the team!
Learning the basics
For a few years before joining Compositional IT, I worked on a variety of ASP.NET MVC web applications written in C#. In that time, I learnt about some concepts that I wanted to put into practice in my C# code: immutability for value objects; a type for potentially missing data (like option) to avoid nulls; a type for potentially errored data (like result) to avoid exceptions. After feeling frustrated with my experience of using these concepts in C# code, a friend recommended F# and Scott Wlaschin's blog, F# for Fun and Profit. I soon discovered that there was much less friction when using these ideas in F# than C# and many more benefits besides.
Having spent a few months getting comfortable with the syntax and concepts, I tried implementing a hobby project in F#. I'd just read Scott's book, Domain Modelling Made Functional, so was keen to solve a problem where the domain was non-trivial; I settled on an app that would help me keep track of cards while playing the board game Pandemic. My initial aim was to get familiar with implementing logic in F# and not worry about a user interface, so I wrote a class library and some unit tests. That done, it was time actually to make the app. I'd heard good things about the Elm architecture, so decided to try Elmish. I'm really glad I did: it allowed me to create a client-side web application (currently hosted on my personal GitHub Pages site) rendered using React, written exclusively in F#.
Now convinced that functional programming is a better fit for the software I work on—solving business problems, usually with a web app—I started sharing ideas from functional programming with colleagues. A few lunchtimes were spent talking about the benefits and trade-offs as compared to other paradigms. I even gave a presentation to the organisation's "coding discussion group" on the underlying principles; expect some related blog posts in the near future 😀
I was thrilled when I became aware of the opportunity at Compositional IT: if I got the job, I'd have the chance to program in F# full-time, using SAFE Stack to write F# across the whole stack! I got started on my job application almost immediately. Thankfully, I did get the job and have got stuck in using SAFE Stack within my first few weeks.
I'd just like to sum up by saying this: if you haven't yet taken the plunge, give F# and functional programming a try. If you want to use F# to write a web application, try SAFE Stack. Once you get past any initial differences, you may find the simplicity liberating and realise that you're having a lot more fun—I know I am 😊
- For an introduction to creating and using option and either types in C#, check out the Advanced Defensive Programming Techniques Pluralsight course by Zoran Horvat.
- F# for Fun and Profit is Scott Wlaschin's F# blog, which I used to get started with F#. It's got some good content for beginners and plenty of deeper articles too.
- Mark Seemann's blog often has interesting F# content.
- If you like Scott's blog, his book Domain Modelling Made Functional has great advice on how to build business applications in F#.
- If you want to write web apps in F#, check out SAFE Stack.
- The Elmish Book by Zaid Ajaj is a great way to get started with Fable and Elmish, the 'F' and 'E' in SAFE used to write web front ends.