473,320 Members | 1,950 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

event naming convention

I am hoping someone from Microsoft could shed some insight into this
question.

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?

The way it is now, I encounter a lot of naming conflicts/ambiguity when
trying to follow Microsoft's reccommened approach in naming my own events.

As I am writing this message, I am just trying to think of event names for a
socket class I am working on. It already has method names like Connect,
Disconnect, and Read. At first OnConnect and OnClose seem like the most
natural event names, but this goes against the standard.

You get the idea.

Why didn't Microsoft want to prepend On to event names? Many other
languages/tools have been doing this for a long time, and in my opinion its
quite natural.

What should I name my Connect, Disconnect, and Read events?

Thanks for reading.
Jul 21 '05 #1
3 4964
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...

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.

For details on the convention (not necessarily why) see:

http://msdn.microsoft.com/library/de...Guidelines.asp

http://msdn.microsoft.com/library/de...Guidelines.asp

Hope this helps
Jay

"boxboy" <a@a.a> wrote in message
news:uQ*************@TK2MSFTNGP11.phx.gbl... I am hoping someone from Microsoft could shed some insight into this
question.

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?

The way it is now, I encounter a lot of naming conflicts/ambiguity when
trying to follow Microsoft's reccommened approach in naming my own events.

As I am writing this message, I am just trying to think of event names for a socket class I am working on. It already has method names like Connect,
Disconnect, and Read. At first OnConnect and OnClose seem like the most
natural event names, but this goes against the standard.

You get the idea.

Why didn't Microsoft want to prepend On to event names? Many other
languages/tools have been doing this for a long time, and in my opinion its quite natural.

What should I name my Connect, Disconnect, and Read events?

Thanks for reading.

Jul 21 '05 #2

"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.
Jul 21 '05 #3
boxboy,
Well, actually I already have a bool property named Connected, so I would have to use some other name for the event. I would use IsConnected for the property.
Do you see how the Mircosoft event naming guidelines make things messy as in the example of Connect/Connected above? Yes I do, however I have never really had a problem with it, as you are
suggesting you have. And yes I have created tons of classes with events, and
properties and similar named things...
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? I cannot offer any "validation"...

Remember conventions & guidelines are just that conventions & guidelines. If
you really want to name your event OnEvent name it OnEvent. If you want to
name the virtual function DoEvent, name it DoEvent. My feeling tends to be
as long as you are consistent within your project, team, department,
organization. Does it really matter what the Microsoft Guidelines state?

I tend to (mostly) follow the Microsoft Guidelines, not because they are the
*Microsoft Guidelines* but because then my code is consistent with the
framework, other .NET developers can pickup my code and be reasonable
familiar with it. I don't blindly follow the Guidelines, for example they
suggest using the same name for Fields & Properties, which may work in C#,
however this fails in VB.NET. Hence I follow another convention (m_field
instead of field).
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#. Too late ;-)

I suspect because I have not really used Delphi, that event naming is not
"messy" for me. Instead of Delphi I've had MFC, VB & Java.

Hope this helps
Jay
"boxboy" <a@a.a> wrote in message
news:uJ*************@TK2MSFTNGP12.phx.gbl...
"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.

Jul 21 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

27
by: Derek | last post by:
The company where I work uses a naming convention that I have never used before. They use mixed-case letters for public member functions, but lower-case with underscores for the rest, like this:...
4
by: Mark Broadbent | last post by:
stupid question time again to most of you experts but this is something that continually bothers me. I am trying to get into the habit of naming variables and controls in an assembly as per...
14
by: 42 | last post by:
Hi, Stupid question: I keep bumping into the desire to create classes and properties with the same name and the current favored naming conventions aren't automatically differentiating them......
0
by: Carl Colijn | last post by:
Hi all, Disclaimer: before I might trigger your "let's start a holy war!" button, I'd like to say I'm not intended to; I just post this message to get some input and not to promote "Yet Another...
3
by: boxboy | last post by:
I am hoping someone from Microsoft could shed some insight into this question. Why did microsoft decide to use a verb based naming convtion for events rather such as Close and Click for rather...
10
by: jjkboswell | last post by:
I'm trying to pin down a good naming convention for the 3 things required to implement an event. You need: 1) a delegate 2) an event 3) an event handler Below is my understanding of a...
114
by: Jonathan Wood | last post by:
I was just wondering what naming convention most of you use for class variables. Underscore, "m_" prefix, camel case, capitalized, etc? Has one style emerged as the most popular? Thanks for...
35
by: Smithers | last post by:
Is it common practise to begin the name of form classes with "frm" (e.g., frmOneForm, frmAnotherForm). Or is that generally considered an outdated convention? If not "frm" what is a common or...
4
by: tshad | last post by:
I am just getting started with events and had a couple of questions on why they do what they do. If you have a textbox and you want to handle an event you can just do: ...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.