Why anyone would bother to learn out-of-demand languages. A case study of the F# community

https://habr.com/post/424461/
  • Translation


We all hear of iconic movies, games, books or musical compositions that get vehemently praised by the community of sophisticados, professionals and critics, yet never seem to attract tangible commercial success or the attention of the wider audience. Such situations leave me deeply frustrated.

When it comes to development, good tech also sometimes never gets into the limelight. Take F# for example. All I know about it is that it is a super-cool, yet totally unpopular language which makes it hard for developers – upon getting to know it – to get back to the languages they’re used to.

I tried to find out what is the story behind this. In fact, who are the people who use it and why are they doing this if the language is out of demand in business? To find answers, I joined the Russian-speaking F# community on Telegram – our round table for the discussion.

How did you start learning F#?


Ayrat Hudaygulov (Szer): I originally migrated here from C#. We once had a job that had to do with Akka.NET – a Scala port of Akka. The port itself was fine, but it lacked examples to rare cases in the user manual, although they were always provided in the Scala manual. While reading that manual, I kept wondering — why does it take just a couple of lines to write it in Scala whereas I’m struggling so much to do the same in C#?

I saw the solution in switching to F#. I never had any second thoughts since then.

Roman Liman (kagetoki): It turned out, it was a powerful tool for solving actual day-to-day problems any developer can face. The hurdles that used to be seen as the inevitable norm of OOP in the world of C# and Java, are in fact not that inevitable and can be easily prevented rather than overcome.

Phil Ranzhin (fillpackart): I once read a long interview with Vagif Abilov on Habr. Back then I just could not get to grips with the paradigm of functional programming, so any related information would seriously piss me off. That interview was no exception.

Vagif Abilov (VagifAbilov): Here is the link to the article in question. I did it shortly after giving a talk at the DotNext conference in Moscow. To put it short, I started learning F# as an attempt to make my code more concise (less code equals less evil) and to utilize persistent data structures. Sure, nothing stops a C# or Java developer to declare their data structures as persistent, but the ability to mutate data structures is a fundamental feature of OOP languages, and one that will always be inherent to them. Functional programming spares you the effort usually spent on protecting the data against inappropriate mutations in a multi-thread environment — the data will take care of themselves, as they are immutable.

Phil Ranzhin: Vagif kept saying that after the strictly formal C# and Java, F# seemed like something much more development-friendly. I did not know then who Vagif was, but I naturally thought the guy didn’t have the slightest clue. C# is not overly formal, C# is exactly the way it should be. It’s powerful and beautiful. I decided to write an article on how preposterous functional programming was after all. I took a simple problem and began implementing it in both C# and F# in order to prove my point. But as I was working on it, I took such a liking to F# that I abandoned the article. Instead I started digging deeper into the technology.

Roman Liman: Much of the stuff that C# verifies at runtime is now taken care of at compile time, so it feels like playing with static typing for the first time — a true revelation.

Without overstating it, where you need seven lines of code in F#, you’ll need 200-300 of lines to write the equivalent code in C# (to account only for useful code). The compiler will do all the boilerplate generation for you, such as structural equality.

Phil Ranzhin: I have never actually debugged my F# code because in my F# code, all the bugs get nipped during compilation. I’m not kidding.

Is it hard to learn F#?


Roman Liman: How hard is it to learn it? I’d say, not hard at all. You might find it tough to tackle it at first if you’ve never dealt with the functional paradigm and immutable types before. But this problem has to do with switching between paradigms, not languages.

The syntax is not obvious at first, so tame your arrogance and do read about this language, don’t hope you’ll get away with your knowledge of C#.

Ayrat Hudaygulov: F# supports everything that C# does, except for goto (as the language is completely expression-based, it would seem weird to make an imperative jump in a computable expression) and the protected keyword (it was so by design, as apparently adding it would be a no-brainer). The rest of everything we love about OOP — the abstract classes, interfaces, auto-implemented properties, using, try-catch, etc. — it’s all there of course. Byte-counting enthusiasts will also be satisfied, what with the ref/out parameters, mutability, spans, unmanaged, pointers, stackalloc.

