Zoran Horvat
Zoran Horvat
  • 160
  • 1 247 347
You’ll Never Write Functional C# Code if You Don’t Know This
First-class functions, among other things, means you can apply a function to a function to obtain a function. Did you get it?
C# supports first-class functions, but not always in the most obvious ways. This video will put your understanding of first-class functions to a test. If you can decipher it, you can progress to learn more about functional design in C#. Otherwise, the best course of action is probably to stop and try to understand this critical concept. It is up to you.
Download source code ► www.patreon.com/zoranhorvat
Join Discord server with topics on C# ► codinghelmet.com/go/discord
Enroll course *Beginning Object-Oriented Programming with C#* ► codinghelmet.com/go/beginning-oop-with-csharp
Subscribe ► ua-cam.com/channels/xsWfh8LCcn55mFB6zGBT1g.html
▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬
👨 About Me 👨
Hi, I’m Zoran, I have more than 20 years of experience as a software developer, architect, team lead, and more. I have been programming in C# since its inception in the early 2000s. Since 2017, I have started publishing professional video courses at Pluralsight and Udemy, and by this point, there are over 100 hours of the highest-quality videos you can watch on those platforms. On my UA-cam channel, you can find shorter video forms focused on clarifying practical issues in coding, design, and architecture of .NET applications.❤️
▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬
⚡️COPYRIGHT NOTICE:
The Copyright Laws of the United States recognize a “fair use” of copyrighted content. Section 107 of the U.S. Copyright Act states: “Notwithstanding the provisions of sections 106 and 106A, the fair use of a copyrighted work, including such use by reproduction in copies or phono records or by any other means specified by that section, for purposes such as criticism, comment, news reporting, teaching (including multiple copies for classroom use), scholarship, or research, is not an infringement of copyright." This video and our UA-cam channel, in general, may contain certain copyrighted works that were not specifically authorized to be used by the copyright holder(s) but which we believe in good faith are protected by federal law and the Fair use doctrine for one or more of the reasons noted above.
#csharp #dotnet #functionalprogramming
Переглядів: 4 826

Відео

