Advanced Pattern Matching in C#

Поделиться
HTML-код
  • Опубликовано: 10 янв 2025

Комментарии • 28

  • @Grimlock1979
    @Grimlock1979 Месяц назад +6

    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)).

  • @DavidSmith-ef4eh
    @DavidSmith-ef4eh Месяц назад +15

    that escalated quickly... I was able to follow the first 1/4 of the video

  • @davidneale530
    @davidneale530 Месяц назад

    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.

  • @kyriosity-at-github
    @kyriosity-at-github Месяц назад +2

    The greatest thing is that we can switch without `break` now !

  • @twiksify
    @twiksify Месяц назад

    @ImmoLandwerth also utilize pattern marching in an elegant way in his Building a Compiler playlist.

  • @seriyezh
    @seriyezh Месяц назад

    Thank you so much! Is there a GitHub repo with these cool examples of pattern matching evolution?

  • @m3xpl4y
    @m3xpl4y Месяц назад

    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 :)

  • @tore28
    @tore28 Месяц назад +1

    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)
    };

  • @chickensoap
    @chickensoap 20 дней назад

    I want that font so badly

  • @vorontsovru270895
    @vorontsovru270895 Месяц назад +13

    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

    • @NickMaovich
      @NickMaovich Месяц назад +8

      I am pretty sure rewriting this code into imperative will spiral out of control much sooner

    • @christoph_wattever
      @christoph_wattever Месяц назад

      Without resharper or rider I couldn't remember how to write this syntax.

    • @NickMaovich
      @NickMaovich Месяц назад +3

      @@christoph_wattever you just need to get used to it. It's same with many functional approaches

    • @mAcCoLo666
      @mAcCoLo666 Месяц назад +8

      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.

    • @Grimlock1979
      @Grimlock1979 Месяц назад

      They are just nested tuples. That's not so difficult but maybe the var keyword breaks the visual appeal.

  • @CuriouslyContent
    @CuriouslyContent Месяц назад

    “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#.

  • @BenjaminAyala-u3l
    @BenjaminAyala-u3l Месяц назад +2

    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.

  • @parlor3115
    @parlor3115 Месяц назад

    Thank you for this! Can you do elite pattern matching next?

  • @FilipCordas
    @FilipCordas Месяц назад +11

    This man should be arrested for that tree balancing nonsense at the end 🤣 for the love of God that's a crime against humanity.

    • @DavidSmith-ef4eh
      @DavidSmith-ef4eh Месяц назад

      AI can understand it.

    • @Grimlock1979
      @Grimlock1979 Месяц назад +1

      How would you write it then?

    • @FilipCordas
      @FilipCordas Месяц назад +1

      @@Grimlock1979 like a normal human being not someone trying hard to look smart

    • @Grimlock1979
      @Grimlock1979 Месяц назад +8

      @@FilipCordas No answer. Thought so.

    • @lnfsg5136
      @lnfsg5136 Месяц назад

      Do you know how to declare variables and functions?

  • @christoph_wattever
    @christoph_wattever Месяц назад +1

    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

  • @nothingisreal6345
    @nothingisreal6345 Месяц назад +2

    That tree example impressively shows what is wrong with SW engineering.

  • @Artefact41
    @Artefact41 Месяц назад +1

    New ways to write terrible C# code.