Hacker News new | past | comments | ask | show | jobs | submit login
Writing high performance F# code (bartoszsypytkowski.com)
243 points by pjmlp on Feb 4, 2021 | hide | past | favorite | 52 comments



I wished they made the ecosystem as easy as Go to install on Linux. Last time I "tried" to get into F# (The lang looks really good). I was lost between mono and .net and the other 1000000 gazillion libraries I had to install to get a basic dev-env. After giving up half my SSD in storage, I still had env issues. :/


Nowadays it's pretty straight forward. Just run `sudo snap install dotnet-sdk --classic`, install plugins for fsharp for vscode and you're good to go.


Worth noting that snap installs aren't supported in the vscode tooling for F#. There's an open issue and I have a handle on some of the core problems, but they invalidate a ton of assumptions we have.

The safer route is to install the non-snap-based versions.

(I maintain this tooling, for what it's worth)


Thanks for working on this tooling. Your efforts are much appreciated.


Can you link to the open issue? I want to subscribe to it.


What's the --classic flag for? Just curious


Classic confinement (no sandboxing) because an IDE needs to access tons of stuff from your system (the compilers, your projects, etc).


Ah, thank you!


You can follow this guide for installing on your distro of choice: https://docs.microsoft.com/en-us/dotnet/core/install/linux

Unless you have a reason to only use LTS releases, install .NET 5. I suppose this doc could clarify that 3.1 is an LTS and .NET 5 is a "current" (but newer and better).


My experience is the opposite, with .NET Core I can manage multiple versions of the SDK with my linux package manager and not an external tool. Then in each project I specify which SDK I want to use and what dotnet tools to install.


It's become a lot easer with the .NET 5 release from a couple months back.

https://devblogs.microsoft.com/dotnet/announcing-net-5-0/


Isn't F# essentially just OCaml on .NET? Wouldn't OCaml be easier to get running?


In the same way that Objective-C is just C++ on OS X.

https://news.ycombinator.com/item?id=25989061


Same, but it’s much better now. The best combination in my experience is:

- .Net Core 5

- VS Code

- Ionide


literally yesterday I installed the above from nothing and was trying out some F# for fun and profit code within moments...amazing how far the tooling has come from even 2 years ago


This kind of optimization actually drove me away from F#. I realized that high-performance F# is essentially imperative C# with F# syntax.

There is no place for high order functions and functional constructs in high performance F# code.


Most of the time you won't need it, and when there is the need the tools are there.

It is no different in most languages, even C++ can look pretty ugly when going for F1 performance.


It's true of C# as well. Implementing the full suite of performance tricks precludes object-oriented techniques every bit as much as it precludes functional techniques, because the fastest possible code path is rarely going to wander through a vtable.

I suppose, though, that it's always easier to throw a baby out with the bathwater when it's someone else's baby.


To be frank, I'd have upvoted you too if you'd ended your comment after "ugly".


> essentially imperative C# with F# syntax

This sounds pretty good to me! Not to mention that once you get out of the hot path, the threshold to switch to more readable F# is very low.


I kind of agree... although I still think F# is a win over C#. IMO the syntax is much nicer and idiomatic F# is still pretty fast.

However, I wish the compiler would more aggressively optimise things so that I can dip into this style less often. I shouldn’t have to write the imperative stuff if the translation is mechanical!

The C++ compilers do far more work for the user, despite F# being a language much more conducive to being optimised.

It would be great if Microsoft Research could sponsor a project in this area.


Articles like that is why I keep reading HN. Excellent write-up.


I'm going to repost my question from a recent F# item and I hope it'll get some traction this time:

I learn a lot by reading others' code. Can anyone recommend a a project or two that is small enough for a newcomer to wrap their minds around, that also exemplifies what makes a high quality F# codebase?



I'd suggest having a look through https://github.com/fsprojects/awesome-fsharp and look at the high starred items (though some are not strictly F# but just something F# can use)

maybe something like suave (backend web framework).

The bigger problem I found going down the F# route is F# libraries go dead. For long term projects, far better not to use any thirdpary F# libraries and just use pretty popular third party .net libs from the C# world or the core .net lib. These days I mostly just use C#. The advantages of F# are not that big compared to just writing C# with a similar coding mindset.


I've worked in F# for seven years and your question stumped me. My company's code is all private

Maybe try looking at the demo code for https://safe-stack.github.io/

I wish our online systems were #F Elmish style. Unfortunately they are TypeScript front-end, but F# server side


Any tips for getting an F# job?


If you're in the market for an F# job in London, please reach out to me at Saul.Rennison@gresearch.co.uk. We have an full-time F# engineer open right now.


If you join the F# Software Foundation (https://foundation.fsharp.org/join), jobs pop up fairly regularly on their Slack.


Not right now, but in the next 6 months we may be hiring. We would prefer in the Houston area, but remote may be possible.


Giraffe for sure:

https://github.com/giraffe-fsharp/Giraffe

As an added bonus you'll learn a very popular tool for sticking a web interface in front of your F# app.


This is not at all a direct answer to your question, but if you are looking for learning material on F#, https://fsharpforfunandprofit.com is kind of the default. Here's a link to a series where he builds an "enterprise tic-tac-toe" in F#: https://fsharpforfunandprofit.com/posts/enterprise-tic-tac-t...


F# is a cool language that I have absolutely no use for, sadly.


Yes, sadly, the advantage of languages with big ecosystems outweigh the advantage of these languages.

I know F# can tap into the C# ecosystem but you have the mental burden of translating every example and documentation from C# to F#. In Clojure land these is pretty bad, you have to spend a lot of time understanding these extreme over-engineered over-abstracted Java libs before you can begin to use them.


The difference between C# and F# is smaller than the one between Java and Clojure though. Also IDE support + the fact that both languages are statically typed make it much easier to explore a C# API from F# code.

It also helps that C# has had some functional building blocks longer than Java had, which means more of the ecosystem has at least some support for passing around functions and the likes.


You can use it + Fable to compile to JS. Assuming you had a use for JS before, now you have a use for F#.


I have even less use for JavaScript. I mostly do NLP and DL, so it's Julia and Python for me.


Off-topic: what did you use to create those diagrams and such?


Blog author here: as weird as it sounds, I have a prefetched Power Point template with color palette and settings, and I'm just using it for all presentations and diagrams ;)


Thank you, I will see what I can create using LibreOffice.


F# was one of the first languages I learned. Great resource!


I'm a simple man – I see F# on HN, I upvote.

This great little language needs a little more love, IMHO


Yes. I know literally noone who has touched it. I even know more Haskell-dabblers. But it looks very cool.


I do think it depends where you live and what ecosystem's are around there. F# to me fills a niche - i.e. in an ecosystem that uses .NET but is also more tech-savvy and willing to evaluate best tools and new approaches. That intersection of users being small shows a bit about .NET developers culture than the F# language itself (IMO only!). It happens less in the Java ecosystem and I suspect that's because Java was much slower to improve - C# isn't the best language on the platform IMO but it is improving all the time. Often reading a new C# release notes in previous roles (C# 6, 7, 9, 9) felt like reading very old F# release notes which means people don't necessarily have to take the risk to get the language endorsed in their enterprise - they just need to wait and they will eventually get something representing it (if not as generic or ideal as the F# impl).

That's more an observation I've seen on the ground in previous roles but YMMV.


C# gets more and more features from F#, for example you can now declare immutable records in a single line:

record Book(string Name, int publishYear)

and there are millions of jobs worldwide.


this seems to be Scala "case classes" or Java "records" or Kotlin "data classes"...the earliest I saw it was (among these) in Scala.

I find it a positive sign that these expressive languages are mimicking one another.


Olo uses it in production, if you order food online you have probably touched their f# code a bit.


I use it in production. Some of the choices they made grind my gears (I'm looking at you ordered `open`s and poor inference for records with similar shapes) but overall it's pretty nice


I used it for a couple WPF apps (of all things) a couple years back. F# is so nice for anything with a good amount of "business logic".


We've been using it in production almost two years now for some backend services to serve as a source of truth for different kinds of data between various servers and applications. It's been a genuine joy for rounding up data, analyzing, and serving it. Half of that is the F# language itself, the other half is being able to use those features on a platform with great debugging + optimization tools, and a huge open source ecosystem to pull from.


JET, now part of Walmart.

Many UK (City area) and Swiss banks use it for data analysis.


AFAIK Credit Suisse have their quant library written in F#.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: