Naming conventions!

pachjo

Well-known member
Joined
Dec 12, 2006
Messages
370
Programming Experience
10+
I am starting to convert my app to the 'recommended' naming convention methodology and am once again confused.

Cjard, you mentioned previously my style was out of date and as such being in a posistion where my app is a learning exercise I have chosen to revamp in order to 'do it right'

However, this link for example suggests my existing way is the recommended and your way is another way?

http://www.ssw.com.au/SSW/Standards/DeveloperDotNet/DotNetStandard_ObjectNaming.aspx#Syntax

So here are some examples which I feel are easier to read than the other way and if anyone can comment or advise, (you too cjard;) ) I would be grateful

textbox

txtAnyDescription or anydescriptionTextbox?

combobox

cboAnyDescription or anydescriptionCombobox

Variables

intCounter or counterInt

Lastly for example I do have a textbox currently named:

txtSaveNewAutoDescription which clearly tells me it is a text box and the camel casing make the rest easy reading. However....

savenewautodescriptionTextbox to me is far harder to read at first glance!

Please advise me......:confused:
 
I would personally prefer txtAnyDescription over anydescriptionTextbox though.

If you want to type the name of a control but don't know the exact name, you will almost certainly know by heart if it's a textbox (txt) or combobox (cbo) rather than if it's name starts with 'description'... or was it 'employeedescription'

The intellisense will help you find a control much faster if you know that it's a textbox and it begins with 'txt' than if you have to guess what the name begins with.

Of course, that's my way of thinking.

If you do it the other way, then you must be consequent and start all your controls with a prefix like Employee... or Client...
That way, you don't have to think about what sort of control it is, but you will have to know the prefix.
 
Last edited:
Interesting topic...

I know the recommended naming convension for .NET. However, I prefer 'txtAnyDescription' over 'anydescriptionTextbox'.

CygNuS said:
If you want to type the name of a control but don't know the exact name, you will almost certainly know by heart if it's a textbox (txt) or combobox (cbo) rather than if it's name starts with 'description'... or was it 'employeedescription'

I agree !

It makes me code with ease. In my opinion, when I'm coding it has to be comfortable to me first! then think about other developers (although it does not reflect team spirit I guess :D but again...can't see any reason for other developers having difficulty in understanding this naming convension)
 
Thanks chaps, I have for as long as I can remember used the convention txtNameOfControl and yes the intelli sense does work well with it.

So why is Microsoft saying DONT use it?
 

Noting of course that that page is specific to .NET 3.0
See the box int he top right for guides to 2.0 and 1.1 :)

I would personally prefer txtAnyDescription over anydescriptionTextbox though.

If you want to type the name of a control but don't know the exact name
It kinda begs the question though.. why dont you know the name of the control?! Was it not named very well?


For an opinion on why microsoft simply say "Dont Use Hungarian", we can look to an interesting point/opinion from Joel:
http://www.joelonsoftware.com/articles/Wrong.html
 
It kinda begs the question though.. why dont you know the name of the control?! Was it not named very well?
Some forms can have a very large number of controls and I can't remember all the names. Did I name that textbox LastNameTextbox or SirNameTextBox? I guess I must be getting old.
 
Some forms can have a very large number of controls and I can't remember all the names. Did I name that textbox LastNameTextbox or SirNameTextBox? I guess I must be getting old.

I admit I have, on occasion, nipped into design view and clicked a control to read its name but it really is quite rare that I need to do this.. as I age, it might become more common ;)

Additionally, I find the source outliner powertoy incredibly useful - it groups all the members of a class by type (variables/properties/methods) so acts as a list of the textboxes I have on a form, as well as a quick nav to methods etc
 
Cjard, I started to read the link you posted but stopped reading after 3 minutes to mop the blood up pouring from my nose ;)

So here I am in limbo ga ga land.

I created a new app and copy/pasted all the form details controls etc into it and named them such as newtransactiondescriptionTextBox etc etc and felt holy unclean and violated :eek:

