Why F# is a fun programming language

Date: 2024-02-28 | create | tech | fsharp | python | programming |

F# is often described as a fun programming language. I've personally described it thus many times.

But this isn't really self-evident if you haven't used F#. How can a programming language be fun?

In this post I'm going to share why I think F# is fun.

Fun for Functional

First off "F# is fun" is a pun on a few things.

  • fun for function - fun is the keyword for a function, often used in anonymous or no-arg contexts
  • F# is functional-first - fun is a simple way to reference that
  • fun appears a lot in F# programs - Prior to dotnet 8, many list ops required the use of fun for anonymous functions. Because F# is functional, it leans towards list ops which means most codebases were filled with fun.
let simplePrint = fun() ->
    printfn "F# is fun"

simplePrint()
|> ignore

Prints "F# is fun"

So on the surface F# is fun because it's punny - F# is functional and fun is how you declare many kinds of functions.

F# feels like a toy

But I don't think punniness is the only reason this description sticks. After all what makes something funny / sticky is that it tends to hold some grain of truth.

I believe F# actually is a fun language. To explain this, let's look at another language that many people think of as "fun" - Python.

I think most people who say Python is fun do so because it feels like a toy. It is easy to use and do things compared to other languages they've used allowing them to focus on doing what they want and not fighting their tools.

Thus comparitively: Fun.

Python feels like a toy because:

  • Low boilerplate - No brackets, no required ; to end statements, can run/write like a script
  • Easy to read - Often likened to pseudo English
  • Easy to do common things - Has a great standard library that makes it easy to do simple list operations, conditional logic, http requests, and file manipulations

F# similarly feels like a toy:

  • Low boilerplate - No brackets, no required ; to end statements, can run / write like a script
  • Easy to read - Pipe and list operators for more concise declarative code, expressive non-verbose type system for safety and conciseness, immutable first so less mental overhead
    • Caveat: F# looks very different from mainstream programming languages so give it a sec
  • Easy to do common things - F# can leverage all dotnet libraries so gets the first class standard library and enterprise-grade ecosystem of C#

So F# feels like a toy for very similar reasons Python does - it allows you to write easier to read programs with less boilerplate for common things.

Thus comparitively: Fun!

F# is more fun at scale

Toys are fun but you'll often lose interest once it loses novelty, it no longer fits the usecases, or you find a better toy. Toys that have longevity are those that can scale with you to new usecases and difficulty levels.

Python is used in many large-scale deployments but at scale runs into many issues. It's a toy in the former category - it's like a video game that has a good early / mid game but falls off at the endgame which means there's little reason to keep playing / using it at scale.

  • Instagram serves ~2B MAU and runs on Python monoliths - BUT built its own ~10x faster Python runtime, built its own ecosystem of devtools like linters and runtime managers, and moved most hot workloads out to Hacklang (PHP) to achieve this.
  • Reddit ran on Python Monoliths for years - BUT called bankruptcy on the entire ecosystem for scale and maintainability reasons and is currently undergoing a multi-year project to rewrite its backend in Go.

The primary issues with Python at scale are typically:

  • Rudimentary type system - Simple types, mostly linter enforced, easy to override incorrectly
  • Performance is meh
  • Syntax has lots of implicit gotchas - dynamic / rudimentary types are the core issue but also duct-taped class declarations (self, cls, ABC, static, classmethod), mem usage pitfalls from common Pythonic paradigms, etc etc

Python is fun to work with and can scale (we use it at Rippling where I currently work). But it starts to breakdown at scale and be a lot less fun to work with. It's like a video game that doesn't have an endgame.

What I think really hooks people on F# is that it's fun both at small and large scale. It has a good progression from early through end game.

  • Excellent type system - Easy to model your domain at small scale and large scale which solves SO MANY ISSUES. Think of the type system of Rust, OCaml, TypeScript (if it was actually strongly typed) - that's what you get in F#.
  • Performance is great - It's not going to beat out Rust or your hand-rolled memory-management of C / C++ / Zig. But it will compete with Go / Java / C# and you'll have a better time doing it.
  • Syntax pushes you towards success - Initially you will fight w the type system and F#'s way of doing things. But you will start to realize that this saves you from so many common pits of failure via things like strong type system and enforcement, exhaustive pattern matching, and lack of nulls to name a few. Eventually you are pushed towards a Simple Scalable System of composable parts.

So F# is fun to work with at small scale but it really starts to shine at larger scale. The more you play with it the more you appreciate its depth and how fun it really is to use.

It's like a video game that has such a good endgame that the earlier parts just feel like a long tutorial.

Next

I've personally been using F# as my main language in personal projects for the past few years and have really been enjoying it. I mostly build fullstack web apps with F# and HTMX (my version of The HAM Stack) so that's where my perspective comes from but with the power of dotnet you can really build anything with F# from CLIs to video games to generative art.

I've yet to use F# for work (IMO F#'s weakest attribute is its level of adoption) but it's really opened my eyes to what programming can be and different ways to solve common problems. So even if you don't think you'll use it at work / your own projects, I still think it's a great toy to play with.

At the very least you'll learn a lot.

If you liked this post you might also like:

Want more like this?

The best / easiest way to support my work is by subscribing for future updates and sharing with your network.