At Omnitech, we are always striving to learn how to make more maintainable and reliable software that will serve our clients.
Our Mentoring guide says, “We do not do things simply ‘because that’s the way it’s always been.’ Challenge convention. Ask questions. Dig deeper.”
Within the last year, several engineers have become interested in learning more about functional programming and started sharing it with others.
What is Functional Programming?
Let’s start with an academic definition:
“In functional programming, programs are executed by evaluating expressions, in contrast with imperative programming, where programs are composed of statements which change global state when executed. Functional programming typically avoids using mutable state.
Functional programming requires that functions are first-class, which means that they are treated like any other values and can be passed as arguments to other functions or be returned as a result of a function” ~ https://wiki.haskell.org/Functional_programming
That’s a heady mouthful. Describing some key concepts should help.
- Pure Functions: no side effects. Given an input, the output will always be the same
- Immutability: once data is set, it will not change
- Functions are composed together to make applications more modular and maintainable (imagine building blocks like Legos)
Why are we interested?
In our learning and experimenting, we’ve found that it is a different way of thinking than our “normal” C# object-oriented approach. Unfamiliar terms and approaches need to be learned and taught. This has brought new life and energy to learning and provided a lot of good conversations.
Our primary tool for developing applications is Microsoft .NET with C#. Microsoft created F# 20 years ago, but its roots go back to the 1970s, to the academic days of functional programming. F# fits well into this ecosystem.
For those of us who have spent the last year learning more about functional programming, we believe this way of thinking will help us create better software and solutions and grow as engineers.
What are some of the benefits?
The great thing is that these approaches and concepts can be applied in any language and many have made it into C# and JavaScript.
After a year of learning and applying these concepts, Matt shared “Level up your C# Code by Thinking Like an F# Programmer” for a 2-part Lunch and Learn series. He shared 5 principles along with code examples to make C# code cleaner, more expressive, and harder to break.
- Expressions are better than statements
- Explicit is better than implicit
- Model your domains with Abstract Data Types
- Make invalid states unrepresentable
- Keep I/O (input/output) at the edge
*learn from Matt on his blog or maybe even at Nebraska Code 2025 in July, if you see this before then!
We want to create code and system architectures that keep the positive momentum and avoid pitfalls that sometimes plague software products. Mark Seemann gave an inspirational presentation that we enjoyed and recommended, called Functional Architecture - The Pits of Success, which showed that we can apply these concepts to architecture as well.
There are many online that have shared impressive testimonials using F#, which caught our attention.
How are we approaching this topic at Omnitech?
Learn, Apply, Share
Some of us are in the learning, applying, and sharing phase. We are not necessarily going to adopt F# for our projects, but we are looking for ways to apply it in scripts, using the concepts in our day-to-day work, and are open to an opportunity to use F# where it makes sense. We will continue to balance being Early Adopters, Pragmatists and finding the correct Middle Ground when using new approaches. We believe that good ideas that will improve our work will stay and spread, while bad ideas will fade.
"Simple Made Easy", a talk given by Rich Hickey, the inventor of Clojure helped us frame our learning around the differences between “simple” and “easy”.
We have gone through 2 books as a group.
F# in Action by Isaac Abraham
This well-written book gave us real world functional programming approaches, code examples and a guide for conversation as well as an introduction to functional programming and F# as a group.
Domain Modeling Made Functional by Scott Wlaschin
Some of us had read it ahead of time, Matt said “the light turned on” after reading this. Scott does an incredible job of making F# approachable and bringing in existing concepts we have employed of Clean Architecture, Clean Code and Domain Driven Design. Using F# types and discriminated unions to model domains in a readable way is attractive.
Listen to Scott Wlaschin - Talk Session: Domain Modeling Made Functional explain the concepts in his own words.
What’s next?
We will continue to apply, learn, and share with more of our team about functional programming. If we have success applying it, we will see it spread to more usage. At the same time, we will continue to evaluate its uses and use the correct tool for each job.
Recommended Resources for More Learning
- https://fsharpforfunandprofit.com/why-use-fsharp/
- https://fsharp.org/testimonials/
- https://fsharpforfunandprofit.com/
- Fabulous Fortunes, Fewer Failures, and Faster Fixes from Functional Fundamentals - Scott Havens
- Kevin’s Journey towards Functional Programing and F#
- A Human Approach to Functional Programming Adoption
- Get Value out of your monad Mark Seeman - monad is a context
- Refactoring registration flow to functional architecture by Mark Seemann
- F# Focus Dot Net Conf Playlist from 2023
- Functional Programming Using F# from Cambridge
- https://www.microsoft.com/en-us/research/podcast/functional-programming-languages-pursuit-laziness-dr-simon-peyton-jones/