"Jay B. Harlow [MVP - Outlook]" <Ja************@msn.com> wrote in message
news:e$**************@TK2MSFTNGP11.phx.gbl...
Boxboy, What should I name my Connect, Disconnect, and Read events? I would use past tense Connected and Disconnected. Unfortunately Read is
both paste & present tense... Which allow for Connecting & Disconnecting
cancelable events...
Well, actually I already have a bool property named Connected, so I would have to use
some other name for the event.
Would Received work instead of Read? For a socket I would think in terms of
Receiving data instead of Reading data...
Why did microsoft decide to use a verb based naming convtion for events
rather such as Close and Click for rather than prepending them with On as
in OnClose and OnClick?
A derived class cannot raise a base class event, the convention is that the
Close event is raised by the OnClose method of the class. Because OnClose is
a method, it cannot be overloaded for the event itself. A benefit of OnClose
is that it is virtual, derived classes can override the method allowing
easier handling of the event in derived classes, and allowing derived
classes to have pre or post processing before the event itself is raised.
Yes I understand the protected virtual OnEventName design.
Let me explain further.
I come to C# from a Delphi background. I absolutely do not want to make or use C# as
Delphi (I understand C# is a totally different paradigm). Having said that, there are
many simlilarities between C# and Delphi. Both use single root object heirarchy, both
fully support PME, both were designed by Anders Hejlsberg.
In Delphi you typically would write a protected virtual method to call an event,
allowing derived classes to pre and post process event just as you described. The
difference was that the programmer would prepend Do infront of the method name to
create virtual protected methods like DoClose, DoClick and so on. The actual events
were then named OnClose and OnClick.
Honestly, when I read name like Click and Close I think of methods and that either
cause a Click to happen or a something to Close. In otherwords it is not immediately
obvious when read the name to know if it a method or event.
Do you see how the Mircosoft event naming guidelines make things messy as in the
example of Connect/Connected above?
I understand that Microsoft wanted change things down to the core with dotnet, and
one of their goals seems to have been to kill hungarian notation, but really I'm a
bummed that they made the descision not to prepend events with On when it seemed like
such a no-brainer.
What I am asking for is validation on the why Microsoft went with this descision, and
wanted to know if anyone would have preferred OnEventNames?
Finally, before someone replay saying I can name events any which way, that is
obvious. I just want to write code that other people feel would comfortable with
should I ever work in a team environment using C#.
Thanks again for reading.