Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?

F# for Python Users

In my opinion, targeting Python users has a lot more potential than introducing F# to C# developers as a better C#.

My reasoning for this assumption is this:

C# Users

  • Use C# mostly in at work.
  • Often not incentivized to try a new language unless it helps them find a better job/make more money.
  • At first glance, the advantages of F# over C# might not be apparent to C# developers. Especially now that C# is tagging on more and more functional features.

Python Users

  • Huge open source community
  • More eager to try something new

F# addresses Python's pain points

Also, Python has a few real pain points that F# directly addresses:

  • Many want the safety of static typing, but find the available options tedious
    • F# Solution: Type inference ("All the advantages of types without the ceremony").
  • Slow execution, especially in parallel
    • F# Solution: Much faster execution and Async.
  • Hard to debug, "refactoring angst" for fear of breaking things.
    • F# Solution: Safety features like static typing, exhaustive pattern matching and Option types. Get a piece of mind that everything just works before you even run your program.
  • No convincing story on mobile for SPA's:
    • F# Solution: You can use (almost) the same code on the backend, frontend, and on mobile. Everything stays in sync.

F# is similar to Python

In addition, F# is similar to Python in ways Python users value very much:

  • Significant whitespace: F# code won't look alien.
  • "Batteries included": Everything you'd ever need is just an "open" statement away. By this I mean all the NET libraries, but I won't mention the name, at least not on the landing page.

Present the biggest advantage first

Of these features I would take one or two and make a very bold headline to hook Python users in. Maybe something like this:

All the advantages of static typing without the ceremony (on the frontend, backend, and on mobile).

Use code examples to convince

Right below the headline, I think it would be interesting to lead with a short example, placing the code of F# and Python side by side.

Then you could say: "See, the F# version looks just like Python, but it's statically typed automatically without you having to add any annotations".

Or, you could pick an example that also shows the beauty of exhaustive pattern matching and Option values.

Then you could say: "Not only is the F# code statically typed out of the box, but you can be sure it won't blow up in production due to a null value or code branch you missed.

What about machine learning?

As I have no experience with machine learning I cannot comment. But I think that adding a code example using units of measure would be extremely convincing, especially if placed side by side with the same code written in Python. Even better, a code example that has a bug in the Python version that won't be possible using UOM's.

@bytesource

This comment has been minimized.

Copy link
Owner Author

@bytesource bytesource commented Mar 2, 2021

Original discussion on Twitter that prompted my above response: https://twitter.com/ljquintanilla/status/1364983101152198657

Today, although probably not intended, @isaacabraham's tweet reveals with humor why introducing F# to C# developers is truly difficult: https://twitter.com/isaac_abraham/status/1366356599296655362

Some "highlights":

  • Microsoft doesn't even use F#
  • It's only for Math-heavy programs
  • C# is already functional
  • VB6 has more devs than F#

In a nutshell:

C# developers have to be convinced of something they don't think they need, whereas a growing subset of Python developers is actively looking for something that addressed their pain points (this is where F# comes in).

@bytesource

This comment has been minimized.

Copy link
Owner Author

@bytesource bytesource commented Mar 2, 2021

How do you react to any of the above "highlights"?

This is how it often goes:

  • Microsoft doesn't even use F#: But F# has a vibrant open source community! Problem is, most C# don't care.
  • C# has record types, too: Now you need to go into the details and explain why the F# implementation is better. As a result C# feel lectured, but nobody wants to be lectured. In this situation, convincing anybody of anything is fruitless.

Compare this to Python developers who are mostly aware of the pain points of their language.

In order to get them interested, you don't even need to mention that F# is based on NET or that it takes a functional-first approach.

All you need to do is show them how this new language solves their main problems:

  • F# offers static typing without them having to change their workflow
  • Gets rid of all null value errors (before even running the program)
  • Offers an amazing Async story
  • Can be deployed literally anywhere (all operating systems, backend, frontend, and mobile)

As for F#'s advantages (and challenges) for data science projects (mathematical planning, ML, etc.) from the view of a Python programmer, I suggest asking @matthewcrews for input.

For example, in this blog post (https://matthewcrews.com/blog/2020-12-09-why-i-love-fsharp-for-mathematical-planning/) he points out a typical problem in Python that is hard to debug. A problem that can be avoided easily in F#.

@dbrattli

This comment has been minimized.

Copy link

@dbrattli dbrattli commented Mar 7, 2021

There is also the Expression library that makes it possible to try out a few F# abstractions from Python, or when you as an F# developer need to write something in Python and want to reuse what you already know. https://github.com/cognitedata/Expression

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment