Solved

VB.NET Naming Conventions for Controls

Posted on 2004-08-04
35
2,098 Views
Last Modified: 2012-06-21
VB.Net apparently does not recommend the use of Hungarian notation for variables, properties, methods, etc. I haven't found any specific guidance on controls (i.e. lbl_Name, tbx_Name). Anyone have an authorative source for such guidance?
0
Comment
Question by:xmlnewbie
  • 9
  • 8
  • 7
  • +6
35 Comments
 

Expert Comment

by:brianhj
ID: 11722639
0
 

Author Comment

by:xmlnewbie
ID: 11723419
Not sure what you are trying to point out. If you are showing the Hungarian Notation for variables, that's not what I want. MS says that's out. I'm not using it anymore. I'm not sure about controls, though.
0
 
LVL 8

Expert Comment

by:rfgkev
ID: 11724005
it's entirely down to personal choice.
Alot of programming shops have their own standards that they expect their employyes to adhere to, to ensure that all of their work is consistent. There is nothing worse maintenance wise than trying to debug code written by 3 different guys (or gals) who each use different notation, etc..

Variables and Controls are both objects, so why use hungarian notation for one and not the other?
0
 

Expert Comment

by:brianhj
ID: 11724119
"Variables and Controls are both objects, so why use hungarian notation for one and not the other?"

Exactly.  There is no "authorative source for guidance" when naming controls/variables.  Hungarian notation is just a naming convention that Dr. Charles Simonyi of Microsoft came up with in the DOS days.  It's just a suggestion on how to name variables (and now controls).
0
 

Author Comment

by:xmlnewbie
ID: 11724136
The help files keeps saying not to use Hungarian for so many things. I just can't find anything about controls specifically.
0
 
LVL 8

Expert Comment

by:rfgkev
ID: 11724147
I should maybe have rephrased that last one, Controls ARE variables. So although it is entirely up to the developer, it is generally considered to be best to be consistent in your coding.
0
 

Author Comment

by:xmlnewbie
ID: 11724163
What would MS say?
0
 
LVL 8

Accepted Solution

by:
rfgkev earned 25 total points
ID: 11724174
They would probably say it can allow hackers to run code on your machine so install the latest windows updates immediatley :)
0
 
LVL 44

Assisted Solution

by:Arthur_Wood
Arthur_Wood earned 25 total points
ID: 11725055
xmlnewbie>> let me ask you one VERY simple question:  If Microsoft said 'JUMP', would you ask 'How high?', on the way up?

Why is it important to you what Microsoft would say about your PERSONAL choice of naming convention in YOUR programs - and when they are compiled, the names that you CHOSE to use are no longer present in any case.  Are you suspecting the Microsoft is somehow spying on you as you write your code, and if you violte thier guidance, then Bill Gates will personally come to your office and whip you with a limp noodle?

The choice of naming convention is completely up to you (and possibly the guidelines of the shop where you work), and while Microsoft can offer an opinion, that is all it is, AN OPINION.  And like everything else, they are entitled to their opinion and you are entitlted to your opinion.

AW
0
 
LVL 7

Expert Comment

by:Joe_Griffith
ID: 11725663
Microsoft has put a lot of naming recommendations into the FxCop documentation (not sure they have recommendations for controls).  Still it's a good place to see the MS recomendations:  http://www.gotdotnet.com/team/fxcop/
0
 
LVL 8

Expert Comment

by:rfgkev
ID: 11725821
have you ever run FXCop against the FXCop exe? it produces some interesting results. Mainly stating that you should not catch System.Exceptions, and that alot of the methods are not used so should therefore not be coded.  The FxCopCommon dll is even better, "Member names should consist of correctly spelled words".
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 11726109
Once more into the breach my friends.  Another one into the dogpile.

Naming Guidelines from Micro$oft:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpgenref/html/cpconnamingguidelines.asp

Bob
0
 
LVL 4

Expert Comment

by:rohanpandya
ID: 11726139
Ok

 Try following

 3D Panel      pnl      pnlGroup