Have You Ever Signaled async/await Progress in These Three Ways?
Переглядів 8 тис.19 годин тому
Tasks have greatly simplified synchronization and data marshaling, which we can use quite effectively to transfer progress information back from the running task. There is always a ton of synchronization code at the back, but we shall never have to write that code. That is the beauty of working with .NET tasks. But the story does not end at the basic scenario. Have you ever thought of what data...
Master the Design of Functional Types in C#
Переглядів 10 тис.14 днів тому
Check out Dometrain and use code ZORAN for 15% off any course ► dometrain.com/?coupon_code=ZORAN The 1980s are over. The new C# does not work well with old habits. Get rid of them and dive into modern-day programming. The road to learning begins with understanding why C# becomes progressively more functional with every new version. Yet, most C# programmers do not know what is functional there o...
Clean Code Tip: Avoid Deep Nesting
Переглядів 6 тис.21 день тому
Clean Code Tip: Avoid Deep Nesting
Deep Dive on Locks & Deadlocks for Application Developers
Переглядів 5 тис.28 днів тому
Deep Dive on Locks & Deadlocks for Application Developers
How Do You Cancel an async Method? | Step-by-Step Tutorial
Переглядів 5 тис.Місяць тому
How Do You Cancel an async Method? | Step-by-Step Tutorial
C#, Dapper & SQL: Interview Questions With Answers
Переглядів 4,1 тис.Місяць тому
C#, Dapper & SQL: Interview Questions With Answers
When and How To Apply CQRS in an ASP.NET Core Application With EF Core
Переглядів 6 тис.Місяць тому
When and How To Apply CQRS in an ASP.NET Core Application With EF Core
The Secret of Unit Testing I Learned by Failing
Переглядів 3,8 тис.Місяць тому
The Secret of Unit Testing I Learned by Failing
How to Implement Strongly Typed IDs with EF Core and ASP.NET Core Razor Pages
Переглядів 4,4 тис.Місяць тому
How to Implement Strongly Typed IDs with EF Core and ASP.NET Core Razor Pages
Enjoy Strongly Typed Code Again With Covariant Return Types
Переглядів 6 тис.Місяць тому
Enjoy Strongly Typed Code Again With Covariant Return Types
Master The L in SOLID
Переглядів 6 тис.2 місяці тому
Master The L in SOLID
Unveil the Mystery of the Liskov Substitution Principle
Переглядів 6 тис.2 місяці тому
Unveil the Mystery of the Liskov Substitution Principle
Learn C#: Method Hiding (and Why You Will Want To Avoid It)
Переглядів 4,2 тис.2 місяці тому
Learn C#: Method Hiding (and Why You Will Want To Avoid It)
Validating Records in C#: Everything You Ever Wanted To Know but Had No One To Ask
Переглядів 7 тис.2 місяці тому
Validating Records in C#: Everything You Ever Wanted To Know but Had No One To Ask
Learn C#: How Do Virtual Methods Work?
Переглядів 5 тис.2 місяці тому
Learn C#: How Do Virtual Methods Work?
The Lesson About GUID IDs I Learned the Hard Way
Переглядів 27 тис.2 місяці тому
The Lesson About GUID IDs I Learned the Hard Way
Learn C#: Abstract or Virtual Method, Which Fits Better Here?
Переглядів 9 тис.2 місяці тому
Learn C#: Abstract or Virtual Method, Which Fits Better Here?
This Is How Domain-Driven Design Makes Object-Oriented Design More Powerful
Переглядів 9 тис.3 місяці тому
This Is How Domain-Driven Design Makes Object-Oriented Design More Powerful
Avoid This Common Mistake in DDD Modeling
Переглядів 8 тис.3 місяці тому
Avoid This Common Mistake in DDD Modeling
Learn To Love DDD-Style Strongly Typed IDs
Переглядів 22 тис.3 місяці тому
Learn To Love DDD-Style Strongly Typed IDs
Let C# Tuples Become Your Best Friends
Переглядів 8 тис.3 місяці тому
Let C# Tuples Become Your Best Friends
The Ultimate Guide to C# Records
Переглядів 13 тис.4 місяці тому
The Ultimate Guide to C# Records
Here is How Fast is LINQ, Spans, and Everything
Переглядів 10 тис.4 місяці тому
Here is How Fast is LINQ, Spans, and Everything
This Is the Place for LINQ in Modern .NET Design
Переглядів 8 тис.4 місяці тому
This Is the Place for LINQ in Modern .NET Design
17 Pieces of C# Syntax That Make Your Code Short
Переглядів 17 тис.4 місяці тому
17 Pieces of C# Syntax That Make Your Code Short
3 Shocking Misconceptions Among C# Programmers
Переглядів 13 тис.4 місяці тому
3 Shocking Misconceptions Among C# Programmers
Will All My Classes Look Like Records Now?
Переглядів 6 тис.5 місяців тому
Will All My Classes Look Like Records Now?
Why is C# Evolving This Way?
Переглядів 20 тис.5 місяців тому
Why is C# Evolving This Way?
Getting Started With Azure Storage | Tutorial
Переглядів 3,8 тис.5 місяців тому
Getting Started With Azure Storage | Tutorial

