3What is F#, and why does it matter?
write F#. In this book, we’ll be effectively ignoring the OO side of F#—which
would mostly just be about learning a new syntax—and focusing on the FP side,
which is much more interesting.
Another point that the preceding quote alludes to is that F# helps us focus on delivering
business logic and ultimately business value, instead of having to focus on complex
design patterns, class hierarchies, and so on in order to achieve quality. This is partly
because F# contains a powerful compiler that does a lot of the heavy lifting for us, which
can lead to more succinct solutions than you might normally achieve in C#. But in addi-
tion, the FP paradigm (in conjunction with F#) emphasizes composing small pieces of
functionality together to naturally build more powerful abstractions rather than
through designing large class hierarchies up front and building downward.
What is functional programming?
To explain this a little more, let’s quickly define FP within the context of this book. Just
as with OO design, defining exactly what FP is can be subjective; many languages that
support FP to some extent will have some features that others do not. At the end of the
day, you can think of FP as a sliding scale of language features that encourage a particu-
lar style of programming; I suggest that any FP language should have good support for
a few core fundamentals:
Immutability—The ability to create values that can never be changed in their life-
time, which leads to a clear separation of data and functionality (unlike the OO
world, which merges both state and behavior into classes).
Expressions—The notion that every operation in your program has a tangible out-
put that can be reasoned about.
Functions as values—The ability to easily create, use, and share functions as a unit
of abstraction and composition within a system.
There’s certainly more to FP than just that, and many languages have features such as
sum types, pattern matching, type classes, and the often-dreaded monad; we’ll deal
with some of these features throughout this book, but the preceding three are the key
ones that we’ll really emphasize. Remember that FP is just another way to model solu-
tions to programming problems; there’s no real magic involved, nor do you need to be a
mathematical genius.
F# alongside other programming languages
Figure 1 illustrates where I believe F# fits in within the spectrum of other mainstream
programming languages.
F# and C#—two sides of the same coin
Let’s start by looking at F# which, as already stated, is a functional-first language. It’s
clearly on the FP side of the axis, yet it’s not on the far right. Why? Well, F# makes it easy