gridlocdev / csharp-learning-roadmap

A beginner's roadmap of concepts to learn the C# programming language
https://gridlocdev.github.io/csharp-learning-roadmap/
Creative Commons Zero v1.0 Universal
261 stars 26 forks source link

Events and delegates #2

Closed lambdacore12 closed 1 year ago

lambdacore12 commented 1 year ago

Hello. Thank you for this roadmap. Why are events and delegates not mentioned?

gridlocdev commented 1 year ago

That is a great question, and I did consider both in the initial design. As I went through initial revising, I narrowed down the list to language concepts that a new developer would interact with directly. In that list, Events and Delegates were not of them for the following reasons:

Events

Events are a core part of Pub/Sub code architectures commonly found within game and user interface development. However, during research for this roadmap I found these were complex enough that a new developer would typically interact with Events through an abstraction in the framework they are using such as UnityEvent or WinForms's code generation tooling. The reason for this is that there are some notable gotchas with Events that also make it not so much of a beginner concept, namely:

  1. Events can create memory leaks if not unsubscribed once its lifetime has completed.
  2. Architecting code to use Events, while not too difficult in practice, can be a bit difficult for a beginner. Deciding to couple your entities vs using a separate Orchestrator type of class can be a bit tricky, and requires knowledge of architectural patterns to prevent adding unnecessary layers of abstraction.

Delegates

For Delegates, while an important concept, developers usually use the modern wrappers such as Action and Func types instead. Each of these handles a bit of the boilerplate usually associated with setting up delegates manually.

Side note: I highly recommend Tarodev's video on Events and Delegates, which if you're interested explains these two things well in greater detail!

lambdacore12 commented 1 year ago

Thanks for the quick response! I was in the process of learning WPF, but I was unable to advance due the fact that I couldn't work with events and delegates. That's why I went looking for a roadmap that would show me where have I missed these two concepts along the way.