If you write an implicit conversion operator from a tuple to a RedBlackTree, you don't need the TT function. You can just write (R, (B, a, x, b), y, (B, c, z, d)).
Now I want to see the F# version of the tree balance function, for comparison. Great to see C# getting more options for expressing logic. Succinctness and correctness usually go together.
Last part of the video is hard to follow without looking more into all the code of the Functional programming repo which is presented. The first half of the video is good, with clear examples. By the way, much of these pattern matching samples should give more examples of them behaving as state machines, let's throw in some evil recursion too : //Use a state machine to find Fibonacci numbers, numbers that are the sum of the previous two numbers for n > 1 int Fibonacci(int n) => n switch { < 0 => throw new ArgumentException("Fibonacci numbers - negative numbers not supported"), 0 => 0, 1 => 1, _ => Fibonacci(n - 1) + Fibonacci(n - 2) };
25:54 Don't get me wrong, I really love pattern matching, but writing code like this it's just madness... Who will support this? Even the author will forget what's here in a couple of weeks not to mention the people who will be reading this for the first time. Again, I really like this language feature, but it should be used within reasonable limits. IMHO
The thing is, if you are implementing a well known algorithm, this might actually be easier to maintain as it will allow you to more closely follow the math in the original paper.
“While it may read ok to a C# person…” I assure you that a c# person would start bleeding from their eyes if they saw that balance function. To me that looks like perl, not c#.
Thank you for the presentation. That was really informative. I just wonder if anybody will ever know (or will be able to recall) all the ways you can construct these expressions.
Nice video but tbh, I think pattern matching was fumbled a little bit. Syntax is very weird, nearly impossible to remember, at least for me. Not gonna use it unless resharper suggests it
If you write an implicit conversion operator from a tuple to a RedBlackTree, you don't need the TT function. You can just write (R, (B, a, x, b), y, (B, c, z, d)).
that escalated quickly... I was able to follow the first 1/4 of the video
Now I want to see the F# version of the tree balance function, for comparison. Great to see C# getting more options for expressing logic. Succinctness and correctness usually go together.
The greatest thing is that we can switch without `break` now !
@ImmoLandwerth also utilize pattern marching in an elegant way in his Building a Compiler playlist.
Thank you so much! Is there a GitHub repo with these cool examples of pattern matching evolution?
Hallo Oli, war eine Ehre dich bei der DWX 2024 in Nürnberg dich kennengelernt zu haben, ahh und vielen Dank für das DevExpress T-Shirt :)
Last part of the video is hard to follow without looking more into all the code of the Functional programming repo which is presented. The first half of the video is good, with clear examples.
By the way, much of these pattern matching samples should give more examples of them behaving as state machines, let's throw in some evil recursion too :
//Use a state machine to find Fibonacci numbers, numbers that are the sum of the previous two numbers for n > 1
int Fibonacci(int n) => n switch
{
< 0 => throw new ArgumentException("Fibonacci numbers - negative numbers not supported"),
0 => 0,
1 => 1,
_ => Fibonacci(n - 1) + Fibonacci(n - 2)
};
I want that font so badly
25:54 Don't get me wrong, I really love pattern matching, but writing code like this it's just madness... Who will support this? Even the author will forget what's here in a couple of weeks not to mention the people who will be reading this for the first time.
Again, I really like this language feature, but it should be used within reasonable limits.
IMHO
I am pretty sure rewriting this code into imperative will spiral out of control much sooner
Without resharper or rider I couldn't remember how to write this syntax.
@@christoph_wattever you just need to get used to it. It's same with many functional approaches
The thing is, if you are implementing a well known algorithm, this might actually be easier to maintain as it will allow you to more closely follow the math in the original paper.
They are just nested tuples. That's not so difficult but maybe the var keyword breaks the visual appeal.
“While it may read ok to a C# person…”
I assure you that a c# person would start bleeding from their eyes if they saw that balance function. To me that looks like perl, not c#.
love pattern matching
Thank you for the presentation. That was really informative. I just wonder if anybody will ever know (or will be able to recall) all the ways you can construct these expressions.
Thank you for this! Can you do elite pattern matching next?
This man should be arrested for that tree balancing nonsense at the end 🤣 for the love of God that's a crime against humanity.
AI can understand it.
How would you write it then?
@@Grimlock1979 like a normal human being not someone trying hard to look smart
@@FilipCordas No answer. Thought so.
Do you know how to declare variables and functions?
Nice video but tbh, I think pattern matching was fumbled a little bit. Syntax is very weird, nearly impossible to remember, at least for me. Not gonna use it unless resharper suggests it
That tree example impressively shows what is wrong with SW engineering.
New ways to write terrible C# code.