Correct and Specific Meaning of "Event Handler"

S

Smithers

I am wanting to clarify the meaning of the term, "event handler"

In reviewing the documentation (MSDN and far beyond) on delegates and event
handlers, it appears that many authors use the term "event handler" when
talking about either of these two very different things:
1. a delegate used as the basis for an event (either a custom delegate or
System.EventHandler).
2. a method that gets registered with the above delegate (and is
consequently called upon the raising of the event).

Because a delegate is not a method, I would think that it is technically
incorrect to refer to both of the above as being "an event handler." While
many authors use the term interchangeably, I suspect that they do so out of
convenience and not out of technical correctness.

My question:
Can it be reasonably concluded that the *only techinically correct* use of
the term, "event handler" is in reference to the delegate? Or is it
technically correct - and not simply convenient - to refer to both the
delegate and a method that registers with that delegate as "an event
handler".

Thanks.
 
J

Jon Skeet [C# MVP]

I am wanting to clarify the meaning of the term, "event handler"

<snip>

It's used pretty loosely, I agree. I think it's reasonable to say that
both the method and the delegate instance are event handlers, as both
are involved in handling the event.

Note that your own post also falls into a common pit of ambiguity: the
word "delegate" is often used to mean both a delegate type and an
instance *of* that type. So the type EventHandler is a delegate, but
so is an instance of EventHandler, in many people's usage. I try to
use "delegate instance" and "delegate type" to clarify matters.

Jon
 
S

Smithers

Hi Jon,

Re:
<< Note that your own post also falls into a common pit of ambiguity: the
word "delegate" is often used to mean both a delegate type and an
instance *of* that type. So the type EventHandler is a delegate, but
so is an instance of EventHandler, in many people's usage. I try to
use "delegate instance" and "delegate type" to clarify matters>>

Yes - I read your article on events where you draw that distinction (very
helpful article, BTW).

Contining the additional pit of ambiguity that you pointed out, and coming
full circle with my OP, I have seen people refer to the following as all
being "the delegate":
1. delegate (meaning "delegate type")
2. delegate (meaning "delegate instance")
3. a method registered with the delegate (used interchangeably, AFAIKT, with
"delegate instance" meaning of "delegate.).

My OP would be a specific case of the confusion created by #3 - by referring
to a method [that is registered with a delegate] as a delegate. In the case
of "event handler" it's just a particular type of delegate.

It just bothers me to no end to see well-known authors and MSDN refer to a
[method that registers with a delegate] as BEING a delegate [instance]...
and equally bothersome to see people refer to an "event handling method" as
being an "event handler." If a case can be made that an event handler is
ONLY a delegate, we can consider that Microsoft named the built-in event
handlers (generic and non generic versions) as "EventHandler"
(System.EventHandler and System.EventHandler<TEventArgs> which are
delegates).

In the article that I'm writing, I guess I'll just have to define the terms
as "as used in this article." like you did in your events and delegates
article. I was hoping to point out in my piece, instead, that I have
identified THE correct vocabulary... I guess that won't happen if we don't
have some objective and definitive authority to point to regarding "correct"
terminology on this.

-S
 
J

Jon Skeet [C# MVP]

Contining the additional pit of ambiguity that you pointed out, and coming
full circle with my OP, I have seen people refer to the following as all
being "the delegate":
1. delegate (meaning "delegate type")
2. delegate (meaning "delegate instance")
3. a method registered with the delegate (used interchangeably, AFAIKT, with
"delegate instance" meaning of "delegate.).

Eek - I haven't seen 3. That's definitely just wrong :)

In the article that I'm writing, I guess I'll just have to define the terms
as "as used in this article." like you did in your events and delegates
article. I was hoping to point out in my piece, instead, that I have
identified THE correct vocabulary... I guess that won't happen if we don't
have some objective and definitive authority to point to regarding "correct"
terminology on this.

I don't believe there's a precise definition. The C# spec uses "event
handler" to mean a delegate subscribed to the event, but the comments
for some code say that a method is now an event handler for a
particular event.

I think it's probably best to define the terms how you want to use
them, and go for it that way.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top