top | item 44843447

Why F# could be the next mainstream programming language (2024)

50 points| smoothdeveloper | 6 months ago |blog.snork.dev

98 comments

order

akkad33|6 months ago

F# is a chimera of a language. The functional parts of the language are nicely designed: no nulls, discriminated unions (ADTs), you write simple functions in simple modules and there is nothing that is too clever to understand: it's very pragmatic. Then there is a whole lot of stuff like inheritance, classes, interfaces, nulls mainly there for dotnet interoperability that gets very ugly very fast. There are way too many variants of the same thing: records, classes, struct records, tuples, struct tuples etc, which are mainly there either for compatibility with similar c# stuff or because the default language constructs often result in suboptimal code. At the end I went with Rust because it has one way of doing such stuff. And for those interested in a gc language with functional features there is now Gleam

DimmieMan|6 months ago

C# will eventually have unions that will undoubtedly be incompatible too, I worry about source generators becoming ubiquitous as well.

This was also my experience with F#, phenomenal language dragged down by ugly interop with an ecosystem that barely acknowledges its existence and I feel is incompatible with its ideals.

Shame too because there’s some genuinely great stuff in the community like fable [1] where if you were to chuck in JSX like templating you’d have an absolute killer web tool rather than the mess blazor is.

It’s ironic that I found js interop less annoying than .net interop.

[1] https://github.com/fable-compiler/Fable

xscott|6 months ago

> There are way too many variants of the same thing: records, classes, struct records, tuples, struct tuples etc, [...]

> At the end I went with Rust because it has one way of doing such stuff.

I haven't looked at C# in 20 years, but Rust certainly has a LOT of ways to do similar things too:

    struct Foo { x: f64, y: f64 }          // Struct
    struct Foo(f64, f64)                   // Tuple Struct
    let f = (1.0, 2.0)                     // Tuple
    enum U { Foo(f64, f64) }               // Enum Tuple
    enum V { Foo { x: f64, y: f64 } }      // Enum Struct
    [ 1.0, 2.0 ]                           // Size-2 Array
    &[ 1.0, 2.0 ]                          // Slice
    vec![1.0, 2.0]                         // Vec
Then possibly wrapping those in Rc, Arc, Gc, Box, Cow, Option, Result, RefCell, RefMut, Cell, OnceCell, LazyCell, UnsafeCell, Weak, and so on... that's a multiplicative product of possibilities. And you still need raw pointers for interop with C libraries.

Anyways, I haven't used Rust in a few years now either, and I'm sure I've made some mistakes and omissions above, but I don't remember it as the poster child for Python's "There should be one-- and preferably only one --obvious way to do it".

banashark|6 months ago

Well there are the 3 you mentioned (records, classes, and tuples) which should be easy enough to differentiate from each other. The struct versions aren't necessary to use in most cases, and are an optimization.

The thoughtful, but not breakneck speed of changes within the language is one thing I appreciate a lot. Things do get added (there are proposals and discussions that are fairly regular in the GitHub repo for language design matters). A recent example is adding a spread operator.

CSMR|6 months ago

You can choose which constructs you use. Avoiding classes in F#, while possible, would be a mistake as they are a way to hide data and functions where these are not intended to be part of the public API. F# is outstandingly pragmatic and the struct types for performance have been a nice addition. As a beginner you can ignore those if you are not interested in getting max perf.

Dotnet does have some minor annoyances (exceptions being one) but gives the ability to deploy everywhere, GUI apps on all platforms, web, backend is fantastic. Lack of native GUI apps would be the main deficiency for me from Gleam, plus the fact that they have decided their community is explicitly politically woke-liberal.

Rust has been a fantastic addition to the language ecosystem, but recursive types, which are the bread and butter of ML-family code, are just too hard to write in Rust.

LittleCloud|6 months ago

Speaking as a C# developer, who had in the past wanted to learn F#, but never got very far. What discourages me every time:

- C#'s good enough. Nothing's stopping you from writing functionally-oriented code in C# (and I do prefer that over traditional "enterprisey" object-orientation.)

- It's relatively difficult to have a codebase that is partly in C# and F# for incrementally trying things out. (I understand this is not really F#'s fault, owing to the .NET compilation model where C# and F# compilers each produce their own assemblies. And that Microsoft hardly cares about F#, and the tooling leaves a lot to be desired - admittedly I'm spoiled by C# tooling. )

