Tony Dwire
Tony Dwire
  • 19
  • 110 701
Better C# - LINQ
In this video we go over LINQ, what it is, how to use it, and how to extend it further with more useful user-written extension methods.
The slides in this video were done using lookatme, a python program available here:
pypi.org/project/lookatme/
The slides are available in markdown form here:
github.com/aqez/LINQ-notes
The source for the dotnet LINQ implementation can be found here: github.com/dotnet/runtime/tree/master/src/libraries/System.Linq
In general the dotnet libraries are very useful to explore, so I would recommend browsing then when possible.
0:00 Intro
0:08 Overview
1:02 Summary
3:00 IEnumerable
4:23 System.Linq namespace
6:25 Where
8:30 Select
9:47 Any, All
10:57 Min, Max, Average, Sum
12:13 First, FirstOrDefault, Last, LastOrDefault, Count
14:18 Cast, OfType
16:34 OrderBy, OrderByDescending
17:49 GroupBy
19:07 Combining them
24:32 Implementing our own 'Where'
27:45 Implementing our own 'Batch'
33:18 Implementing our own 'Combine' (like SelectMany)
Переглядів: 3 169

Відео

Better C# - IDisposable
Переглядів 6 тис.3 роки тому
In this video we talk about how the IDisposable interface works and how the IDisposable pattern should be applied to classes in order to allow correct behavior. 00:00 Intro 00:08 Overview 02:30 Naive IDisposable Implementation 04:35 Under the hood 06:20 IL Disassembler 07:00 "Using" Disassembled 08:38 "Try/Finally" Disassembled 09:47 Inheritance and IDisposable Issues 12:00 IDisposable Pattern ...
Better C# - Source Generators
Переглядів 4,5 тис.3 роки тому
In this video we talk about the new .NET 5 feature source generators. We go over an example of where they could be used - compile time serializer generation. They're a decently complex topic that was hard to fit into one video, so please let me know what you think! The git repo for this project can be found at github.com/aqez/SourceGenerators 0:00 Intro 0:08 Overview 5:55 Reflection Based Seria...
Better C# - Reducing Complexity
Переглядів 2,6 тис.3 роки тому
We talk about why complexity is disastrous and why we should work as hard as we can to avoid it. GitHub repo for this video can be found here: github.com/aqez/BetterCSharp.Complexity
Better C# - Parallelization (with Dataflow)
Переглядів 10 тис.3 роки тому
We talk about some parallelization methods and why Dataflow is the best thing since sliced bread! Seriously, if you haven't checked out the dataflow classes be sure to look at them! The git repository for this video can be found at github.com/aqez/BetterCSharp - check out the Dataflow tag. 0:00 Intro 0:08 Overview 1:28 Serial Implementation 5:35 Semaphore Parallelization 8:41 Dataflow Paralleli...
Better C# - SOLID Principles
Переглядів 10 тис.3 роки тому
We talk about the solid principles and what each one of them are and give a brief overview of how to make changes to accommodate them in code! Also we record the longest vim macro in history, I didn't see it until way too late! GitHub: github.com/aqez/solid 0:00 Intro 0:08 Overview 0:48 Single Responsibility Principle 8:23 Open Close Principle 10:56 Liskov Substitution Principle 18:43 Interface...
Better C# - Refactoring
Переглядів 7 тис.3 роки тому
We talk about why refactoring is important and give a few examples of refactors that you should be doing on your code base. If you take anything from this video, please know that you do not have to be the original author of a line of code to change it for the better - the original author isn't the one watching these videos, you are! So use this knowledge and make your code base a better one to ...
Better C# - IEnumerable
Переглядів 2,7 тис.3 роки тому
We talk about how IEnumerable and IEnumerable of T work in order to facilitate foreach, LINQ, etc. We talk about how to implement IEnumerable for your own types, both with generators and enumerable classes. We even touch on a little known trick in the C# language about foreach.
Better C# - Exceptions
Переглядів 1,2 тис.3 роки тому
We talk about the when, how, and why of throwing and catching exceptions as well as creating our own exception types.
Better C# - Dependency Inversion
Переглядів 1,6 тис.3 роки тому
In this video we go over dependency inversion, specifically across library boundaries. We also talk about the 'low level' part of dependency inversion also depending on abstractions - most things focus just on the high level but the low level is just as important.
Better C# - Unit Tests
Переглядів 2,2 тис.3 роки тому
In this video we go over unit tests - why they are valuable and what important roles they play in development. We also go over some examples of unit tests and then show how the SOLID principles make unit testing easier.
Better C# - Switch Statements (can be evil)
Переглядів 3 тис.3 роки тому
In this video I go over why switch statements can wreak such havoc on a code base. I explain why they can be hard to maintain, hard to extend, and result in many bugs. I also give two clear examples to get rid of them using polymorphic behavior.
C# Vim Development Setup
Переглядів 22 тис.3 роки тому
This video goes over my setup for developing C# applications in neovim. Neovim and vim are awesome modal editors that make working with text a fluid and fun experience! My vimrc can be found at: github.com/aqez/dotfiles If you think you might like vim-based editing, check out ThePrimeagen on youtube here: ua-cam.com/channels/8ENHE5xdFSwx71u3fDH5Xw.html
Better C# - Static Classes (and how to get rid of them!)
Переглядів 1,8 тис.3 роки тому
We talk about static classes in this video and why they are generally not what you want in your code. We also go into how to get rid of them in code that you control, and talk about the few times you may actually need them.
Better C# - Intro
Переглядів 2 тис.3 роки тому
We give a quick overview of what this series is about and who is targeted. We also talk a little bit about what our setup is for the series.
Better C# - Command Line Arguments
Переглядів 7 тис.3 роки тому
Better C# - Command Line Arguments
Better C# - Configuration
Переглядів 7 тис.3 роки тому
Better C# - Configuration
Better C# - Dependency Injection
Переглядів 3,3 тис.3 роки тому
Better C# - Dependency Injection
Better C# - Class Architecture
Переглядів 13 тис.3 роки тому
Better C# - Class Architecture

