220 points · by todsacerdoti · 5y ago · 214 comments
IMO C# is picking up a lot of small things that make it incrementally better than it was before, and at some point it's not worth the hassle to go to F#. F# features are gradually added to C# so C# developers have time to pick them up as well.
I've heard of F# only projects doing great, but I think you need to have a team committed to doing F#. Back when I was into Clojure they had this mantra of "add Clojure to your work projects as a library and pretend it's just this small thing you used to solve some problem because it's all on JVM and Java compatible and then keep expanding on it" - I think this turns out terrible in practice.
Programming language adoption is based on politics, not technical merit.
This isn't inherently bad, but is important to remember.
Languages are successful due to the community that rises up around them, far moreso than anything inherent to the design or quality of the language itself.
Which can be correlated, but not necessarily so.
At my company there have been several devs trying to introduce Clojure as well as parallel forays to introduce Kotlin. Overall, Kotlin has caught on and spread much more rapidly and with less effort.
This is not a statement of which languages are "better" given all things equal or what problems each are suitable for, but in my first hand experience it is easier for the average Java developer to pick up Kotlin. Of course we as a company are also cognizant of the IntelliJ lock-in as I suspect using any other editor would run into the same random bugs / autocomplete annoyances that the GP experienced.
There's your politics. Kotlin is succeeding because of it's ties to a very popular Java IDE, so developers already using IntelliJ tend to trust it.
It wouldn't do nearly as well without that built in base of support.
The reason might be, that Clojure is following a completely different paradigm and people are not willing enough to learn it.
> This is not a statement of which languages are "better" given all things equal or what problems each are suitable for, but in my first hand experience it is easier for the average Java developer to pick up Kotlin.
Yep, I would expect that to be the case.
There is a lot to learn for the average Java only (so far) programmer to really get Clojure.
This is overly reductive, but here's an example: if you have 3 developers, and 1 will be twice as productive in F# and the others will be 10% less productive, it's probably practical sense to switch, but the 2 developers will resist it, and it may fail for political reasons.
And yet it happens all the time. And the decision is rarely based on anything but a veneer of technical merit.
This is a very serious problem in a production system and it's not a political problem. Having a mixed language system is never as maintainable as a mono-language system, assuming that mono-language is up to the task.
>they leave and now the project has this magic F# part that nobody really knows how it works but everyone knows how to work around.
That's how politics generally works: there always has to be a plausible "objective" reason for something, it just doesn't have to be applied uniformly or even actually true.
I've seen countless migrations to React from other equally capable frameworks because "everybody uses React" it must be the best tool!
I've seen companies picking up Python because if you wanna do ML you gotta use Python, right?
Anybody can write Python, right?
Except now you have a Python codebase written by people that pretend to know Python, while they really don't know how to write a maintainable software program in any language, it just happens that Python is the only language they "know".
And now everything sucks, but at least it's trendy, right?
Programming languages are tools, if you hire someone competent in Ocaml but force them to use Java because "it's more maintainable" you now have two problems.
IMO
You cannot add the best features of F# to C# without making it a fundamentally different language. You're not gonna make C# into a type-inferred FP language by bolting on some random half-understood bits anymore than you can make a cat jump better by gluing rabbit legs onto it.
It's the core paradigm and philosophy that makes it great, and if anything, what I've seen hold it back from its potential is insufficient support requiring essentially importing C# idioms into the language just to interop with existing libraries.
If you have a team looking for a functional language on .NET it's amazing - so I don't dismiss it - it's just a very niche thing on .NET platform.
What objective measure can someone use to determine whether F# is the best choice?
What is possible however is to first analyze the core attributes of the techs which are relevant for the project and team such as: good supported libraries for the problem, support for immutable data-structure, expressiveness of the type system, experience of the team with the tech etc. You can then decide which tech fits better the environment. If still undecided you can try to build a prototype on a short period (at the risk on giving up on technologies which are hard to learn but could be rewarding on the long term).
Which is really a positive - if you start a new effort in F#, it basically self-selects for the most technically curious or proficient devs. Most corporate C# code-slingers are fearful of learning it or putting themselves through the mindset shift required to grok basic FP principles. "Do you know or are you interested in learning F#" becomes the only interview question required. But I do agree, if you have to build a team around the "least common denominator" then pick the boring tech stack and go.
it just selects for people who have hipster level enthusiasm about function programming. That doesn't mean proficient.
Many talented developers have a life of their own, and can do well without changing the language.
That's why Joel said 'smart AND gets things done'.
But I share some of your reasoning and am curious how this actually plays out (I haven't seen any examples so far). One project I worked on, when starting they wanted to do Clojure and they ended up using RoR because everyone was using it and Clojure was a hiring concern. In retrospect RoR fell out of favour, there's a bunch of vacancies for it but it's not very hot so it's hard to find devs and they are forced to take "learn on the job" just like with Clojure, plus you need to compete with a bunch of employers looking to support their projects in now out of fashion stack. I think using Clojure would give them a unique candidate pool and be a hiring differentiator. But that's just speculation. I haven't actually seen how this choice works out in practice.
agree. C# is kind of morphing into F# with new features like record.
An OO language with record types and pattern matching expressions, plus a vague hint of union types in the future; is not a functional language. Depending on who you ask, it's either a quasi-functional OO language or a bloated OO language. I used to be in the first camp, now I lean towards the latter.
Over time, projects morph into the average of their framework. If you started off badly, if it survives long enough eventually someone will refactor it into something acceptable. If you start off using FP features, eventually they will be eroded away; through friction with external dependencies, or later developers being less invested in the paradigm. In both cases you're usually left with an inconsistent codebase.
When people say that C# is morphing into F#, my usual thought is 'have you ever seen an FP project?' Take some time and read some FP codebases, and compare them with a typical C# codebase.
(side-note: one of the most widely used FP language for web development is elixir. There are a few good open-source elixir projects you can read to get a feel for the structure. Almost all elixir projects follow the same structure, and it's about as anti OO/SOLID as possible, yet still conforming to a vague onion architecture.)
This is very accurate, and speaks more towards the sociotechnical systems at play here than anything else. It's not just about being a fan of F# and getting management to approve you using it. You need to cultivate an environment where others want to use it too.
No regrets, canopy was an absolute pleasure to use https://lefthandedgoat.github.io/canopy
The victim of this pattern is not you
The problems with F# are that .NET was originally Window's only causing the creation of a separate run-time in Mono, there were breakages when .NET moved from .NET Framework and Mono to .NET Core (now .NET 5), problems with messaging F# as a C# replacement, biased perspectives of F# as a Microsoft product, Microsoft's lack of investment in and marketing of F#, and F#'s overall ecosystem. There's also the push and pull that comes from some developers wanting to make F# into Haskell, whereas I think that's against the natural settled state of F# as a multi-paradigm practical language.
One can write F# basically as one would write Python, yet F# comes with a host of improvements over Python. One could even go full OOP in F# like one would in C#, again with improvements of conciseness and readability. With F#'s functional paradigm but non-insistence on purity, one gets a language that allows you to write beautifully correct code that works and doesn't fight against you. I use F# in my side projects and also some small work projects, and when using F#, it feels like I'm just translating a specification into code where when done, the code just works.
Unfortunately, the F# ecosystem is not as coherent as others. Probably the comparison I would make is to Elixir. Although I'd argue Elixir isn't as nice of a core language as F#, Elixir's ecosystem and coherence across that ecosystem is very nice and yields a great development experience. The Elixir community has rallied around certain ways of doing things and frameworks where it feels F# is a little more spread out.
I agree with this; it should of never be marketed this way. For me C#, once you get past a lot of the initial ceremony of the language and all the libraries/OO patterns you need to learn (DI, mocking frameworks, etc) the gap between C# and F# gets a lot smaller. C# isn't a bad language and has a lot of features, it just also has a lot of history that adds complexity. IMO the benefit of F# and other newer languages is about simplifying things while keeping the same level or more expressive power. If you've already learnt all the patterns and frameworks in C#, have reasoned around the historical complexity and the ways around things seem second nature to you there isn't much to gain and some things to lose (e.g. familiarity, politics, fear of change, support).
Grab a Go, Python, JS dev however and show them idiomatic F# code vs idiomatic C# code (with tests, and scaffolding) and from first hand experience I've seen what they choose. Even more so because typically these people typically use tools like VS Code and not a full blown IDE, where F# has the advantage at present.
F# - ML + .Net
Clojure - Java + jvm + lisp
Rust/OCaml - System Programming
Both F# and Clojure give you access to probably the two biggest ecosystems, but they are obviously put them at opposite ends of the programming paradigms spectrum, but this makes learning both less redundant
Rust and OCaml, are probably what you should use if you want a compiled system language
Honorable mention PureScript, because haskell + Javascript (but F# will take you close and is more practical)
Yeah, I know everyone hates on Go for its type system and because Rob Pike called it a systems language once (although the idea that OCaml is a systems language while Go isn't boggles the mind), but it's honestly so much more productive than any other language I've used. I also tried hard to like OCaml but the tooling was crumby and integrating libraries which used different standard libraries or async libraries or etc was painful. The ecosystem was also quite a lot smaller and important libraries were missing or low quality. While the Go community has its own problems, the OCaml community was positively toxic (if you have a problem for which there isn't a pat solution, then what you're trying to do is stupid and if it wasn't stupid then Jane Street would have solved it already).
While an ML type system is certainly nice to have, it turns out there are a lot of factors that matter more for practical software development, and if you're missing out on these fundamentals, the best type system in the world won't save you (and I posit that Go excels in these fundamentals even if it lacks an ML type system). I understand that this will not be a popular sentiment in a thread about F#.
Of course not every organization needs this, but many people will find B2B customers, regulators, due diligence people, etc. who are interested in the coverage metric as an indicator of quality. If you write the same tests as you would for another language, your line coverage will suck.
F# seems nice and if I had to pick C# or F#, I would pick F# but I see Clojure as conceptually stronger, easier to explain and teach, to finish projects quickly and run them reliably. Immutable datastructures, the REPL and somewhat related hot-code reloading on the backend and frontend also really is something. (I know, F# has a "REPL" but is it more a Shell or a REPL e.g. running even in production?) Perhaps I should update my views about F# sometime. With my current knowledge I see it as somewhat inferior to the Clojure/ ClojureScript duo and the related ecosystem.
I can see static typing helping e.g. with compilers, low level software where every clock cycle and byte matter and some specialized stuff. I don't see much point in static typing in a language like Clojure.
I would be very surprised if the amount of Clojure/Clojurescript out there in production isn't several times larger than the amount of F#. Not trying to start a language war but with the exception of Jet which I don't think is around any more I can't recall a single large company using F#.
I really wish .NET Core came earlier and would have enticed Clojure to stay as a .NET language.
First hand unfortunately I find the opposite is true - I have personally seen Clojure abandoned in a company and F# adopted instead in the same company albeit different parts. A rare case considering the nature of both langs. F#, to me really is like a statically typed Python that's got better performance, has better portable package management, and reads easier than OcAML/Haskell to newcomers with its "light" mode syntax. Having used Scala, Clojure F# feels like a simplification - it only takes in more expressiveness if it can stay simple. It also reads quite similar to most new breed lang's (e.g. for me when I look at Rust - if I squint many of the constructs look similar). In a month I've seen dynamic language only devs (e.g. JS, Ruby) with no static typing experience be productive in F# contributing advanced code - I've also seen Clojure abandoned in the same company with dev's perplexed with all the brackets, lost as the code scales, etc. Because it is simpler than Scala, Haskell, etc but does pretty much most of what these langs do (80%/20% rule) its a good gateway into functional programming IMO. With some of the new features in .NET 5 it can also be faster since it tends to run closer to the metal than Scala (i.e. no implicit wrapper types, rather use compile time polymorphism, stack allocation support, value types, etc when needed)
F# also has a REPL, and yes its simple but it does the job I argue with a lower learning curve. With one single script file you can load all dependent packages, and write your quick script straight from a naked .NET installation. Just `dotnet fsi script.fsx` or if you want to shebang the script that works too. May not be as pretty as Clojure but it has most of the bells and whistles and arguably much easier for a newbie to understand. There's also a ClojureScript like facility in Fable, heard good things but haven't used it personally. Being able to cut and paste a script in text (e.g. via Slack) to a colleague and it just works on their machine, libraries/packages restored whether they are on a Mac, Windows, Linux machine is pretty cool. All they need is .NET 5 installed.
On the teaching aspect using a JS dev (could be any lang) as an example - a module in F# is the same as a module in JS approximately - they contain functions that refer to other modules. Async blocks are similar to async/await and promises (! instead of await keyword). After that they get the hang of it pretty quickly. They even start to want to move away from their previous language as they realise things just work first time more often. They don't need to learn classes, OO, or all the frameworks typical of a C# project and all the "patterns". In other words it still feels concise like JS/Go/Ruby/etc to them. Functions chained to other functions in a readable syntax - that's it.
I've also seen F# dev's present F# code on slide decks to non technical people and it be well received - they didn't realize it was actual code. There's Twitter threads over the years on this exact scenario and it's what initially made me curious about the language. I can't imagine that happening with Clojure and its syntax of brackets, :require, classpath setup, etc etc.
There's some nice stuff in F# that is entirely novel: my favourite feature is that if you omit passing ref values in a function call, they are added as multiple return values, a kind of dual to Currying.
Then there is the whole point if writing compilers should be considered systems programming.
Here are the top 5.
1. Python
2. Python
3. Python
4. Python
5. Python
If you REALLY can't use Python, then Rust or Go. If you are programing a game, the GDscript.Technically you don't need the former, you can pipe the FSX file directly into the fsharp interactive EXE that interprets them from notepad and console if you like.
It feels more like an introduction section than a whole article.
https://fsharpforfunandprofit.com/series/designing-with-type...
It's amazing
I didn't realize that was true. Long time coders or newbies?
Ocaml's standard library is amazing, and it has a great developer community, but at the end of the day Ocaml is its own thing. F# had virtually identical syntax, but put all of .NET at my fingertips. I was using it for UDFs in SQLServer, UIs with tables and plots, and a lot more. My brief flirtation with windows ended years ago, but F# remains one of the most positive parts of that experience.
Lost me. This is not true, by far.
It is therefor become an interesting alternative to TypeScript/Redux and Clojurescript/Reagent.
Also, Redux does make working with TypeScript slightly more difficult and verbose, at least in my experience, but I may just not be doing it correctly. The paradigm behind Redux and the Boilerplate that I end up with is what drives me to look for alternatives to Javascript and Typescript.
My main frustration with it is its lack of community. The Elixir forums are absolutely terrific; there is seemingly tons of knowledge sharing going on between passionate members of the community. The same with most other languages: if I Google how to solve a specific problem, an answer or an answer to an adjacent problem will pop up. That's true for Swift, Go, C#, Python...
It's not true for F#. F# seems to me almost like a dead language judging from the lack of relevant Google results, zero YouTube presence, no jobs where I live (northern Europe).
Is there a vibrant F# community somewhere online that I've missed?
I think in terms of actual community they have a discourse but it's dead because it's so hard to sign up for.
He has been the best PM for F# so far.
Naturally everyone is free to change careers and all the best to him.
Now F# needs another PM with the same passion.
> F# Is The Best Coding Language Today
Mmmhhh...
At least there is still C++/CLI behind it, in the set of tooling and .NET frameworks coming out of Redmond.
Anyway, the next .NET Conf focus will be on F#.
It is not managed by a secondary team.
With a few exceptions, every Visual Studio tool targeted for .NET development also does VB.NET.
The enterprise developers, those that Hanselmen calls dark matter developers, are more likely to use VB than F#, then leave and do something completely unrelated to work.
Maybe that isn't being strong, but it gets the job done.
Compared to that, F# is managed (by a peer of the C# group), advertised, and arrives everywhere.
Wish granted. https://imgur.com/a/PODd0Iv
And I find VS to be absolutely terrible in every aspect when compared to Qt Creator so the idea of using it for F# does not feel appealing at all.
So long as Microsoft makes sure F# is 100% supported in jupyter I see myself using it more and more to replace Python.
One huge item missing is a data frame library though. They started developing one last year but since then I have seen nothing.
Without dataframes it’s hard to convince myself to spend the time doing analysis. And Deedle is not up to par with pandas unfortunately.
> If you want to personally pick up a programming language in order to become a better coder in whatever other languages you use, F# is the best overall teaching/coding language you can find.
I can't speak to F# at all, but I can to Rust, in this regard. I haven't heard many people say this before - writing F# makes you a better programmer - but mostly that F# people are GSD types of people.
In contrast, I commonly hear other people talk about how dealing with Rust's strict compiler and clippy's lints help them improve their skills by rejecting bad code. In C, C++, Python, and JS, there's limited "guardrails" so most learning or improvement is mostly self-motivated. In Rust, the guardrails are strong that many people learn a thing or two about project structure, memory allocation, performance, semver, etc.
I just feel like this claim for F# is pretty strong, when the primary argument seems to boil down to "you can change your coding style over time." Does F# have as nearly as strict and helpful compiler as Rust - or any other language built-in tooling?
I've been wanting to play around with F# for years. Perhaps some day.
Maybe building your startup that needs 100 new people every year on F# is a bad idea, but for enterprise projects that don't move much, it seems a reasonable choice.
The classic chicken and egg problem
Rust feels like the closest thing to me in terms of overall practicality/ease of use.
I think F# does have a much stronger "in the browser" game. Yes, even a bit more than Rust, if you consider whole web applications and not just performance critical modules.
And some people and companies are extremely stuck in Dot.Net...
Sure I can write stuff in Go or Rust or Python but I don't see that any of those offer anything significantly better than .Net, including the support level, the quality of the IDE and even, God forbid, half-decent performance.
Sure I would choose another language for something that had to be super fast or perhaps headless but otherwise I would choose .Net every time.
Disclaimer, I have professionally used Java, PHP, C, C++ and C# but not Go or Rust.
IDEs for Python have improved a lot, and the more passionate Pythonists might fault C# for actually needing IDE tooling for being bearable...
I can see why you would prefer C# over PHP, C++ and Java for Web programming though.
F# came out well before Go and Rust and well in time to compete with Python's popularity. There were other factors that affected its adoption.
I think you should look again :)
You can do it in any language, FP languages can help enforce the distinction. For going even more functional, in FP languages that support it, free monads and effect systems allow you to define interpreters for effects and you can write code more or less like you would non-functionally, but the interpretation can be pure (say hardcoded results for a query) for tests, and impure for actually running. Basically fancy dependency injection, but for everything.
I could be wrong but I think an onion or clean architecture solves any issues you would have.
Depending on what you are used to, that might not be a huge problem, but the drop-off from the experience of working in C# or Java or even Python with modern tooling is stark.
I wish that there was an F# zealot or three working at JetBrains lobbying for better support in Resharper or Rider.
Great, we're back to this nonsense (also promoted by Haskellers) right off the bat. The best way to learn the language you use is to learn the language you use, period. If you want to be good at C, learn frickin' C. No, F# is not going to help.
Certainly if you just want to learn about "functional programming", yes, find a relatively completist FP language that that looks easy to learn (F#, maybe - Java, nope), and you'll find it easier to learn other functional-programming languages after that. It's also a good idea to learn new programming languages in general, just to expand your career potential and also make better decisions about what to use (if and when you are ever allowed that choice...).
Actually, if you want to learn one language that will make you better at all others? Assembly. Yeah. This is not because Assembly is The Greatest Thing Ever, but because you'll understand the magic behind the curtain a lot better, and be a lot more immune to the incessant nonsensical daily hype around programming languages. For bonus points, learn to write your own compiler/interpreter (but don't feel compelled).