F# Is Not as Hard as You Think It Is!
This week, I had the opportunity to attend a talk by the one and only Isaac Abraham about F#.
I might have mentioned it here and there, but I definitely want to learn F# in the future. Unfortunately, I havenât been able to learn it yet.
I tried it a few times, but I didnât really have a goal and stopped. My next goal is to write at least one part of an application in F# this year.
Today, I want to debunk a few prejudices C# developers make when it comes to F#.
Is F# a Replacement for C#?
Yes, in theory, you can do everything with F# that you can do with C#. Both are general-purpose programming languages.
However, there is also a world where they live side-by-side. After all, both are .NET programming languages.
I have a friend who works on a team that implements the core logic of their time-tracking system in F#. They benefit from the better type system and F#âs immutability by default. Also, they cannot have circular references in their code.
On the other hand, they implement their WebAPI controllers using C# because they want to use dependency injection and other object-oriented techniques.
They claim to be much more efficient, have a simpler to maintain code base, and have higher developer satisfaction than before.
What Is the Strength and the Promise of F#?
While C# was released in 2001 and is over 20 years old, F# was released in 2010, and therefore carries a lot less old functionality.
Modern software development shifts more towards separating data from logic. OOP is inherently stateful, while functional programming separates data from operations. This makes functional programming more and more interesting to learn.
The reason for separating data from logic is cloud computing. Itâs a lot simpler to scale software that separates data from logic.
Another reason is that developers learned that extensive OOP systems tend to become more challenging to maintain, while functional-oriented systems do not suffer the same from growing over time.
The designers of C# also realized that we need more functional programming concepts in our beloved programming language.
Take a look at the recent new version of C#. The most new C# features were functional programming features (collection expressions, inline arrays, list patterns, record types, etc.). The OOP part of C# seems to be complete.
F# is a functional-first programming language, but you can still consume and create classes with it. The most significant advantage is that while we can do certain things with C#, they are a lot simpler using F#.
F# as a programming language has less features and less operators. It has immutability by default and a much stronger type system. The compiler helps us avoid making certain mistakes at compile time, whereas we only catch them during runtime using C#.
For example, in C#, we need more and more modifiers to write modern code. We often end up with many keywords because the default is from a time when we implemented code differently.
With F#, the code is shorter, more to the point, and with a focus on business logic than boilerplate keyword listings.
Is F# Really That Hard to Learn?
I am guilty of this. Or better, I was. During the last 4-5 years, I always wanted to learn F# but thought it was way too difficult and only something for math experts.
Meanwhile, I talked to many developers using F# and realized I was wrong.
Yes, F# is vastly different from C#. Itâs not only the syntax and the keywords; most importantly, itâs how you think about implementing code.
But does that make it hard to learn? I wouldnât say so. When we have a great resource at hand, we should be able to play with it in a few hours.
Learning something new or different is always challenging. When we overcome it, we have new tools and options to solve problems.
The point of being a software developer is constantly learning new things to not fall behind.
Should You Learn F# Too?
Of course, youâll always feel more productive in a language you have used for years than in one that you have only used for a few days.
Is it worth learning F#, though? I absolutely say yes, and itâs still one of my 2024 goals. Will you try it yourself? Will you broaden your horizon, and are you open to learning something new?
Note: You can find the missing F# resources to getting started in next weekâs newsletter issue.