КОМЕНТАРІ

  • @pharoah327
    @pharoah327 9 годин тому

    Won't this cause us to always check each moving ability to see which is null and which isn't? Every time I want to do something with a vehicle object, I'll have spaghetti code if statements checking to see which ability it has that's not null. Don't get me wrong, this solution clearly has benefits over inheritance but let's be clear about the drawbacks too.

  • @FunWithBits
    @FunWithBits 12 годин тому

    nice... I use c# all the time and did not know this and wish it had this. Now we just need a myValue.ClampToZero() extension. (myValue < 0 ? 0 : myValue) This is instead of Math.Max(0, MyValue).

  • @0XAN
    @0XAN 14 годин тому

    i'm afraid C# is becoming a language for wankers

  • @okcharles7
    @okcharles7 14 годин тому

    This time, the Turkish Ice cream man flips too long for the C#hildren to take the F#luffy.

  • @user-xc8wv5mz5u
    @user-xc8wv5mz5u 15 годин тому

    (Native speaker is Chinese, the following is from machine translation) Suddenly I realized that using static actually breaks the boundary between object-oriented programming languages and functional programming languages.

  • @ayoubrayanemesbah8845
    @ayoubrayanemesbah8845 17 годин тому

    Lean

  • @creepy99
    @creepy99 17 годин тому

    Code is, on average, written once and read 10x. Write your code to be easily read and understood. If I have to do mental olympics to read and understand your code, it's probably too condensed. Shorter != better.

    • @zoran-horvat
      @zoran-horvat 15 годин тому

      Which line of code is that?

    • @creepy99
      @creepy99 15 годин тому

      @@zoran-horvat Sorry... I was not talking directly to you. I meant the general "you", as in the person that wrote whatever code I'm reading. I prefer the first line in the Car example because it's clearer (to me). I don't have to think or look something up, it's just clear from the start. Hope that clears things up... sorry for the confusion.

  • @F2H16
    @F2H16 19 годин тому

    Amazing! You are an articulate person, it would be nice to get a DDD course (An affordable one) from you. It would have covered your programming mastery and eloquence to deliver the goods.

  • @m31coding
    @m31coding 21 годину тому

    Thank you very much for this great video! The advantages of fluent interfaces become very clear. However, for complex use cases, writing a fluent interface can become tedious. To address this, you might find the M31.FluentAPI source generator library I created helpful. Happy coding!

  • @dusanknezevic9072
    @dusanknezevic9072 День тому

    Well. It's awesome that you can do this. Convolutedness of signatures is a bit of a problem. All delegate types are incompatible with one another even if they have the same signature (seen as different types by compiler). You can get around this by explicitly typing (wrapping) one. Prime example is that you can't assign Func<A, bool> to Predicate<A> and vice versa. It's gonna be interesting to see how C# tackles these incoveniences. Functional first languages win here. Like Haskell or F#.

    • @zoran-horvat
      @zoran-horvat День тому

      Incompatibility of delegates is not an inconvenience - it is intentional. The same situation is with classes. Their objects are not assignable to each other even when the two classes have the same shape.

  • @Myself0094
    @Myself0094 День тому

    In whole honesty this is exactly where functional C# loses to regular F# and where it becomes obvious it’s not functional first. It sure can be functional enough, but should it?

  • @Rein______
    @Rein______ День тому

    Do this at work just to troll everybody. You dont understand it? Your problem. Lol!

    • @zoran-horvat
      @zoran-horvat День тому

      That is what makes it a good joke, I guess.

  • @Curlack
    @Curlack День тому

    To return items from primary of alternate if primary contains nothing. Couldn't we also use two foreach loops where first will set found boolean and afterwards return if found?

    • @zoran-horvat
      @zoran-horvat День тому

      Some sequences throw when you try to iterate them twice. For example, streams do not support multiple iterations in general, and so a sequence deserialized from a stream would throw.

    • @Curlack
      @Curlack День тому

      @@zoran-horvat was thinking more in the lines of the following code (see found variable): public IEnumerable<DiscountApplication> GetDiscountAmounts(Money price, DiscountContext context) { var found = false; foreach (var discount in _primary.GetDiscountAmounts(price, context)) { found = true; yield return discount; } if (found) yield break; foreach (var discount in _alternate.GetDiscountAmounts(price, context)) { yield return discount; } }

  • @LordErnie
    @LordErnie День тому

    I agree with your description of functional programming. I agree to most of what you do. But there is one slight problem. Functions aren't first class citizens in C# as far as I know. Functions cannot exist on their own. They must exist on a class. A delegate is basically a type description for a function. Its header becomes its type in a sense, because it is. But a description is not a concrete instance. Those must live in the form of methods on objects. Even static methods are just tricks, they are still part of a class. A first class function can live on its own. That means no classes. It can be created, defined, all without a class, or a type, it just exists. Static methods are just a trick (in a sense, they do have use in an OO context these days within C#). Delegates are indeed WAY nicer then only using Func and Action! I agree. Makes it look more like Haskell, where every function needs an abstract type definition (not called that, but we get the idea).

    • @zoran-horvat
      @zoran-horvat День тому

      Delegate types exist outside enclosing classes, and they are functions.

  • @DmitriNesteruk
    @DmitriNesteruk День тому

    Why have ToOption() when you can just have an implicit conversion operator from T to Option<T>? That way you can transparently declare parameters of type Option<T> and pass ordinary objects into them. Also, why not have `public static Option<T> None = new();` as a single instance? There is no real need to have it as a method. In fact, you could sacrifice type information and introduce a non-generic (Value)Option<T> just to have a `None` member so it could be referred to without extra type information.

  • @DmitriNesteruk
    @DmitriNesteruk День тому

    The use of terminology here is not 100% correct, because normally `Reduce()` does a completely different thing. The correct term here would be something like `Otherwise()` or something to that effect. `Map()` is more correct though you could equally call it `Select()` (per LINQ terminology), `Take()` or something else. Also, in `GetLabel()`, the initial call to `person.` can throw if it's null, and this call isn't handled here by the Maybe monad.

  • @7th_CAV_Trooper
    @7th_CAV_Trooper День тому

    I'm going to have to watch this a few times. My OO ordered brain resists the truth. :)

    • @1992jamo
      @1992jamo День тому

      Functional programming can be excellent, but this is unreadable. The delegates hide the structure of the actual functions and when it's this nested it's a nightmare. Without putting words in Zoran's mouth, I think that he's showing the power of containing state within expressions rather than classes. But going between 5 layers of functions and their abstract representations as delegates seems a bit much to me when we're literally just filtering a collection.

  • @websystema
    @websystema День тому

    Thanks for the video

  • @prakashKumar-zj8nw
    @prakashKumar-zj8nw День тому

    This type of expert level coding gives me orgasm😂

  • @10199able
    @10199able День тому

    mind blown!

  • @XXnickles
    @XXnickles День тому

    You just showcased one of the main barriers I have had with functional paradigms in c#: the complexity in the signatures. Whether we like it or not, c# is not designed for this, and this is a real pain in the rear end specifically when you work on a team and people have a hard time following (heck, I have tough times myself!) With that said, that trick with the delegate definition is a good one that I am taking note of it. What a shame that currying has to be this complicated (in terms of readability) as it is one of those functional tools that can be very handy in several scenarios to remove a bunch of interfaces and abstract clases. Great explanation!

    • @zoran-horvat
      @zoran-horvat День тому

      C# will hardly advance further in readability, unfortunately.

    •  День тому

      Viewability and listenability are the future, so don't care.

    • @zoran-horvat
      @zoran-horvat День тому

      I like the way you formulated it.

  • @1992jamo
    @1992jamo День тому

    So we're using FilterBooks to return a delegate of type Filter<BookType> which is extended by the static extension method "for", which takes a function that returns Task<IEnumerable<Books>>, and returns a function that has a search string parameter, and then this function is passed to the PromptAndReport method which matches the FilteredDataSource<BookType> delegate? Then finally, it pass it a string to do the filtering? My God.

    • @zoran-horvat
      @zoran-horvat День тому

      That's it :) Now, the reason! The reason is that one function knows the data source and another function knows the phrase. Neither should depend on other's data, so the delegate arithmetic comes to the picture. It is the direct inverse of traditional dependency injection in OOP.

    • @1992jamo
      @1992jamo 17 годин тому

      @@zoran-horvat I have to admit Zoran, it took me longer than I care to admit to work out what I was seeing. Clearly you are a very talented and experienced developer, but the delegates hide so much that it's extremely hard for me to read without seeing their definitions. As always, thanks for the video as I have learned lots. I didn't even realise that functions could be extended. It's also very interesting to see how state can be entirely contained within functions.

    • @zoran-horvat
      @zoran-horvat 12 годин тому

      @@1992jamo I told you it is going to be difficult :) But those things you have seen in the end, that is the important lesson. Give it some time, and you will see that it will change the way you look at the functions and delegates, not only in C# but in any language.

  • @Naton
    @Naton День тому

    as much as i like FP, i worry my juniors wont be able to understand my convoluted delegates

    • @zoran-horvat
      @zoran-horvat День тому

      True, they won't. It takes a lot of experience and even more formal knowledge to start to appreciate functional designs.

    • @Robert-yw5ms
      @Robert-yw5ms День тому

      I had a senior recently not understand the curried function I'd written. That one surprised me.

    • @zoran-horvat
      @zoran-horvat День тому

      @@Robert-yw5ms Currying requires a wider view on functions to understand. A litmus test is for someone to answer why F# functions have no parentheses around arguments.

    • @UwuseSawase
      @UwuseSawase День тому

      ​@@zoran-horvat Do i have to know the mathematical background also, to get very good at funktional programming?

    • @zoran-horvat
      @zoran-horvat День тому

      @@UwuseSawase You should have a clear understanding of mappings and functions. That is primarily algebra, rather than mathematical analysis, for example.

  • @1lem0nati0n5
    @1lem0nati0n5 День тому

    Program.cs line 10 is dataSource a great name for the argument?

  • @danilodjokic5303
    @danilodjokic5303 День тому

    Great video, really puts into perspective how C# has been evolving over the years. How often do you get to write this type of code in production? Do you find it confuses people that are accustomed to the traditional OOP way of doing things, how do you get over that? Pozdrav iz Finsoft/Fincore-a !

    • @zoran-horvat
      @zoran-horvat День тому

      This is the regular coding pattern when designing pure functional code. It is not common to see this kind of code mixed together with OOP design.

  • @martinprohn2433
    @martinprohn2433 День тому

    Well thanks for the video. My personal opinion is, that I would have stopped before the introduction of "OrElse". I find the "FirstOf()" outer call clearer, because all three calls inside are on the same level. With OrElse on the other hand, the first call is outside the OrElse method call, but the other two inside OrElse. I find that ugly. But that’s probably just my opinion. For the same reason I prefer "Enumerable.Zip(a,b,…)" instead of "a.Zip(b, …)". (Usually with line breaks between the parameters.)

  • @Joanarkj
    @Joanarkj 2 дні тому

    I understood nothing. 😢

    • @zoran-horvat
      @zoran-horvat 2 дні тому

      Watch again. This is literally the single point you should understand, and once you do...

    • @abj136
      @abj136 День тому

      @@zoran-horvat There’s many C# features used here that I’m not familiar with. What means “b!”? What do delegates do in this context? Also I constantly lost track of definitions and had to scrub back and forth through the video to get what you were referencing. And the final point of difficulty is not understanding WHY all this indirection would exist. I can do this same function without all these.

    • @zoran-horvat
      @zoran-horvat День тому

      @@abj136 Can you?

    • @David-id6jw
      @David-id6jw День тому

      @@abj136 The "b!" is easy enough to explain. "!" is the null forgiving operator. If you're using nullable reference types, you use "?" to designate that a variable or return type can be null. His Create() functions return things like "BookType?" (this was shown in a recent video he did - Master the Design of Functional Types in C#). So his "a" and "b" variables could potentially be null if the creation logic failed. However, since this is a demo, he knows that those are not going to be null, and doesn't want warning squiggles distracting from what he's talking about. So he uses the "!" operator to say, "I definitely know that these are not null, even if the analysis logic says they might be, so don't show me any warnings about them." Basically, they're not related to the topic he's trying to explain, just part of the general C# syntax.

  • @YordanTGeorgiev
    @YordanTGeorgiev 2 дні тому

    I really try to understand your videos, but for some reason most of them are not clear at all😶

    • @zoran-horvat
      @zoran-horvat 2 дні тому

      This particular detail is hard. But once you clarify it, you'll be looking at functions in an entirely new way!

    • @colcoomagnumar
      @colcoomagnumar День тому

      Me too. But I love Zoran’s presentation style and I keep repeating videos until things start to click. I don’t converse like this with my fellow developers so I’m just a bit rusty and Zoran sets an excellent standard to rise to.

    • @d2pgoon86
      @d2pgoon86 День тому

      There are a couple reasons for this: 1. He moves quickly in his demos. I ⏸️ and ⏪ all the time to clarify details that he might gloss over. I prefer this now as I don't need to sit thru mind numbing tedious explanations. 2. He focuses strictly on the topic, so if something he does is unclear (say with the bare Func signatures), it's mostly on you to figure it out. 3. He's now skipping over refactorings like Func -> BookFilter etc., because that's now understandably hidden behind Patreon. I've come to love Zoran's style as he speaks to you like a young child but does not treat you as one--you must come prepared with knowledge of c#, because he focuses on the abstractions which is where the real learning happens. Just keep watching and it'll click!

    • @1992jamo
      @1992jamo День тому

      @@d2pgoon86 I think point 3 is the most important. Especially since the delegates hide parameters.

    • @chrisspire
      @chrisspire День тому

      I am a beginner developer (well, I did that 20 years ago as a hobby in school) and I went through Zoran's tutorials on Udemy to refresh and update my knowledge. They were phenomenal and easy to understand. Most of the stuff here on YT is too advanced for me but I could not find better source of C# knowledge on the internet than Zoran!

  • @Robert-yw5ms
    @Robert-yw5ms 2 дні тому

    The main use case I've found for currying has actually been in UI logic. I.e. you have some inputs that should trigger redraws of other parts of the UI along with some other custom actions? Tedious without currying, simple with currying.

    • @zoran-horvat
      @zoran-horvat 2 дні тому

      That makes sense. Currying is closely related to dependency injection, in the sense that it applies to scenarios where one party provides dependencies and other party provides parameters.

    •  День тому

      My practical experience says me to not care about UI LOGIC so much. UIs are rewritten each 5 years.

  • @shadowsir
    @shadowsir 2 дні тому

    You have to admit F# reads a heck of a lot easier than whatever this C# "we must define everything" mess is... 😅

    • @zoran-horvat
      @zoran-horvat 2 дні тому

      It is not a mess, but yes, F# syntax is streamlined.

    • @Robert-yw5ms
      @Robert-yw5ms 2 дні тому

      I've barely dabbled with f#, so this is a genuine question: is the type inference really powerful enough to work out what all the types here would be without being told?

    • @zoran-horvat
      @zoran-horvat 2 дні тому

      @@Robert-yw5ms Almost always yes, but the implementation of the compiler must change. The type resolution might sometimes need to wait until the time it is used. In the meanwhile, the compiler might go along with rough guesses. As a last resort, F# settles down with a guess, such as always assuming some numeric type is int unless proven otherwise. I am not the best source for questions regarding the F# compilation process, I must say that, too.

    • @shadowsir
      @shadowsir День тому

      @@Robert-yw5ms Hmm, in this case, you'd probably want to define the input types. let filter (dataSource: Async<BookType seq>) (phrase: string) = async { let! bookTypes = dataSource return bookTypes |> Seq.filter (fun bookType -> bookType.Title.Contains(phrase, StringComparison.InvariantCultureIgnoreCase)) } The return type would just be deduced, no need to specify it. We usually create a function to be able to "map" an Async, so without the computation expression: let filter (dataSource: Async<BookType seq>) (phrase: string) = dataSource |> Async.map (Seq.filter (fun bookType -> bookType.Title.Contains(phrase, StringComparison.InvariantCultureIgnoreCase))

  • @MehediHasan-xd6rj
    @MehediHasan-xd6rj 2 дні тому

    Please take 1000 likes and thanks from me for your excellent Job. I am following you from the Pluralsight course. I have become a fan of your UA-cam videos.

  • @shauas4224
    @shauas4224 3 дні тому

    I use this very often in unity

  • @Ben-nc9qw
    @Ben-nc9qw 3 дні тому

    ua-cam.com/video/KFx9XHpoYV4/v-deo.html "Without further validation..." doesn't this lead to a runtime validation error though if someone casts an empty string to a NonEmptyString? even without having to cast and reversing the implicit operator you would get a runtime exception and provides no guard against someone creating a book with an empty title? ---LinqPad--- void Main() { var myString = "test"; var myEmptyString = ""; var book = new Book(Title: myEmptyString); book.Dump(); } public record struct NonEmptyString(string Value) { public string Value { get; init; } = !string.IsNullOrWhiteSpace(Value) ? Value.Trim() : throw new ArgumentException("Value cannot be null or white space.", nameof(Value)); public static implicit operator NonEmptyString(string b) => new NonEmptyString(b); } record Book(NonEmptyString Title); --Output at runtime-- ArgumentException••• Value cannot be null or white space. (Parameter 'Value')

  • @mrslave41
    @mrslave41 3 дні тому

    i would say that using “delay” is a bug 🐛.

  • @AhmadElkhouly
    @AhmadElkhouly 3 дні тому

    As far as I can remember, I used to use this method in Unity game engine (Mathf.Clamp) a long time ago. I am surprised that .Net hasn't had one until recently. Good reminder. Thank you!

  • @RiversJ
    @RiversJ 3 дні тому

    I'm really spoiled in that i learned to program with large math libraries that are not only documented well, but super fast and with context appropriate typing. The C# Math class is about barely passable, Clamp is among the first methods that should reside there, but how about bounded Remap, Unbound Remap, Rescale, half the lower level math ops nowhere to be seen. Custom Math class is always among the first classes i implement if one doesn't exist already.

  • @JollyGiant19
    @JollyGiant19 3 дні тому

    Very nice!

  • @MasterKrzychuu
    @MasterKrzychuu 3 дні тому

    Nice, I forgot about Clamp but now I have the perfect idea where to use it in my code, thanks! Just saying, the way you've defined your Percentage class, it is still possible to initialize it with an invalid value: "var invalid = new Percentage(75) { Value = -12345 };". Change the init setter to private set to disallow this.

    • @zoran-horvat
      @zoran-horvat 3 дні тому

      Yes, that is the topic of other videos where I explain that issue.

  • @websystema
    @websystema 3 дні тому

    Thank you

  • @mohammadrezajavidpoor8307
    @mohammadrezajavidpoor8307 3 дні тому

    You Speak too bad and your accent is a disaster that left the video at minute 2

  • @CRBarchager
    @CRBarchager 3 дні тому

    4:05 & 4.50 Thank you for mentioning the reasoning behind to position of CancellationToken here.

  • @MsT0mahawk
    @MsT0mahawk 4 дні тому

    var result = list.Select((p, i) => new { p, i}).OrderBy(p => p.p != 0 ? p.i : list.Count + 1).Select(p => p.p); Console.WriteLine(String.Join(", ", result));

    • @zoran-horvat
      @zoran-horvat 4 дні тому

      That algorithm is interesting, but it has O(n logn) time complexity, where the simple alternatives have O(n) complexity.

  • @ghevisartor6005
    @ghevisartor6005 4 дні тому

    Sorry but i lack a bit of experience on this topic. Are the models like Person and Tag supposed to be on their own or can they be used as complex types for EF core? I guess they are the model that is core tho the app and it is then used to populate entities? For example if i try to use them and migrate EF fail since it cant bind Name and Surname to properties on the Person type, i think there are workarounds for it but is logically wrong?

    • @zoran-horvat
      @zoran-horvat 4 дні тому

      Records are not of great use with EF Core because they are immutable by default. Making them mutable requires the same level of effort as writing a common class, which defeats the idea of records. Records are primarily used in functional designs, where they become the principal design element together with delegates and static methods.

    • @ghevisartor6005
      @ghevisartor6005 4 дні тому

      @@zoran-horvat thanks! i'm dealing with Blazor and making a non trivial model, thanks to some of your courses i realized that much of my code is procedural rather than oop or functional, i'm slowly trying to move to away from it, but it's kinda hard to fit it all together

  • @noaml-1
    @noaml-1 4 дні тому

    Great stuff. Thank you! But how can I implement passimistic and optimistic locking using DDD aggregate and EF Cote?

    • @zoran-horvat
      @zoran-horvat 4 дні тому

      For optimistic locking with EF Core, all you need to do is configure the version field. For pessimistic locking, you need to begin and commit the transaction on the connection used by the DbContext.

    • @noaml-1
      @noaml-1 4 дні тому

      @@zoran-horvat Where should I define the version field? In the Books table (aggregate root) or in the BookAuthors table (entity)?

  • @sebastianszafran5221
    @sebastianszafran5221 5 днів тому

    You are a phenomenon I've found lately. Besides the rich content I especially love the passion for coding coming out of your voice!

  •  5 днів тому

    One word separates the noobs from the pros: multithreading.

  • @poketopa1234
    @poketopa1234 6 днів тому

    You criticize the junior programmer, but without more context their implementation is just as fast as the second solution. The rest are overly complicated and have unnecessary overhead for the simple problem

  • @faridfereidoony227
    @faridfereidoony227 6 днів тому

    This is not code, this is art. Thank you sir.

  • @bogdanbucur4849
    @bogdanbucur4849 7 днів тому

    wow

  • @zo1dberg
    @zo1dberg 7 днів тому

    Great vid and love your accent and storytelling!