Hungarian Notation

  • Thread starter Sebastian Mares
  • Start date
S

Sebastian Mares

Hello!

As long-time Visual Basic 5 and 6 developer, I am quite familiar with
the Hungarian Notation and used it in most of my programs. Now that I
finally got into the .NET world and learned VB .NET and C# (and am
currently learning C++), I decided to give up HN as recommended by
Microsoft. However, I am facing one problem: Microsoft recommends to use
names that are semantically relevant. Therefore, if you have a text
field for example where the user has to enter his first name, you would
name that text box "FirstName" instead of "txtFirstName" or "Textbox1"
or "Name1" or whatever. But what do you do when you have a menu item and
a toolbar button that both do the same thing? Semantically, there's no
difference between the two elements, but unlike in "legacy" Visual Basic
where you could give two controls the same name in order to have a
control array, you have to give the two controls different names. With
HN, you could name one control "mnuOpen" (mnu = menu) and the other one
"tbOpen" (tb = tool button). Does anyone have a solution for this (other
than using Open1 and Open2 as control names)?

Regards,
Sebastian
 
S

Scott M.

In this particular case (naming controls), I continue to use Hungarian
Notation (txtFirstName, btnSubmit, etc.). I do not, however use it on
variable names, class names or any other programming structure that would be
named.
 
H

Henning Krause [MVP - Exchange]

Hello,

you can also append a suffix: SubmitButton, FirstNameTextBox,
FirstNameMenuItem, and so on.

Best regards,
Henning Krause
 
S

Sebastian Mares

Yes, but unfortunately, this brings back the problem that you have to
replace all references to that particular control once you decide that
you no longer want a textbox, but a combobox for example since you will
have to rename "FirstNameTextBox" to "FirstNameComboBox".

Regards,
Sebastian
 
S

Scott M.

I find that notation difficult, cumbersome and not a standard I've ever seen
anyone else use.
 
S

Scott M.

True, but a couple of points on that:

1. Honestly, how often does this come up?
2. Find & Replace would easily solve this problem in one easy stroke.
 
R

RobinS

Feel free to search this group and microsoft.public.dotnet.languages.vb for
"Hungarian notation" and read the thousands of posts, discussions, and
arguments in favor of and against Hungarian Notation, and save the rest of
us from having the whole thing hashed over again. Really, we wouldn't mind.
:-D

Robin S.
 
J

Jon Skeet [C# MVP]

Henning Krause said:
you can also append a suffix: SubmitButton, FirstNameTextBox,
FirstNameMenuItem, and so on.

That would be my preference too - to me, it reads much more clearly.
It's how you would describe it in English:
"What's that there?"
"It's the address textbox."

You certainly wouldn't say "It's the textbox address."

As Scott says, it's far from standard, but there we go...
 
R

RobinS

Jon Skeet said:
That would be my preference too - to me, it reads much more clearly.
It's how you would describe it in English:
"What's that there?"
"It's the address textbox."

You certainly wouldn't say "It's the textbox address."

As Scott says, it's far from standard, but there we go...

If it makes you feel any better, Jon, this is the standard the Microsoft
seems to be following these days.

Robin S.
 
C

Cor Ligthert [MVP]

Sebastian,

As Scott wrote with the 3 lowercase characters for controls starting with,
is the most common I see this in this newsgroups. (There are some more for
the most used objects in the Data namespace).

Cor
 
S

Sebastian Mares

I already searched for Hungarian notation but everything I come up with
is related to how to name variables, classes, pointers and that sort of
things. Even Microsoft's naming conventions handle only "back-end" stuff
and don't mention Windows-Forms development at all (at least from what I
found).

Regards,
Sebastian
 
S

Sebastian Mares

I also prefer writing the full name of the control especially since .NET
has a plethora of controls and coming up with a unique shortcut (and
avoiding ambiguity) for all of them won't work easily.

Regards,
Sebastian
 
A

AMDRIT

I still like the Hungarian Notation, and think that it is just a guildline
to follow a different way. It is more confusing to rely on undescores and
alternate case (C++ and C#) to differentiate variables, properties and
controls.

I believe any developer can encouter either standard and continue forward.
Besides, it is generally a practice to document the coding standards used
for development prior to developing, so as the team grows or changes there
isn't too much unknown.

Either way, when learning new things, there is no reason to give up on
things that are second nature. Become proficient first, then worry about
naming conventions is my rule.
 
J

Jon Skeet [C# MVP]

Sebastian Mares said:
I already searched for Hungarian notation but everything I come up with
is related to how to name variables, classes, pointers and that sort of
things. Even Microsoft's naming conventions handle only "back-end" stuff
and don't mention Windows-Forms development at all (at least from what I
found).

Well, bear in mind that when you name a control, you *are* naming a
variable - at least in Windows Forms. (It's not necessarily true in
WPF.)
 

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