- F# having its own implementations of concepts like async, option types introduces friction with C# obviously. I get that F# async is more powerful in some ways, but then again... F#'s option type is a reference type unlike C#'s Nullable<> value type, it's hard to see what's the advantage in that other than worse performance. One almost gets the impression that F# designers don't care about performance (while C# designers do in the past few years with additions to the ecosystem like Span<T>). This makes it hard to justify coding in F# for infrastructure libraries (which is what I often do).

CSMR|6 months ago

Lack of expressions is the main C# deficiency that will never get resolved. The other big advantage of F# is that it can be very easy to understand: file ordering means that you can read through from start to end to understand the code.

Ordinarily in a mixed codebase, the F# comes nearer the start, with C# depending on F#. That's because C# has lots of glue code to connect to the outside world (xaml, cshtml, EF...) and this is less straightforward to migrate to F#. The only problems with mixing languages is when you want F# in the middle of some project where it depends on some parts of the project and other parts of the project depend on it. But if you can identify something independent in a C# project and extract that out, you have already made the project simpler.

You can ignore async and use task. You can use async in the (very rare) cases when you don't want a hot task. You can also ignore Option and use ValueOption all the time. The struct types are new and have meant that F# does not have a performance deficit.

ValueOption is just better than Nullable<> since Nullable<> restricts to value types only. Resulting in Nullable composing terribly and requiring ad-hoc code everywhere.

mrbluecoat|6 months ago

When your top reason for a language being mainstream is "interoperability with .NET", I think the argument is a stretch.

banashark|6 months ago

I understand where you're coming from, but I'd challenge your dismissal of that note by noting how seemingly powerful a large ecosystem of available packages is when onboarding people to an ecosystem.

I don't think Scala, Kotlin, or Clojure would have had as much adoption if they hadn't had access to the JVM ecosystem of libraries available.

While it's not the only benefit, I think one could just point at the usage of OCaml as the alternative to F#. While both are in the lower percentages of language popularity/usage, I've worked with at least 50 (dozens lol) people who were paid to write production F#.

enjo|6 months ago

It's Scala all over again.

glimshe|6 months ago

This feels like "This year is the year of Linux on the Desktop"

I've been hearing about F# hitting mainstream for over a decade. Unlike Linux, which is now fairly popular on the Desktop, I predict that F# won't ever be mainstream.

ffin|6 months ago

not to get into this debate, but linux is far from mainstream

jakebasile|6 months ago

Could be! Depends if MS starts putting some more money behind it, including marketing. They're pretty deep in an AI-everything spiral right now though.

I'm a Clojure guy, but the ML family (specifically OCaml and F#) have always interested me as another branch of functional programming. I started out in the before times as a .NET Programmer (VB6 -> VB.NET -> C#) and have toyed with F# a little since then. It's cool, but the tooling leaves a lot to be desired compared to what's available for OCaml unless you decide to use full fat Visual Studio.

What I particularly like about them is the middle ground of inferred types. I don't need types since maps, lists, and value types are enough for me in almost all cases, but if I must use a strongly typed system why not let the compiler figure it out for me? I always thought that was a neat idea.

CrimsonCape|6 months ago

I had a thought today, "when is Microsoft and/or Apple going to earnestly search out their next Steve Jobs?"

And I think the answer is that guys like Bill Gates and Tim Cook are too proud, too prideful to admit they are not kickass rockstars of tech, too jealous to find and cultivate their next super-figurehead. Instead they are safe and lame.

Microsoft needs a non-lame, non-MBA, engineer to take control and inject some younger mindset into making themselves cool again, focused back on tech, UI, user experience, and passion. Engineer tooling would be a great approach.

mbac32768|6 months ago

I do not understand how they could develop a language inspired by OCaml but not bring over labeled function arguments. A real L when it comes to ergonomics.

And they just have no plans to ever fix this??

AdieuToLogic|6 months ago

> I do not understand how they could develop a language inspired by OCaml but not bring over labeled function arguments. A real L when it comes to ergonomics.

Is this what you desire?

  Named Arguments[0]

  Arguments for methods can be specified by position in a 
  comma-separated argument list, or they can be passed to a 
  method explicitly by providing the name, followed by an 
  equal sign and the value to be passed in. If specified by 
  providing the name, they can appear in a different order 
  from that used in the declaration.
0 - https://learn.microsoft.com/en-us/dotnet/fsharp/language-ref...

Beermotor|6 months ago

I became more proficient in one language than any other. Therefore this language is the best language ever and will take over the universe.

buffet_overflow|6 months ago

That language isn’t the same language I became more proficient in, so are you sure it’s not terrible, useless, and will lose handily to the one I use for my specific purposes?

