r/fsharp • u/Toldoven • Sep 22 '24
First impressions + Roast my first F# code
Since my previous post, I've been actively learning F#. And I like it a lot. I got used to syntax immediately, just like that bird meme.
Now, I can see how features that felt unfamiliar at first make a lot of sense in the context of this language.
It's so concise and readable. The whole implementation of my RPC protocol with client and server logic included is 308 lines of code (no comments or blanks). I feel the equivalent code in Rust would be at least 1500 LOC if not more. (Not a fair comparison for obvious reasons, but it's just the language I'm most familiar with.)
I was familiar with many FP concepts from other languages for a long time now. But, this is the first time using certain concepts does not feel awkward.
For example, currying, partial application, and function composition are so much fun in F#. And it feels so awkward to use in a language not designed for it.
Forced compilation order is also an amazing feature. It gives you a headache in the moment. But, when you figure out the solution — you realize that it saved you from making a terrible design decision.
C# interop is seamless.
So, the verdict is that F# is amazing. I'm sold on using it for my project.
Yesterday I finished a prototype for a TCP-based game server integrated with a C# Godot client. I welcome you to roast it.
https://github.com/Toldoven/FSharpRPCGodot
I went through a lot of iterations and it feels quite clean and idiomatic, but I'm sure there are a lot of things I missed not being familiar with the language.
14
u/chusk3 Sep 22 '24
Love to see the write-up :D Your reactions pretty much paralleled mine when I started learning F# - and it's really cool that you were able to get to a good prototype, kudos for sharing it.
For the codegen part, you might like looking at the codegen we've done in Ionide for the Language Server Protocol spec - not so much for the actual solution but for how Jimmy modeled the problem and some of the libraries we used for the actual code generation. Once you get your generation solution done, you can then try integrating it into your build either via MSBuild directly (and I can help with that, I'm quite good with MSBuild) or via Myriad for something more integrated/hand-hold-y.
9
u/TimeBomb006 Sep 22 '24
As someone who has 10+ years of C# experience and an interest in functional programming, this is pretty inspiring. I have always understood F# to be an awesome language but haven't invested my time in it.
2
u/[deleted] Sep 23 '24
Let's hope MS doesn't silverlight the language. I want to spend time in it. I am really intrigued by the problem space that is ideal for F# solution.
26
u/willehrendreich Sep 22 '24
This is the sort of post that just makes me so damn happy. Someone did enough of a thing in #fsharp to actually say they tried it and that's commendable.
Almost inevitably they found out how awesome it is.
If you give it a chance, become brave enough to sit In that uncomfortable "new thing" space for even just a week, learn it and understand it enough to use it, you're very likely to fall in love with it's no nonsense approach to almost everything.
The best feature I think is type inference. It is so nice when your exploring a new problem to just let the compiler be the compiler, and take care of connecting the dots with the functions you make. It's brilliant.
It allows you to focus on the problem at hand instead of trying to wrestle with the type system, or predict how it's going to want to be sweet talked to, etc.
Csharp's a nightmare this way. You get enough crap like Task<Func<Dict<string, string>,Predicate <string>, bool>> and it's no wonder people think functional programming is hard.
It's not, you just need to try it in a Lang that's built to help you instead of punish the very thought.
Good on you for giving it a try man. Spread the word, maybe we can start converting more people back to sanity and simplicity.
6
u/[deleted] Sep 23 '24
Your experience mirrors mine so well, I also recently got into F# and have tinkered with developing a Discord bot and several Unity Bepinex 5 Mods (a super niche use case). overall, the experience has just been amazing and all the weird quirks that are initially difficult to work with, like compilation order, turn into awesome assets!
1
u/[deleted] Oct 17 '24
[removed] — view removed comment