Animated button      ani      aniMailBox
Check box      chk      chkReadOnly
Combo box, drop-down list box      cbo      cboEnglish
Command button      cmd      cmdExit
Common dialog       dlg      dlgFileOpen
Communications       com      comFax
Control (used within procedures       ctr      ctrCurrent
when the specific type is unknown)
Data control      dat      datBiblio
Data-bound combo box      dbcbo      dbcboLanguage
Data-bound grid      dbgrd      dbgrdQueryResult
Data-bound list box      dblst      dblstJobType
Directory list box      dir      dirSource
Drive list box      drv      drvTarget
File list box      fil      filSource
Form      frm      frmEntry
Frame      fra      fraLanguage
Gauge      gau      gauStatus
Graph      gra      graRevenue
Grid      grd      grdPrices
Horizontal scroll bar      hsb      hsbVolume
Image      img      imgIcon
Key status      key      keyCaps
Label      lbl      lblHelpMessage
Line      lin      linVertical
List box      lst      lstPolicyCodes
MAPI message      mpm      mpmSentMessage
MAPI session      mps      mpsSession
MCI      mci      mciVideo
MDI Form      mdi      mdiNote
Menu      mnu      mnuFileOpen
MS Flex grid      msf      msfClients
MS Tab       mst      mstFirst
OLE      ole      oleWorksheet
Outline       out      outOrgChart
Pen BEdit       bed      bedFirstName
Pen Hedit      hed      hedSignature
Pen ink      ink      inkMap
Picture      pic      picVGA
Picture clip      clp      clpToolbar
Report      rpt      rptQtr1Earnings
Shape       shp      shpCircle
Spin       spn      spnPages
Text box      txt      txtLastName
Timer      tmr      tmrAlarm
UpDown      upd      updDirection
Vertical scroll bar      vsb      vsbRate
Slider      sld      sldScale
 
Control type      Prefix      Example

ImageList      ils      ilsAllIcons
TreeView      tvw      treOrganization
Toolbar      tlb      tlbActions
TabStrip      tab      tabOptions
StatusBar      sta      staDateTime
ListView      lvw      lvwHeadings
ProgressBar      prg      prgLoadFile
RichTextBox      rtf      rtfReport
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 11726143
That goes back to the Hungarian Notation that Micro$oft is trying to get away from:)

Bob
0
 

Author Comment

by:xmlnewbie
ID: 11733934
TheLearnedOne, your link explains naming convention for everything else but does not specifically address controls. Did I overlook something?

Arthur_Wood, you went off on a tangent. Nevermind what I'll do if MS tells me to jump. I'll cross the bridge when I get there. For now, just make the assumption that all I want to know is what is MS's recommendation for naming controls. And no, I am not afraid of Bill Gates coming to my office to whip me with a limp noodle. I happen to have two in case of such situations. Bill Gates -- bring it on.
0
 

Expert Comment

by:brianhj
ID: 11733946
We already told you.  Hungarian notation is MS's recommendation.  They created it.  It's on their web site.  And it extends to controls.
0
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 
LVL 8

Expert Comment

by:rfgkev
ID: 11734034
"Prefix interface names with the letter I, to indicate that the type is an interface" - is this not hungarian notation? (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpgenref/html/cpconinterfacenamingguidelines.asp)

Although not built by microsoft, it is build by a Microsoft Gold Certified Partner and distributed on MSDN as one of their best examples,
if you look at the TaskVision source code (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnwinforms/html/wnf_TaskVision.asp) you will see that they use hungarian notation.
0
 

Author Comment

by:xmlnewbie
ID: 11734126
brianhj, I guess I am not making myself clear. I know Hungarian is MS's recommendation. I know the history of Hungarian notation. I know how to use it. I know it's on the MS web site. What I suppose I am not making clear is that MS DOES NOT RECOMMEND THE USE OF HUNGARIAN FOR VARIABLES, etc. in VB.NET. In other words, you will not find a variable named "strFirstName" in an application that follows MS's new convention.

rfgkev, are controls and interfaces the same? I've never prefixed a, say, text box with "I." Instead, I would use the prefix "tbx" (as in tbx_FirstName). Am I confused with the terminologies here? Is a text box (or form, or list box, or button) a control? I'll be looking at your link tomorrow.
0
 
LVL 8

Expert Comment

by:rfgkev
ID: 11734154
They are being used in a different context, The interface was microsoft's recommendation for naming the actual interface class. With controls we are talking about naming instances of them in which case they are class level variables, and since microsoft recommend to not use hungarian notation for variables(although i have still not seen them say this anywhere so maybe you could post a link to somewhere you seen it) they must obviously not use hungarian notation for controls as they would be breaking their own recommendation.
0
 

Expert Comment

by:brianhj
ID: 11734177
"As it turns out, the Hungarian naming convention is quite useful—it's one technique among many that helps programmers produce better code faster. Since most of the headers and documentation Microsoft has published over the last 15 years have used Hungarian notation names for identifiers, many programmers outside of Microsoft have adopted one variation or another of this scheme for naming their identifiers."

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnvsgen/html/hunganotat.asp


This question is ridiculous.  Lol.
0
 
LVL 8

Expert Comment

by:rfgkev
ID: 11734195
4th line down says "Reprinted November 1999"

The question relates to microsoft's recommendations for .NET
0
 

Expert Comment

by:brianhj
ID: 11734207
Yes I know it's from 1999.

It doesn't matter anyway.  He doesn't see that variable naming is personal preference.
0
 

Expert Comment

by:brianhj
ID: 11734212
And.. what difference does it make what version of the language you use?  Why would naming conventions for VB 4,5,6,.NET change?
0
 