UncleOxidant|6 months ago

Wishful thinking, me thinks. How good are the AI coding agents at coding F#?

banashark|6 months ago

Comparisons to typescript/node (which I have more ai hours in, but equal experience)

Pros:

* type system is less flexible which simplifies things for the ai

* mostly functional code

* the language hasn’t evolved as much as others because it’s had a strong foundation of features for a while, leading to the corpus containing fairly common themes

Cons:

* smaller corpus

* no reliable hot reloading, which causes annoying iterations of starting a server in the background to test, then forgetting to stop it and hitting errors from starting it again. It does this even when attempting to prompt against it

* Struggles with some breaking changes and interfaces for dotnet things (using old apis, installing old versions of packages)

* file ordering dependency messes with its flow. Usually has to stop to reorder things every once in a while. Can create a mess in the fsproj

Overall my “tier-list” so far has f# below typescript, but above a number of other environments (Kotlin/jvm, Ruby, c#).

Last week I wrote out a 2 page prd for a small service and it got about 95% of the way there (not including tests). If you’re promoting doesn’t have to do with web framework stuff, or you have a repository with existing patterns, it does pretty well.

I gave it a task of “write an inertiajs 2.0 server compatibility library for the oxpecker framework” with a few extra things to create an example test and verify with the playwright mcp. It struggled pretty hard and didn’t end up anywhere close to what I had in my head.

So I’d definitely say that directing it more than vibing would yield a higher chance at success.

sasmithjr|6 months ago

For me, AI code generation for F# has been pretty good! There's one annoying thing Opus/Sonnet do (honestly don't remember what other models do): use old syntax for array indexing.

  values.[index] // Old way of indexing required a .
  values[index] // Supported for awhile now
That's the "biggest" issue I run in to, and it's not that big of a deal to me.

Yesterday, it did try to hallucinate a function that doesn't exist; compilation failed, so the agent changed the function to a fold and everything was hunkey-dorey.

CharlieDigital|6 months ago

I tried F# when we were building out a scraper at a startup. After a bit, I realized that must of the things could also be done in C# and ended up using C# instead because it's just a bit more accessible. F# looks neat, but C# has a lot of parity at this point on some of the core selling points IMO.

smoothdeveloper|6 months ago

C# can't fix the wrong defaults, still lots more mutable by default, and statement oriented, as an example.

average C# codebase looks different depending language version idioms, not so in F# (because initial release already had >80% of things that C# today doesn't even have and won't be able to fix).

But C# is great too, nonetheless.

scrubs|6 months ago

I recently left a c# shop in finance. My background c/c++. I was very interested to see if c# was less work: easier to write and build.

I was not impressed by what I saw - it was junk code. One of the major errors was writing apps as MS services which dragged in tons of MS OS junk.

I cannot totally blame c#; i think the staff there were not engineers but more guys doing stuff.

The code was complex; replete with async calls. Build artifacts were entire directories of dlls, exes, json eg 50+ files per task.

The code was littered with warnings. The company could not or would not do hardly anything outside Visual Studio.

There were entire repos of code without comments; no method contracts, obscene reliance on exceptions.

I'm prepared to think f# could be better but never underestimate how bad things can be with a good language if the devs are not engineering grade developers.

smoothdeveloper|6 months ago

Never under-estimates wrong defaults in a language, for example:

C++, const modifier, verbose for more correct code (less mutable state, etc.) Rust, mut modifier, verbose for less correct code

C/C++, bothersome to have tight scopped values, due to split of expression & statement ML languages, nesting of let bound values, everything is tight scoped, even recycling local names non destructively via shadowing.

C#: mostly, all flaws of C/C++/Java F#: mostly all right things of ML, OCaml, Rust

F#: Structural comparison of ML types from day 1 C#: just adding records recently; most of libraries, idioms, and semantics geared towards reference comparison

idioms

C#: mainly OO, noisy syntax, low expressivity (constructing immutable values out of generators or expressions), lots of navigation due to adhoc things needed to be named, poor type inference F#: data & functions, concise end non noisy syntax, high expressivity (list expressions, computation expression values), less scrolling & navigation, object expression rather than defining type used once, great type inference (less noisy diff on refactorings)

etc.

So average F# codebase is by construct, more sound, than average C# codebase, however F# code quality may be poor, and C# great, still, more soundness in F#, IMHO.

ofrzeta|6 months ago

