Functional Programming With C# Using Railway-Oriented Programming

Functional Programming With C# Using Railway-Oriented Programming

Milan Jovanović

1 год назад

23,771 Просмотров

Ссылки и html тэги не поддерживаются


Комментарии:

Diego De la Fuente
Diego De la Fuente - 01.09.2023 18:28

¡Gracias!

Ответить
Angell Dark
Angell Dark - 02.07.2023 21:22

Mr.Milan, do you have this project on Gidhab?

Ответить
Christian Marpert
Christian Marpert - 27.06.2023 23:00

Hey Milan, fantastic introduction to FP. I started watching your DDD serious and then stumbled upon this one. To be honest, I am not yet deeply into C#, am rather programming in Dart for mobile. However, I use FP there to stream line exception handling. There is a well documented package called fpdart, accompanied by some blogs on functional programming. Looks like the Result type in your project corrresponds to the Either<Left, Right> type in fpdart, where Left is by convention the Failure, and Right is the Success, whereby only one state is possible. Method chaining can also be done easily.
Really enjoy your videos, as you explain the topic in a great way!

Ответить
ELH Imp
ELH Imp - 14.06.2023 20:57

Two chars: Rx

Ответить
Danimo
Danimo - 19.05.2023 12:19

I actually have a similar solution to this in my own projects, although I didn't know it actually had a name already, I just dubbed it chain validation.

I quite like this approach personally as you can just chain call validations and it is neater. I also like the result wrapper and will definitely include this, mine doesn't have this and instead throws an exception when a condition fails (I suppose in this context you would say it gets derailed), but your solution is better.

Ответить
Alex Alexander
Alex Alexander - 15.05.2023 20:45

Milan, I would appreciate if you clear one point for me. As far as I understand, we write extension methods for classes we can not change. And here you write an extension method for Email class and then edit this class. What about O from SOLID? Isn't it easier to write the method inside this Email class? I am a newbie if anything :)

Ответить
Deadbeat Pennyless
Deadbeat Pennyless - 27.04.2023 14:17

A switch would be easier to write and debug.

Ответить
Brendan Alexander
Brendan Alexander - 20.04.2023 19:34

Love the railway approach here. Tho I find these fluent statements hard to debug. Is there a way to step thru each step?

Ответить
Chris Baker
Chris Baker - 15.03.2023 12:14

Hi Milan, I've watched many of your videos and I do enjoy them. I would like to point out that you said you finished with less lines of code when in fact, you finished using more than 3 times as much code. (The original method had, effectively, 7 lines of code if you removed the blank lines and the superfluous braces). I am not a fan of using functional styles in an OO language (I don't include LINQ as it is effectively a separate language within a language). I admit that your code is more resuable though, but it's arguable as to how much reuse you will achieve. Reuse could be achieved in an imperative style too.

I worked for a company where they had taken this style of programming to the nth degree and it was a mess of functions the all did similar things but were meant to be used in differnt situations, everything had similar names wrote bucket loads of code to effectively do null checks and turned the whole thing into a framework. It was difficult to follow and there was no documentation. I know what you may be thinking, that was an example of bad coding style functional or not, well maybe, but these things tend to get abused.

IMHO if one wants to use a functional style of programming, then I would recommend F# not force an OO language to be Functional. Just my opinion Milan, please do keep up the great work that you are doing.

Ответить
Orges Kreka
Orges Kreka - 06.03.2023 18:56

What keyboard are you using ?

Ответить
Scott Baker
Scott Baker - 19.02.2023 00:48

Still waiting for more videos in this series

Ответить
UristMcFarmer
UristMcFarmer - 19.01.2023 21:02

Well, other than the cons you listed, I disagree with everything you've said. However, I don't have the wherewhithall to discuss the finer points right now. I just want to say that if one is truely committed to writing Functional code in .NET, one should probably switch to using F# so they don't have to constantly write the boiler plate backing needed in C#

Ответить
Tony Caesar
Tony Caesar - 22.12.2022 15:28

Great video. I like the approach. It looks much cleaner and self-documenting. This is especially true when coupled with the Result and static Error approach. Thanks for sharing!

Ответить
Carlos Lui
Carlos Lui - 12.12.2022 17:12

Good class,tks!

Ответить
kevin aubuchon
kevin aubuchon - 10.12.2022 01:14

Good video. These functional programming concepts are difficult to get other team members to embrace though. Some appreciate them, others simply don't understand.

Ответить
kevin aubuchon
kevin aubuchon - 10.12.2022 01:13

Great video.

Ответить
cocos cacao
cocos cacao - 10.12.2022 00:16

F# video?

Ответить
krccmsitp
krccmsitp - 04.12.2022 21:26

Interesting and straightforward as always, keep going! 👍🏼

Ответить
Bob Archer
Bob Archer - 27.11.2022 04:08

It's clever code but I'm not sure it's less code always. Depends on where you apply it. Also, as you said, it quite reduces the understanding of the code.

You could probably have written the original code with pattern matching, made it a single expression and it would be just as readable and understandable as well as made into an expression.

Also, small niggle.

Linq is not pronounced 'Lin Queue' with two syllables it is pronounced with one syllable like the word LINK. Like the character's name in Legend of Zelda. :)

