It came to my attention this week that asynchronous programming and delegates aren't that easy for people to understand and even if you do understand them, they're difficult to explain - okay, it came to my attention a while ago but it only occured me to write anything about it today. It's a concept, much like pointers that can take some getting your head around. There are many excellent in depth explanations of how to implement them found all over the internet but none of them seem to do a very good job of explaining the basic underlying concept in plain understandable English.
A friend of mine explained it to me a while back after I'd read 20 websites and numerous book excerpts trying to understand delegates and how they worked and what they were used for. The explanation is no more than a dozen lines of plain English that even a non programmer can understand. The legendary Jon Skeet asked me for this explanation yesterday and prompted me to wonder if so many well renowned authors find this concept difficult to explain, then maybe I should post it on my blog.
It occurs to me that pointers in general could be explained in much the same way. If I put a letter in your pigeon hole, you know where to find it. The pigeon hole is the pointer to the letter which is the variable and the value which is the contents of the letter. Then you get to pointers to pointers and pointers to pointers to pointers etc which I couldn't even grasp when I was beginning to learn programming no matter who tried to explain it to me. It basically becomes a treasure hunt of pigeon holes with police tape over them and a note saying "look in pigeon hole n" (where n is the number of a different pigeon hole)...finally in the last pigeon hole is the letter which is your variable, and the letter contents which is the value.
Lets forget pointers for a minute and use a similar example in a different fashion to explain the difference between passing values by reference or by value.
This effectively is the same as passing a pointer to the variable to the method which is in fact what passing a variable by reference means.
And so concludes a plain English example of the basic concepts of asynchronous programming, delegates, variables, pointers, by reference and by value...
I know I've simplified and skated over some of the nuances and implications of these concepts, but I hope that is of help to those that don't get it, and of help to those that find it hard to explain these concepts to others.