Part 1 is this article on how I started in FP in C# by learning LINQ and trying Project Euler puzzles.
Part 2 is a detailed look at the first Euler puzzle with source for the first puzzle and source code for the next 17 puzzles using Imperative and LINQ
Part 3 is making C# code more functional by using abstractions from the excellent functional c# library
Notes Are my developer notes whilst working through the book
Why learn FP techniques
NDC Video by Enrico Buonanno has a very good introduction as to why we should consider FP in C# - he is the author of the orange book linked below.
- Power (do more with less code, raise the level of abstraction)
- Safety (avoiding unnecessary side effects makes code easier to reason about)
- Clarity (we spend more time maintaining and consuming existing code than writing new. Achieving clarity will become more natural)
I have a tricky programming problem, which I’ve tried and the code is rapidly turning into complex unmaintainable spaghetti. Am I saying that OO isn’t up to the job? No. But:
I believe OO becomes cognitively very difficult when a project reaches a certain scale. Functional programming allows my brain to manage complexity much better.” source
As a side effect it has pushed my C# language skills and is thoroughly enjoyable!
- Be patient
- Experiment in code
These techniques are for an ambitious breed of developer who is aiming for code which is: concise, elegant, robust and maintainable.
The orange book below is very thorough, and I suspect to fully understand the ideas I’ll have to learn other languages just as the author did. F# and Haskell are the 2 natural fits. Scala is getting a lot of traction around London, and Clojure seems interesting too. I’m going to push very hard in C# first as I know it well.
‘Change the way you think is hard, and learning the syntax is relatively easy’
- Extension methods
- Lambda expressions
After doing the Pluralsight course I did the first 17 or so Euler puzzles in an FP / Linq way and explanation of the first one
Using ReSharper to understand the names of different concepts and different ways of writing something
Functional Programming in C# book is a very in depth book. It took me many attempts to understand Chapter 1, and think is one of the best C# programming books I’ve read.