I stuck with it and renamed the lot.....and there are a lot I tell you, but I could not sleep or rest easy as deep down this just goes against the grain of how I have always done things.

Yes, I should know what the controls are called and yes they can be found with intelli sense, but having all textboxes start with txt or comboboxes with cbo just makes things more crisp and cleaner to me.

I also not that you said functions should be like this:

Private Function ThisIsMyNameButton_Click

However, if I have a button named thisismynameButton (painful to read) and then double click to have the IDE create the code block for me it gives this:

Private Function thisismynameButton_Click

Which means for me to follow the convention I would have to alter every block created by the designer.

I guess as the programs I write in VB.NET 2005 are of my own private 'for fun' ones that will never have another developer modify etc it probably does not matter really what convention I use.

The good thing about all this is that this has made me sort of start my app that was almost finished again in a much more conventional way, ie I have removed underscores from the names of items in the app, I have redesigned my database after reading your suggestions and watching the Absolute videos pointed out by JohnH.........and best of all am now using datasets with bindingsources and tableadapters all provided by the IDE. Rather than the way I was doing it, manually creating everything in code.

So all in all not a total loss.......you guys have taught me some very important things ............ thanks muchly :D
 
Cjard, I started to read the link you posted but stopped reading after 3 minutes to mop the blood up pouring from my nose ;)

So here I am in limbo ga ga land.

I created a new app and copy/pasted all the form details controls etc into it and named them such as newtransactiondescriptionTextBox etc etc and felt holy unclean and violated :eek:
Hate to tell you this, but ms recommends camelCasing for everything, not just the type:

newTransactionDescriptionTextBox

I stuck with it and renamed the lot.....and there are a lot I tell you, but I could not sleep or rest easy as deep down this just goes against the grain of how I have always done things.
Poor guy.. where did you get the impression that you were to useaformthatlookslikethisexceptforTheTypeName?

Yes, I should know what the controls are called and yes they can be found with intelli sense,
Dont forget to instlal the powertoys for VS2005 from MS. Source Outliner is very nice

but having all textboxes start with txt or comboboxes with cbo just makes things more crisp and cleaner to me.

I also not that you said functions should be like this:

Private Function ThisIsMyNameButton_Click
I actually think even the IDE gets these wrong..

However, if I have a button named thisismynameButton (painful to read)
thisIsMyNameButton

Private Function thisismynameButton_Click
Private Function ThisIsMyNameButton_Click
Private Function TxtThisIsMyName_Click

better/worse?

Which means for me to follow the convention I would have to alter every block created by the designer.
You think VB guys have it tough.. if you rename the method in C# it might update the reference in the designer generated code for the handler addition..

I guess as the programs I write in VB.NET 2005 are of my own private 'for fun' ones that will never have another developer modify etc it probably does not matter really what convention I use.
Probably not, just get used to the idea that if you work in a team of developers then youll be working to a standard, which will probably be based on MS guides for obvious reasons..

Rather than the way I was doing it, manually creating everything in code.
Every cloud... ;)

So all in all not a total loss.......you guys have taught me some very important things ............ thanks muchly :D
Welcome!
 
Noting of course that that page is specific to .NET 3.0
See the box int he top right for guides to 2.0 and 1.1 :)
They don't look different in this case. :)
Hate to tell you this, but ms recommends camelCasing for everything
No, they recommend PascalCase for everything, except camelCase for parameters.
 
No, they recommend PascalCase for everything, except camelCase for parameters.
I didnt mean everything in the "everything in the language" sense, I meant "everything in the word."
Snipping the "not just the type" off the sentence makes it easier to take this statement out of context

I'll clarify my original posting..
 
The edit button is gone from the post you quoted.. Since when was it impossible to revise a posting? Is this a recent change?

John, can you edit the text to:

Hate to tell you this, but MS recommends camelCasing for every word in the identifier, not just the type:

newTransactionDescriptionTextBox



Thanks
 
Back
Top