F# for the C# Developer - F#, the .NET Runtime, and Aesthetics - Scott Arbeit - NDC Porto 2023
Вставка
- Опубліковано 29 лис 2024
- This talk was recorded at NDC Porto in Porto, Portugal. #ndcporto #ndcconferences #dotnet #developer #softwaredeveloper
Attend the next NDC conference near you:
ndcconferences...
ndcporto.com/
Subscribe to our UA-cam channel and learn every day:
/@NDC
Follow our Social Media!
/ ndcconferences
/ ndc_conferences
/ ndc_conferences
F# is a beautiful programming language, but learning F# when you're already familiar with C# can seem like a big task. In this session, we'll take examples from real-world F# code, and see what that code decompiles to in C#, giving you an essential low-level bridge between the languages through the .NET Runtime and IL byte-code.
While some basic functional constructs will be shown, the goal of this session is not to teach category theory and monads; it's to show how functional constructs in F# get translated into C# constructs that you're already familiar with. We'll highlight the benefits of using F# to "say" those things in succinct, robust, beautiful ways that help you write clear, maintainable code, and show how to bring some of those constructs back into C#.
At the end, you'll have an appreciation of some of the ways F# lets you write beautiful, expressive code that takes full advantage of everything .NET has to offer. Even if you never write F# yourself, this session will give you tools and new perspectives on C# that you can start applying to your projects right away for better, cleaner, easier-to-test code.
Very good talk about F#. F# needs more love.
Hi Anton. Few years ago I wanted to work with you on F# and applied to trading company where you worked. Unfortunately some HR had some weird requirements that I decided to ignore. Couple years later I started working for Microsoft and had privilege to be consulted by Scott Arbeit to use F# with DAPR cloud agnostic microservices. However you, Anton also inspired me to use F#. I just exited how small world may be specially when you are fun of F# :)
F# is awesome, great talk!
Yeeeeeaaaaaahhh, moar #fsharp. Let's go. Keep it up, let's see the good stuff.
Great talk, Thanks Stott.
Great talk!
good talk!
So what for you need F# if C# is fine & cool?
Type Inference. It's a drum I will beat all day and all night, a hill i will die on. I think it's even less that it's functional first and all that, which is of course awesome, but not having to fight function signatures because everything can be inferred is a MASSIVE speed up, especially in the prototype/exploration/"lets just get the thing working" stage.
The amount of time, as a csharp dev professionally, I spend trying to babysit the compiler for every little change is absoutely absurd, and completely unnecessary, if only they would change the type system to be able to infer more properly.
fsharp allows you to think more generically, to look at the way data is flowing through and transforming a bit more clearly. functions and data preferably separated, so you build up composable behavior on immutable data, and it ends up being a force multiplier there too, because you write great little re-usable lego pieces of code, and stack em together in new combinations really easily with the pipe operator.
Very nice to see a picture from Russian folk fairytales :)
I wish I had this F# in my C#
(would like to handle errors as values, rather than throwing exception left and right😅)
There are a few libraries that give you that functionality. If you don't want to add third-party libraries you could return a tuple or create data structures that do the wrapping. If you go the latter route you'll probably start writing Source Generators to avoid writing more code and if you do, look at the source code of the third-party libraries. There are some very good ideas 😀
In F# it is not that flawless actually, out of the box you will have to wrap everything in Result functions, which will quickly become annoying. Somebody will say that you should use computation expressions for that, but the amount of builtin CE's in F# is very limited, there is no ones for Result and Option types, and CE's do not compose, so if you find yourself in need to operate in async of result or result of async you will have to go and look for specific CE. Also there is no custom bindings like in OCaml or error propagation operator like in Rust to just stay on happy path without CE's.
So my impression was that though it is an interesting approach and F# talks mention it all the time the actual state of language doesn't provide enough support for one to feel confident enough with that choice.
Good luck with living with unmaintainable mess. Biggest f# project used by Walmart is being rewritten to Java because one of the biggest companies in the world couldn't find people to fix bugs on it because it was such a mess.
f# errors are bunch of reference types wrapped in result. and f# is not really that good to be sincere
@@konstsh2240 Async is for IO, not for the domain. Scott Wlashin has a great video on that. Yes we have to wrap everything and that can feel tedious but when it's time to refactor, it's a bliss.
Ah yes, going from filet mignon to ground chuck is always a very enticing prospect.
I know. I hate going back to csharp after knowing better.
Didn't fast f# guy switch to Odin?
He did switch his fastest portions to Odin. He writes the glue code/shell in fsharp still. Odin, by it's nature, is just so much better at the low level hardware and memory control that it blows away anything dotnet can accomplish. But fsharp is just about the best development experience a dev can get, as far as I can tell.
@@TapetBart You've got me there! I have no first hand experience in haskell, scala, ocaml, or lisp. I just know that I personally hold as most valuable the experience of having an algebraic, hindly milner type system for inference, being immutable by default, it being expression oriented and functional first, etc...
I would imagine other functional langs have a superb DX as well, but I think I would look at the ecosystem for fsharp as a pretty big advantage. Being on dotnet is pretty nice, lots of good, stable, mature libraries, lots of free perf upgrades because the work on dotnet in general give improvements across the board, etc..
@@TapetBart oh I didn't think you were! I was just saying, beats me! haha. admitting to my own lack of experience in this area, really.
Amazing talk!