Where’s C# headed? - Mads Torgersen - NDC Copenhagen 2022

Поділитися
Вставка
  • Опубліковано 16 сер 2022
  • Let’s take an early look at C# 11, which is scheduled to release in November. Static virtual members in interfaces will allow for much better generic abstraction over math, as well as more direct expression of abstract factories, strategies, etc.
    We’re also adding list patterns to pattern matching, a mechanism to require initialization of members, and “raw” string literals to avoid escaping, just to name a few. Finally we'll peek a little further into the future at some features we’re working on that will take longer to get right.
    Check out more of our featured speakers and talks at
    www.ndcconferences.com
    ndccopenhagen.com/
  • Наука та технологія

КОМЕНТАРІ • 54

  • @JohnWilliams-gy5yc
    @JohnWilliams-gy5yc Рік тому +30

    The auto-trimed indented unescaped string is very creative. This pattern should be in every other language already.

    • @desertfish74
      @desertfish74 Рік тому

      kotlin has trimMargin() and trimIndent() to do this.

    • @Alex-dj1rf
      @Alex-dj1rf Рік тому

      Java actually got it first :)

  • @santiagoflorez6865
    @santiagoflorez6865 Рік тому +1

    What a video bro! Can't thank you enough! Thank you so much you made life so much easier!

  • @Dmitry-Moiseenko
    @Dmitry-Moiseenko Рік тому +3

    Mads, thank you for a great talk! Looking forward to use these great new language features when C# 11 and .NET 7 will be released.

  • @userfortytwo
    @userfortytwo Рік тому +21

    " " " " " " " " " Nice presentation, thanks! " " " " " " " " " 🙂

    • @KieranDevvs
      @KieranDevvs Рік тому

      You seem to be missing some interpolation. $$$$$$$$$$$$$"""""""""""""""""""""""""""""""""""""""""{{{{{{{{{{{{{{{}}}}}}}}}}}}}}}}}}}}}{{}{}{{{{{{}}}}}}}}}{{{{{{}}}}}}""""""""""""""""""""""""""""""""""""""""""""""

  • @seanvogel8067
    @seanvogel8067 Рік тому +6

    “That was a joke.” 😂
    It was funny even. 😀

  • @frankhaugen
    @frankhaugen Рік тому +18

    My nuget with a HUGE amount of generated extension methods is now obsolete :-(

  • @alirezanet
    @alirezanet Рік тому

    Amazing presentation and features 👏👏

  • @mcmaddie
    @mcmaddie Рік тому +1

    I don't even use C# yet here I am watching/listening this...

  • @xionwin5514
    @xionwin5514 Рік тому +1

    OHHHH, very exciting features, The INumber related is what I have been looking forward to for many years.

  • @nmarcel
    @nmarcel Рік тому +21

    I love the Static members in Interface features. However I think that math focused example of application is way less required and useful than using it for common applications such as to centralize metadata like entity model info or behavior like business rules or so (i.e. require less or no extension methods or reflection).

    • @ryan.crosby
      @ryan.crosby Рік тому +4

      Agreed, generic math is very cool (great for the BCL to include), but for end developers there are a lot of other opportunities to use static members on generics via interface constraints. Factories are one usecase (as mentioned).
      Personally I have usecases in EF Core where an interface returns a different Func depending on concrete type, which will in turn generate different SQL queries when EF gets to it. In this way I can significantly reduce the amount of duplicate code in the codebase by writing generic extension methods over an interface which in turn define a single LINQ query that organically changes based on which type is used.
      I already do this with reflection... I basically define the method on the interface as a normal interface method, but in the implementation I make sure to never touch the "this" reference. Then I use Delegate.CreateDelegate to create the delegate manually with a "null" this reference, allowing the method to be called as if it were a static method (without instantiating the object), even though it's really an instance method. Once I get C# 11, I can swap all of that code right out and it'll be beautiful ✨

    • @modernkennnern
      @modernkennnern Рік тому +1

      I'm still stuck in .Net Framework land (I honestly hope Microsoft just fully ends support for it soon, so we _have_ to convert our projects, but that won't happen anytime soon unfortunately.. (Not that we'd swap even if they did >_>). Thankfully almost every feature added to C# since 8 (The first version of C# not officially suppported in Framework) does work. Practically only the interface-specific ones don't.
      That's a long pointless tangent. All to say; I had a scenario last week where an static abstract interface member would've been useful, but I couldn't use it, so I had to resort to instantiating each type just to get metadata, which feels so wrong.

    • @phizc
      @phizc Рік тому +1

      While it's true most people won't need to make types that implement INumber, it's an easy example to show what's possible. Generic math has already been used to trim a lot of duplicate code in the BCL. E.g. LINQ's Sum method.

    • @ewdlop1
      @ewdlop1 Рік тому

      it is just an example

  • @Jankoekepannekoek
    @Jankoekepannekoek Рік тому +2

    Oh cool, so C# interfaces can now be used as type classes, nice!

  • @lancemarchetti8673
    @lancemarchetti8673 Рік тому

    YaY! From Cape Town South Africa...great 😃...sea the sharp canon !!

  • @def1nt
    @def1nt Рік тому

    I wanted this new string literal format for so long, so I could just slap an entire html page into my string. Also good for sql.

  • @RobertGeorgeAtkinson
    @RobertGeorgeAtkinson Рік тому

    Given all this new cool stuff, I'm a little surprised to see just INumber and not IRing, IField, etc. Was that considered?

  • @jaiderariza1292
    @jaiderariza1292 9 місяців тому

    the new namespace System.Numerics :)

  • @ryanlashkevich9615
    @ryanlashkevich9615 Рік тому +4

    Yeah, number of dollar signs solves a lot of problems nowadays 😏

  • @spoonfuloftactic
    @spoonfuloftactic Рік тому

    I'm smelling a new version of Pegasus.

  • @larsthomasdenstad9082
    @larsthomasdenstad9082 Рік тому +1

    Dude, you're Norwegian enough for me. :)

  • @otilionunezmaciel8951
    @otilionunezmaciel8951 Рік тому

    everytNice tutorialng, I really would pay for a webclass

  • @sps014
    @sps014 Рік тому +16

    Discriminated Unions,
    Struct finalizers
    Move semantics,
    In C# please 🥺

    • @IshCaudron
      @IshCaudron Рік тому +1

      Why?

    • @martinprohn2433
      @martinprohn2433 Рік тому

      I wanted to ask the same question: Why? If you need all that, why not use C++/CLI directly for that.
      But speaking of which, C++/CLI could support C++20 things like std::thread and stuff like C++ lambdas, which is about supported yet. It makes writing .net in C++ much harder not having these syntactic sugars.
      On the other hand, it is s great way to really understand what happens in C# under the hood, if you have to write it verbosely in C++.
      (Sorry, I think I drifted a little from the actual topic.)

    • @sps014
      @sps014 Рік тому +3

      @@martinprohn2433 c++/cli is windows only

    • @obinnaokafor8125
      @obinnaokafor8125 Рік тому

      DU only

    • @martinprohn2433
      @martinprohn2433 Рік тому +1

      @@sps014 You are probably right, I didn't thought of that.
      But I'm still not sure, that putting all those C++ concepts into C# is a good idea.
      Maybe instead it would be a better idea to improve C++/CLI to work on different platforms. Or create a possibility to create pure .net assemblies with C++ instead of mixed assemblies, like with C++/CLI.

  • @neroamayo6345
    @neroamayo6345 Рік тому

    Why not instead of public required string FirstName {get; init} just have something like public string FirstName {get; required;} . it's more clean and required implies it should be initialized like init. am I missing something here?

  • @b33j4y
    @b33j4y Рік тому

    32:00 - Why can't the compiler determine the type of T? (It's not because of a preview version - current VS2022 behaves the same)

    • @FlameRat_YehLon
      @FlameRat_YehLon Рік тому

      Checked a bit of document and my guess is that because double[] isn't inheriting or implementing Span there's no way for the compiler to know which T to use.
      Not sure if it's possible to figure out generic types using implicit conversion (posible means that there's mathematical proof that it can always work), but it's reasonable that it isn't working yet.

    • @b33j4y
      @b33j4y Рік тому

      @@FlameRat_YehLon True, they are different types, but I've passed double[] to methods that take Span lots of times before. Don't think there was anything special about them

    • @FlameRat_YehLon
      @FlameRat_YehLon Рік тому

      @@b33j4y The only reason you can pass T[] to Span is that there's an implicit conversion being implemented. And this doesn't say anything about if you don't specify the T, would the compiler still be able to know which T it is.

  • @denischudinov2379
    @denischudinov2379 Рік тому

    I wander why to not introduce backticks ` ` instead of multiple quotes " " ?
    Like JavaScript does.

    • @fabioluizalvaresosti7115
      @fabioluizalvaresosti7115 Рік тому

      Because of languages that have like portuguese that have backticks like in à

    • @denischudinov2379
      @denischudinov2379 Рік тому

      ​@@fabioluizalvaresosti7115 But this code works perfectly in JS with backticks:
      var a = `à`;
      Did I get you wrong?

  • @dlg75
    @dlg75 Рік тому

    What happens when your string literal starts or ends with a double quote? Can you still win?

  • @bigbtripathi
    @bigbtripathi Рік тому

    There are new age languages like Rust, Go, Carbon and Zig etc which are much faster. Even Python, JavaScript, Java are also working to make the language/framework faster. Seems everybody working towards increasing performance. Can C# be made faster ?

    • @Mr7Shane
      @Mr7Shane Рік тому +3

      People don't use languages based on how fast their are? Nobody uses rust, go, zig. C# is already 100x faster then python and yet python is more popular.

    • @MasterOfMisc
      @MasterOfMisc Рік тому

      In .NET 7, you can compile your app with AOT (ahead of time). You end up with an app that is self-contained and that has been compiled to native code. The app will start up very quickly and use less memory. It would be nice if benchmarking sites like techempower would use test the AOT version of C# as well as the normal JIT (just in time) version to see how it stacks up against C++, GO and Rust

  • @dennisfruhauff6295
    @dennisfruhauff6295 Рік тому

    I struggle to see the obvious benefit I'd have with static interface members for factories... can anybody give me a simple example?

    • @ciberman
      @ciberman Рік тому +3

      If you don't see the benefits it's because you never had a full tree hierarchy with 20+ classes and 20+ factories for each one of those classes 😂

  • @user-ey9yo3fd6t
    @user-ey9yo3fd6t Рік тому

    😂🙏😀💥

  • @daitedve1984
    @daitedve1984 Рік тому +1

    C# is rolling down to cloaca. Useless, half-baked, stupidly implemented features completely stop me from watching C# progress - I stopped at C# 8.0 and don't want to see your(Torgersen) work anymore.

    • @halvarf
      @halvarf Рік тому +4

      Make a good video or blog post about what you mean and you will surely get a lot of attention. Ranting in a UA-cam comment and just claiming instead of showing is pointless.
      From your comment, you could just be a bad old grumpy programmer unwilling to learn anything new (there are definitely a few of those in the C# community).