I would be very reluctant to use it because of the fear that at some point Microsoft just kills it. You have to wonder why they are keeping it alive so long as they are probably getting not much value out of it (some people here say they are using it as a testbed for functional features in C# but I don't believe this - I guess the C# team has enough resources to do their explorations on their own). I guess if Don Syme leaves Microsoft or retires that will be the end of it.

cosmos64|6 months ago

I can tell you, that the community keeps it alive for all these years already.

F# used to be the project #1 across all the thousands of repositories of Microsoft in terms of community contributions to the ecosystem, compared to the contributions by paid employees.

Next, F# has already been a very refined language 10 years ago, so it doesn't get a lot of things added to begin with. Slow and steady evolution, with lots of care is the topic of this game.

Also: A lot of the paid work went into the tooling, which has finally reached a point, where I consider it industry ready.

By the way: Don isn't paid to work on F# anymore for quite some time.

The world still moves on.

From my personal perspective, would it change little, when Microsoft would F# let go.

And did you know, that they finance the development of Haskell since decades?

Simon worked literally on the same floor as Don for years.

They won't let it go. Paying 2, 3 devs is peanuts for them. They don't even notice it.

I am just scared, what will happen if F# truly competes with C# for market share.

The internal competition amongst projects at Microsoft can become quite nasty at times.

thuridas|6 months ago

Not having exceptions doesn't seem like an advantage. My experience with either tough me that some infrastructure error are better as exceptions.

Kotlin handling of nulls is probably the most elegant. And you do not need. Net. When you want 20 pods in kubernetes you probably want some alpine image instead of windows

zdragnar|6 months ago

You can have your cake and eat it too with dotnet core on Linux if we're talking remote / web servers.

akkad33|6 months ago

F# has exceptions though

SoftTalker|6 months ago

C# was Microsoft’s response to Java, was F# their response to Scala and Clojure?

azhenley|6 months ago

It was a Microsoft Research project based on OCaml and adapted for .Net.

cosmos64|6 months ago

.NET was initially planned as a multi language VM.

The first plan was to bring over Haskell, and Don (the creator of F#) implemented support for generics in dotnet.

The reason, why C# has an edge over Java, when it comes to generics. ;)

Then he noticed that Haskell wouldn't run on that runtime back then, and they chose OCaml instead.

to11mtm|6 months ago

F# came out within a 18 months of Scala, It's 'possible' it was a response but my understanding is that many of the folks who created F# were instrumental in adding generics to NET2.0, so it's hard to say for sure.

moron4hire|6 months ago

It's a research language with legs. Microsoft's explicit strategy with F# is to test functional features they might decide to bring into C#.

swader999|6 months ago

Clojure is the youngest in that group.

cosmos64|6 months ago

F# is basically a better C#

wewewedxfgdf|6 months ago

Functional programming people have been hoping for their favorite functional language to go mainstream for a long time but it never happens.

pyuser583|6 months ago

Every now and then one starts to rise up ... XSLT, Scala, etc. But for some reason, it never makes it all the way to the mainstream.

cosmos64|6 months ago

Javascript, Typescript, Rust, and Kotlin are fundamentally functional programming languages.

daft_pink|6 months ago

Seems unlikely as most of us are ditching .net

I was a Microsoft fanboy years ago but even I am completely uninterested these days.

smoothdeveloper|6 months ago

Just a polling of HN hive mind on this critical matter.

Worst case, let the "tried F# once/for real" ramblers unload their bag once more :)

adastra22|6 months ago

The very first advantage listed is actually a disadvantage for 95% of developers.

“Wedded to the dotnet ecosystem.”

sheepscreek|6 months ago

I think, we’re not far from the day when LLMs will be spitting out highly optimized ilasm/byte-code (dotnet intermediate language representation). So your programming language will well and truly be a bunch of prompts. That’s it.

suprjami|6 months ago

I think that's unlikely to get widespread traction.

Source code is not for computers, it is a way for human developers to communicate with each other.

Compilers/interpreters are a consumer of that communication.

Without easy communication of ideas, software does not work. That's why very few people write in raw assembly (hardware or bytecode) and why so many people write in programming languages.

LLMs will not remove the human interchange of ideas. At least not the current generation of generative LLMs.

ofrzeta|6 months ago

How to you review the resulting bytecode? Or will you just go on running it blindly on some computer on the Internet?

adzm|6 months ago

What would be the benefit to this versus generating highly optimized c# for example?

lihaciudaniel|6 months ago

If you do not believe in the python supremacy you are an idiot. C#, F#, M#, G# these are chords not programming languages.