LVL 8

Expert Comment

by:rfgkev
ID: 11734226
yes, he was asking for Microsoft's recommendation on naming controls. Microsoft's recommendations on naming has changed quite a bit from VB6 to .Net, why? who knows.
0
 

Author Comment

by:xmlnewbie
ID: 11737038
The reason MS says to no longer use Hungarian is that the .NET IDE does a good job of helping you figure out what type a variable -- just place the mouse pointer over the variable in code editor and it'll show you how the variable was defined. If you are in debug mode, just look at the Locals and Watch windows and it'll tell you a variable's type.

brianhj, I realize naming convention is a personal preference. This is not a matter of personal preference. I am researching what MS's recommendation is. The link you posted does not apply to .NET.

rfgkev, take a look at this guide for naming properties in .NET: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpgenref/html/cpconpropertynamingguidelines.asp - 3rd bullet say not to use Hungarian.
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 11737123
The truth is, no matter what Micro$oft or anybody else says, a programmer can do anything that they so choose.  You have the choice to do anything that you want.  

With VB.NET, C#, J#, and the other .NET programming languages, Micro$oft was trying to get away from type-specific variable names, since they violate cross-platform programming.  If you are not doing that, then I wouldn't worry:)

Bob
0
 
LVL 8

Expert Comment

by:rfgkev
ID: 11738580
but the link  http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpgenref/html/cpconpropertynamingguidelines.asp relates to public properties, which nobody uses hungarian notation on anyway as it would just look silly.

The only things that say do not use hungarian are Public things, i.e properties/classes/namespaces etc... which a developer using your class would see. Nothing is said about Private variables.
0
 
LVL 44

Expert Comment

by:Arthur_Wood
ID: 11741563
as rfgkev points out:

"The following rules outline the naming guidelines for properties:"  

from the first line of the posted link. This advice says ABSOLUTELY NOTHING about naming conventuions for VARIABLES.  The advice to NOT USE HUNGARIAN notation applies to naming PROPERTIES of objects, where NO ONE, in his/her right mind, would ever even consider using Hungarian notation.  It would be sort of like advising you to NOT wear Combat Boots when swimming - or the advice that I have seen on some Irons - to NOT use them on clothes while the clothes are being worn.

The original question is asking about something that is irrelevant. Sorry to be so blunt.

AW
0
 

Expert Comment

by:brianhj
ID: 11741567
Lol.

This is all too much.
0
 

Expert Comment

by:todd_
ID: 11759854
Yea theres a lot here, but basically, Microsoft doesn't want you to use str, int, or whatever anymore.. For example.. if in VB6 you had a variable named intCustomerID you might just use something like CustomerID or customerID in VB.NET. I myself still use all the same conventions used in VB6 because it's just what I'm used to. You should just find what style you like best and stick with it. Here are some sample styles for a counter variable:

intCount
Count
count
iCount
int_count
int_Count

It's all about choice and whatever YOU want to use.
0
 

Author Comment

by:xmlnewbie
ID: 11857872
Last time: I am trying to find out what Microsoft recommends. I realize I have the option to do whatever I want to. That's not the point. What is Microsoft's guidance on naming controls. I am specifically interested in the naming convention of controls only. I know for a fact that the MS has recommended against using Hungarian on "data type" variables (i.e. intCounter), classes (i.e. CHelloWorld), functions (i.e. intFoosball for a function that returns an integer), etc. Interfaces still seems to be prefixed with an "I" in VB.NET.

Please stop advising me that this issue is a personal preference. I am fully aware of that. However, I am really looking for MS's guidance on naming controls. And I need references.

I will request that this be deleted in a few days if I don't find the answer I am looking for.
0
 

Expert Comment

by:brianhj
ID: 11857912
You won't find the answer because there isn't one.
0
 

Expert Comment

by:waynefeltham
ID: 11868605
lol...it's very funny how sometimes a simple question (with a simple answer) gets soo complicated!

MS changed their naming convention because the IDE is so much better in providing a developer details about variables (types etc) that there is no longer a need to identify a variable type through it's prefix.

MS also recommend naming variables fully.  So if you need a variable to keep count of the number of wheels on a bus, use something like numberOfWheelsOnBus rather than intWheelCounter.

Everything (to my understanding) in .NET is an object.  Yes, they have value objects and reference objects (read up on this because I'm not gonna explain it) but everything is an object (feel free to correct me if I'm wrong here) including controls.

So, when it comes to controls, MS are suggesting you use the same naming convention.

So where in VB you would have previously called a textbox containing a firstname something like "txtFirstName" you should now call it firstNameTextBox.

This is my interpretation of the MS naming guidelines...but thats what a naming convention is there for...interpretation.

I think it's good that everyone adopts the same standard but it's never gonna happen...so just code how you're comfortable  :)

Cheers


Wayne
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now