All C# features get added with a delay of a couple of years compared to F# (generics, async/await + task, LINQ, pattern matching and many others). Moreover, many features will probably never make it to the language (sum types as discriminated unions, native function currying). The forthcoming C# 8.0 is expected to be enhanced with records and recursive pattern matching. The question is, why wait?

Another question is: why learn a new language to use it in the old ways? To really embrace the advantages of F# that are missing in C#, you will have to comprehend the other side of the Force. Nobody said it was easy.

John Doe: As a C# developer, I’m grateful to the creators of F# for generics and asynchronous programming with a human face in C#. For those who didn’t know, those mega-features came to C# thanks to F#.

Vagif Abilov: The author of the popular Pragmatic Development recommends that developers learn a new programming language every year. I can’t say I religiously adhere to this piece of advice, but I guess the authors really wanted to say that developers must always be prepared to revise the principles on which they write their code.

Many people revere programming languages like their beliefs. Some will treat a switch from Java to Clojure like a conversion from Christianity to Islam. Why on earth should it be that important? Learning new programming languages will often give us an opportunity to reconsider our old ways of working with the languages we already know. Getting familiar with F# makes people write C# code in a new way.

Roman Melnikov (neftedollar): The OOP part of F# is more proper (although it is completely compatible with the C# version of OOP), since it encourages you to program using abstract interfaces instead of explicit classes.

What do you think about the designers of this language?


Nikolay Matyushin: I once helped introduce the support of data type providers to .NET Core. They wouldn’t work for quite a while, so, having enlisted another member of our Russian-speaking community, I made up my mind on finding out what exactly was wrong. After some digging, we discovered that .NET Core lacks a function for saving the assembly object to a file — this function was needed by type providers.

We spent a week or two on developing a prototype that would be able to do it. We put together a messy hack, but it worked (at least to some extent). All that time, we kept posting to Github’s Issues until Don Syme popped in, said it was ‘a few hours of work’ and fixed the type providers.

Vagif Abilov: The language designer Don Syme is approachable and open-minded. I hope he will someday venture as far as some Russian conference to meet Russian developers in person.

Roman Liman: Syme is a genius. It’s incredible that he was pretty much all alone behind this beautiful design.

Pavel Smirnov: He is my role model in the world of programming.

Ayrat Hudaygulov: By the way, Don Syme was the one to introduce generics to .NET, otherwise we would be still hard-casting everything from and to object in C#, as it was (and partially is) the case in Java. Syme grows the language with a look back to C#, to the compatibility with its new features, which is probably the right thing to do from the strategic standpoint. Yet it means that the aftertaste of poor decisions in С# can also leak into F#. He is also opposing the introduction of nerdy FP features (hello Scala!) and overcomplication of the language, as all of that can scare off other people and bloat the standard library (hello C++!).

I think Syme is a hero. I side with him on his vision of the language as a multi-paradigm one, however, I’d probably add more features to the language.

Why is the language not very popular?


Roman Liman: I’d say the language is not popular because FP is generally less popular than OOP. Besides, there is the steep learning curve. The rest is a Catch 22 situation. Few projects are coded in F# because the market lacks F# programmers, whereas programmers do not learn this language because the market lacks relevant project.

Phil Ranzhin: I don’t know anyone who would practice functional programming and at the same time prefer the object-oriented model. In that sense, F# is especially unlucky, as it works well only for those who believes in the symbiotic union of both paradigms.

Pavel Smirnov: Many considered it a still-born child because of Microsoft’s policy of making F# just a platform for playing with features intended for C#. However, the language was originally aimed at data science rather than at industrial development.

Roman Melnikov: ReSharper. It’s essential stuff for C#, and many people have already invested in it. Writing C# code without ReSharper is hard work, considering the amount of manual configuration, such as to highlight allocations. Thus, ReSharper relieves a lot of pain in the ass for C# developers. F# does not inflict this pain in the first place, but those using ReSharper cannot really appreciate the whole beauty of a language that does not rely on tooling.