КОМЕНТАРІ

  • @brycethompson
    @brycethompson 2 місяці тому

    Fantastic explanation, glad I stumbled across your channel!

  • @ranavitaln
    @ranavitaln 2 місяці тому

    These videos are aboslutley amazing!!!!!

  • @vitalyshein5345
    @vitalyshein5345 3 місяці тому

    That's absolutely incredible, there's not much explanations of this lib on youtube, you've helped me a lot bro, thanks

  • @WolfieDad67
    @WolfieDad67 5 місяців тому

    Excellent - very informative and seemingly very powerful tools.

  • @schmidtlach
    @schmidtlach 7 місяців тому

    I loved it. Thank you so much for the explanation👏

  • @rpo3ge
    @rpo3ge 7 місяців тому

    Hi Tony, Thank you for your video, I like it so much I go back to it every now and then. With that said I hope you are still around and doing great work! I have a question about thinking and writing code on the high level. I still struggle with seeing the bug picture and always go berserk with implementation. Have you got any practical tips on how to achieve this mindset to really code to an interface. When and how did it click for you? How can I impose it my day to day. I would really love to be able to think about programming first in this high level abstract way and only then focus on implementation details.

  • @NormalNvim
    @NormalNvim 7 місяців тому

    We ship all that!

    • @greendog105
      @greendog105 3 місяці тому

      nvim distro that comes with tools for C# out of the box? I'll give it a try. I was already cryingly installing Rider

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

    great lesson! thanks

  • @ChuckAsum
    @ChuckAsum 11 місяців тому

    Also did you find a way to update names of var/classes/interfaces which cascade to references in the code base? :) Something that is quite bleoved in resharper/intelij tools

  • @ChuckAsum
    @ChuckAsum 11 місяців тому

    Wondering if you found a way to see usages and implementations for concrete classes and interfaces?

  • @ChuckAsum
    @ChuckAsum 11 місяців тому

    Omisharp vim Vim spectre

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

    How could this be updated to show a progress bar or two? You're writing out log statements to the console, but what if we wanted to simplify to a % complete for file processing and another for trucks processed?

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

    Many new things in newer C# versions, create videos about them ...

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

    thanks sooo much! I thought about moving to nvim instead of Rider, but I work with a big project, so I need staff like "go to". Omnisharp is slowing it. The last thing that I need to explore is how to build, run and public the project.

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

    your videos are very very good. thanks for those lectures!

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

    Great vid really very useful but I'm also looking for yaml config can we suggest or provide some vid.

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

    Awesome video, thanks!

  • @감사합니다잘보겠습니

    Love you from Korea

  •  Рік тому

    I was looking for some kind of multithreaded file processing, with a batched upload, Your example was exactly, what I needed. Never heard about Dataflow before.

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

    Awesome videos man, I hope you'll make some more, please do, you have a talent of teaching!

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

    Thanks for the great content! May I ask 1 question about your custom exception classes (like EmptyClassroomException). Whay do they need properties we instantiate in constructor (like Classroom) if all the message gets is in argument itself. What could be the use of that?

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

      Great question! It really serves two purposes - when catching the exception you can respond to the exception in different ways depending on the values of its properties if needed, and also during debugging it can be incredibly useful to see details about the objects involved in the exception since the call stack gets all messed up by the catch

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

    I'm in love with your channel, thank you! Although creating everything from scratch without the complexity of existing project should make it easier to understand

  • @danielbergfrederiksen3731

    I've been playing around with neovim for a while on my mac, and I really wanna move to linux, but I am not confident enough yet :p I mainly work in C#, and I was wondering if you have done some Azure function work in C# on your linux machine, building, debugging etc. in neovim?

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

      I have not! I had done some on windows in neovim but that job wouldn’t allow me to use an OS of my choice. That being said after a quick read of the docs at learn.microsoft.com/en-us/azure/azure-functions/functions-run-local?tabs=v4%2Cwindows%2Ccsharp%2Cportal%2Cbash#v2 nothing seems to stand out as windows only. I’d give it a try in a VM and see how it goes!

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

      @@tonydwire Thanks a lot for the reply! Yea, I think I’ll give it a go in a vm 😃

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

      @@tonydwire btw. The configs in your GitHub, are those the ones you are currently using? Is there any capability that they might be missing for c# development off the top of your head?

  • @Guo-ml3hp
    @Guo-ml3hp Рік тому

    The reason why we use interface besides abstract class here is for dependency injection?

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

    Great materials. Hope you're doing alright in there!

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

    Awasome, finally something said that to run this app you have to make sure that json file is in output directory. Wasted 1 hour searching for this. Thanks a lot!

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

    You should keep going videos man. Perfect

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

    Bad, bad Dipendency inversion implies depending injection. if not you will be wrong.

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

    Good job, but be more clear: you speak like you have a clear idea in your mind wht the objective is, but you do not transfer this to the finale viewer.

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

    Hi Tony! Got my first job in the software developing industry couple weeks ago and I'm loving it. I'm currently working on a client that consumes a rest api and after watching your videos I'm redesigning the architecture of my project because so much make more sense now. I'm working with a data mover class similar to the one you showed in the SOLID video and I'm not sure how to work with parallelization while respecting my DataMover architecture. Should my HttpClientDataSender work with Tasks ? Should my FilesDataProvider work with Tasks ? (since I have to get data from a folder before sending it to the API and then saving it to a backup folder). More precisely, I think working with tasks is the way to go, but should my Processor call my DataMover objects or the other way around ? Thank you so much, any hint would be greatly appreciated !

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

      I typically think of the processor as the outer most logic besides main, so I would have it call the data movers. As for whether or not to work with tasks or not it really depends on the data and the setup. The data and the api you are hitting will really drive how parallel things can be. But tasks really don’t necessarily represent parallelism, they represent asynchronous operations. A task is really like a handle to some operation that will complete at some point in time - possibly in the future. If I had to give an example it’s like the bank accepting your payroll check - and you have to wait until you get paid to buy groceries. So something like await PayrollDeposit(); BuyGroceries(); is saying I know that getting my paycheck will take some unknown amount of time and I can’t buy groceries until after that. The parallelism comes in when you realize that both you and your partner can wait on checks at the same time without interfering with each other - in other words multiple tasks can be waited on.

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

      @@tonydwire That is clear. Im working with a HttpClientDataSender : IDataSender class and since it works with a HttpClient object all the methods are Task and i thought it felt weird to have my processor calling my HttpClient that also works async. As for the parallelism, it might still come handy with my non-api file management later on... Working with solid principles is challenging as a beginner but its also lots of fun and thinking and i really feel it makes me improve a lot. Thank you again !

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

    You just taught dependency injections best way possible

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

    Unless you are dead, you have no excuse. Make more excellent videos. Now, please.

  • @FortyTwoAnswerToEverything

    I'd say that typing too fast and making a lot of errors can get a little distracting from your video. Slow down the pace of your typing instead

  • @James-fo3iy
    @James-fo3iy Рік тому

    Don't write code as you present, have it done already and highlight bits of it

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

    Thank you for this!

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

    Where did you learn most of the information in these videos? Can you make a video about what books, resources, or how to find good materials to learn from? Most programming videos on UA-cam have very poorly written code and yours in your examples is well written.

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

    Your .vimrc is not available in the repo anymore, nor your C# configuration. Could you please provide a link?

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

    -you say "switch statements", but you are only talking about switching on type, there are different types of switch statements. -"if you add an enum, you have to go back and add code", I have to change my code sometimes? unacceptable! I didn't become a coder to write code. -"switches are dangerous..300 lines of code" because you have long switches??? lots of code is bad code? you are just afraid of code, you are scared if you see a lot of it -"what if we don't control the code we are writing", but if we actually do control the code then there is no argument -you either need an abstract class OR and interface, you don't need both its redundant, you are defining all fields twice You create a cost calculator class and the only point of this class is to store a magic number? where is your data and behaviour? aren't classes meant to have fields and methods? if you want to store typed numbers use an dictionary this is definitely the bob school of thought where "create more classes" is the solution to everything

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

      In order from top to bottom.. - The point is that switches generally can be more extensible if implemented via polymorphism instead of a direct switch statement. - You are missing the point twofold here, first that “going back and adding code” may not even be possible, it could be in a library you don’t control. Second is that it’s not just one place you have to change it.. if you switched in 1000 different places then good luck going back and changing all of those. - Again missing the point. Would you rather have a 30 branch switch in 50 places that you have to keep track of or would you rather have your code be neatly compartmentalized and have the related code for those 30 branches each in its own self contained unit that we happen to call a class? - It is quite often we don’t control the code we are working with. I hate to make assumptions but the idea that you control most of the code you interact with daily kind of points toward a novice. - It is correct that we only need it to be an abstract class. This was a pretty aggressive comment and comes across more of an “I hate OO” comment than an actual productive conversation. I’d like to just point out that there is nothing specifically “Uncle Bob” about this code, these ideas have been around for a very long time even in languages that are not themselves object oriented. You can see this plenty in the Linux kernel for example using function pointers as an indirection, and that’s really all we are doing here is working with a nice abstraction over function pointers when you get to the bottom of it. Also to suggest that someone who took a lot of their time outside of work to make code based videos is afraid of code seems pretty naive. I do this because I enjoy code (specifically code that makes my job easier with traits such as extensibility). These videos specifically related to C#, which is a highly object oriented language, may not be your cup of tea and that’s okay.

  • @penggao2278
    @penggao2278 2 роки тому

    Hi Tony, I learned a lot from this video, thank you! I have a question regarding this approach though. What happens when you have multiple implementations for one interface? How to you wire the implementations to the constructors correctly ?

    • @tonydwire
      @tonydwire 2 роки тому

      Awesome glad it helped! It depends on the DI container but with the Microsoft one from this video if you add multiple implementations for one interface then you can accept IEnumerable<IMyInterface> in the constructors and get all of them. If the intention is to pick one of them, the best idea in my opinion is to do that when adding to the DI container and not add more than one, because outside of there one of the main points is not to know the specific implementation that you have.

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

      In this case you should check out Autofac and the Keyed feature.

  • @mohammedamr5650
    @mohammedamr5650 2 роки тому

    13:44 here you didn't take into account if classroom contains IPersons but not Students.

  • @RaabStephan
    @RaabStephan 2 роки тому

    Very cool! I wonder if you could lunch the debugger for mobile applications from neovim too? As I use VS for cross-platform development with Xamarin and now MAUI.

  • @henrik3098
    @henrik3098 2 роки тому

    thx bro

  • @mehrdaddowlatabadi2319
    @mehrdaddowlatabadi2319 2 роки тому

    The intro music is too loud. the content is of high quality. you also can create a video about Threading.Channels.

  • @behrouzseyedi
    @behrouzseyedi 2 роки тому

    Thank you Tony, it was amazing! 👍

  • @RobertoDeMontecarlo
    @RobertoDeMontecarlo 2 роки тому

    Love these videos... Thank you!

  • @rolandfaulhaber3520
    @rolandfaulhaber3520 2 роки тому

    I like the topic, but did everyone put the program together while watching him? I followed his programming verbatim and the file is created but no data is put into the file. Maybe provide the ability to download the project for comparison.

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

      Needed to flush after each WriteLIne _streamWriter.WriteLine( data ); _streamWriter.Flush(); // without the flush the file was empty

  • @tiphuat4808
    @tiphuat4808 2 роки тому

    subscribed and forked. I learned a lot from your videos.

  • @tiphuat4808
    @tiphuat4808 2 роки тому

    The first time I saw interfaces and abstract classes come together. This really a brain storm for me. Thank you so much!

  • @etienne.etienne.etienne
    @etienne.etienne.etienne 2 роки тому

    hello tony, thank you for making these uploads! they are a huge help. do you currently plan to make some more in the future? have a nice weekend!

    • @tonydwire
      @tonydwire 2 роки тому

      Thanks! I’m glad they help. I will hopefully eventually get back around to it. Are there any specific topics you would like to see?

    • @etienne.etienne.etienne
      @etienne.etienne.etienne 2 роки тому

      @@tonydwire that sounds great! :-) ...maybe you could just show some code you like or find to be well written.or you could do a howto-series on your own approaches to more common problems. or sth off topic? you could do parcour

  • @BigBrainHacks
    @BigBrainHacks 2 роки тому

    Thank you so much! The switch-case example really helped me to understand the 'when to implement' of the pattern.