Keep up the fun videos.

Ответить
BlazorPlate
BlazorPlate - 26.11.2022 18:58

Is it thread-safe?

Ответить
Just Me
Just Me - 26.11.2022 17:07

Hello, Milan. Great example, i like it. But i have some thoughts:
That example works with primitive conditions. So what if we need to process some async assertions that works with db(for example)? I heard about fluent validation, it allows you to inject you service in ctor, write your rule and call MustAsync or CustomAsync.
What you need to do (or change)in that scenario with extensions to archive that goals?

Ответить
Jeff
Jeff - 26.11.2022 15:03

Is it possible to do with async/await in ROP ?

Ответить
Major Martin
Major Martin - 26.11.2022 11:35

Good stuff. Have you ever used the FluentResult library?

Ответить
Friedrich Hayek
Friedrich Hayek - 26.11.2022 03:21

Why don't just use Haskell. Where all of this is mandatory.

Ответить
Friedrich Hayek
Friedrich Hayek - 26.11.2022 03:19

This feels like what you must do in a common Haskell program.

Ответить
Hugo Tachoires
Hugo Tachoires - 26.11.2022 02:17

Nice video, like every time ! Keep up

Ответить
GeorgeMan6644
GeorgeMan6644 - 26.11.2022 01:28

Thank you for your videos :)

Ответить
Mark
Mark - 26.11.2022 00:23

Enrico Buonanno makes the best case for functional programming in C# that I've seen. Hopefully the language will support it in a way that makes code more readable when it comes to handing multiple return types (discriminated unions).

Ответить
amit saraf
amit saraf - 26.11.2022 00:03

Good one...liked to learn more about c# functional programming...will you please share some more insight into this?....liked your work....love to learn more from you....thanks 👍

Ответить
Mohammed Albosifi
Mohammed Albosifi - 25.11.2022 23:44

Niiiiiiiiooccccccccccccce.... Thank you

Ответить
Soverain
Soverain - 25.11.2022 21:45

Functional programming, yes! Very excited to see more on this topic!

Ответить
Jochen Zeischka
Jochen Zeischka - 25.11.2022 21:22

Hi Milan, thanks for your efforts on this. It would have been nice however to give credit to Scott Wlaschin (F# for fun and profit). He invented the ROP term for this kind of functional composition. Also, it would have been better to take a different example than validation. Chaining functions which can fail would have been a good example.

Validation however, requires a different composition, because you don't want to stop validating after the first failure, but instead return info on all failures.

As you indicate, it indeed complicates the consuming code and this should not be underestimated. You did not touch the topic of composing the results, which is pretty important. Especially if some results arrive asynchronously ;-)

But my main remark is that Scott really should have been given credit in this video. Thanks.

Ответить
Piotr Wawrzaszek
Piotr Wawrzaszek - 25.11.2022 19:54

Thank you for the video Milan! ROP looks great with linear workflows. Could you elaborate on more complex cases where an object requires to validate multiple parameters on creation?

Ответить
Manuel Knörle
Manuel Knörle - 25.11.2022 19:44

A benchmark on this approach would also be very interesting. Which of the two implementations has the greater impact on performance?

Ответить
Maynard
Maynard - 25.11.2022 19:43

seems similar to fluent validation?

Ответить
mahmoud alaskalany
mahmoud alaskalany - 25.11.2022 19:37

Great One Milan Keep It Up
and can we use something like this to create automated workflows

Ответить
PrabhPahul Singh
PrabhPahul Singh - 25.11.2022 18:39

Hi, nice video, do we have github repository? To follow your videos, specifically interested in Result class, and Domain Error implementations, thank you again.

Ответить
Branislav Petrović
Branislav Petrović - 25.11.2022 18:16

Great intro to ROP!

Thanks!

Ответить
About Clean Code
About Clean Code - 25.11.2022 17:49

That reminds me of the Option module from F# which is just a bit more enhanced as it applies full set of "filter-map-reduce" (LinQ style) functions to the Option type which is modeling existence and absence of values ...

Ответить
Saif Eddine Ben Romdhane
Saif Eddine Ben Romdhane - 25.11.2022 16:48

Amazing, any idea on whether the code will be published on Github or not, i would love to dig into it. Thank you

Ответить
Duarte Silva
Duarte Silva - 25.11.2022 16:32

Fantastic video in such an interesting topic.
Looking forward to your advanced videos on this - there is not a lot of content out there (even paid content) on functional programming in C#, and I think the benefits of using it are huge. There is the amazing book Functional Programming in C# by Enrico Buonanno (now with a 2nd edition), and a nice blog from Mark Seemann.
However, at the end of the day, C# is not a functional-first programming language, and I have realised that either I move to another language, or I acept those imperative if statements.
Your video shows a practical and clean way to turn an imperative method to a declarative one. Railway-oriented programming looks very interesting and practical. Thank you for sharing, Milan - another excellent video!

Ответить
John Addo
John Addo - 25.11.2022 15:58

Wow! Interesting concept. Thanks Milan

Ответить
ajirahman
ajirahman - 25.11.2022 15:28

Thanks for the demo. Waiting for new videos. Could you share how can do xunit for this railway programming please. Could you please share an intro about what version of c# and the core.

Ответить