Vagif Abilov: In my opinion, the reason it lags behind Scala’s success lies in the dominating position of Microsoft which still dictates the priorities across the Windows platform. Despite that fact that F# was developed in Microsoft Research, the company has always been positioning it as a language for enthusiasts. Microsoft has its own metrics for economic feasibility of growing a particular technology based on current sales performance, so surely, according to those metrics, projects like SharePoint look much sexier than F#. However, little strokes fell great oaks.

Phil Ranzhin: I am confident it will take off. The power of .NET combined with the most modern syntax and the unprecedented idiomatic concept are just bound to take off.

Roman Melnikov: The future looks incredibly promising. F# is paving its path to data analysis, thanks to type providers for example. There are also js compilers and the magic elmish library (which is in fact Elm for .NET).

Miguel de Icaza is an avid supporter of F#, so Xamarin has always had the same level of F# support as C# has. There is also a compiler in ErlangCore, which is also pretty awesome. F# can be used to code both backend and frontend. SAFE-Stack is mind-blowing stuff, with typed API calls, cool web socket wrappers (Elmish.Bridge) and tons of other stuff.

Vagif Abilov: I’m happy to hear that F# is used in practice. I work on a project of a Norwegian broadcasting company whereby the system uploads television and radio media files to the cloud to make them available for playing back from computers and mobile devices. The system is written in F# and it leverages Akka.NET. This is not our organization’s only project in F#, and what’s even more promising is that the number of such project grows as does the number of developers willing to switch to that language.

What is F# good for?


Phil Ranzhin: F# is perfect for AI development. This language is literally designed to separate my mind from any hassles and to focus on the important stuff. When you’re working on AI, your task is to adjust your mindset to the behavior of the machine. In such cases, your code is your intermediate language which is incapable of describing ideas that are too complicated. But F# is capable of being enough abstract to let you and your machine make history.

Vagif Abilov: It can be used to solve any problems, and is especially good for domain-driven design. In my last-year’s interview on Habr, I was silly to state that functional languages were applicable to algorithms and backend to a greater extent than they were applicable to the programming of user interfaces and web pages.

Someone then mentioned in the commentary section that there was a functional language Elm which was designed specifically for programming web pages. The person who left the comment was absolutely right. Since then, I started using Fable that allows writing web apps in F# and compile them to JavaScript. The effect was outstanding: the combination of F# plus Fable (and the Fable-Elmish library) opens up access to web programming for such CSS-challenged developers like me.

Pavel Smirnov: Data-driven development — it is a concise FP language with the support of type provides. Its MailboxProcessor actor model, as part of the standard library, is a treat!

Roman Melnikov: It solves web problems perfectly and integrates well with react components. It solves data analysis and machine learning problems (fslab.org), ETL problems, business logic design problems — its system of types allows to code in such a way as to avoid incorrect states.
It works beautifully for parsing (Fparsec). It’s great for designing and interpreting your own languages. Just take TypeScript – it was originally written in F#. It can be used to write GPU code.
I myself use F# instead of bash and Python to code fsx scripts for my computer.

It’s true that you can’t use it to program microcontrollers. But I guess quite a few people can do without this.

Where to get information


Books




Internet



Telegram


fsharp_news
fsharp_chat

A brief description of the community


Roman Liman: The community is fabulous: it is driven by the desire to code in F# commercially, so newbies are welcomed and offered tremendous support in a bid to grow the community and increase the members’ chances for finding jobs.

Phil Ranzhin: Those dangerous cult followers! But they are right.

Pavel Smirnov: The Russian-speaking F# community is a nice place. What I like the most is that they truly care about their favorite language, just like people do in other, better known ecosystems.

Nikolay Matyushin: That’s probably because the language is not very popular, so toxic people don’t stay.

Roman Melnikov: The community has its share of dramas that don’t affect the language itself yet make life more exciting.
Share post

Similar posts

Comments 1

Only users with full accounts can post comments. Log in, please.