I finally did it-- hungarian notation

C

CMM

Early in the lifecycle of the guidelines (way back in 2002 or so) they did
espouse camelCase for private variable.... but then decided to concentrate
on the PUBLIC object model of classes rather than enter into the fray of all
the arguments going back and forth in the community.

Again, look at all their code samples. Look at the Right-click Code Snippets
in VS2005.... you'll see that you're wrong.


Mitchell S. Honnert said:
They do so in the internal naming guidelines and in the "Field Usage
Guidelines" chapter.
Herfried, am I looking in the right place?
http://msdn.microsoft.com/library/d...s/cpgenref/html/cpconfieldusageguidelines.asp

If so, then I still hold to my assertion that Microsoft doesn't state
definitively to use camelCase for variables defined within a method.
Admittedly, the sample code uses this convention, but as we both have
pointed out, this is most likely a result of the fact that the VB.NET
sample code was written by C# developers. Nowhere do I see a plain
statement by Microsoft that says, "Use camelCase for local variables in a
method."

As I've mentioned in other subthreads, using camelCase for variables
defined within a method would render the use of camelCase for parameters
as useless. So, surely this can't be what they really mean. When a
programmer sees a variable in camelCase format, they know that the only
place in the Microsoft standards where camelCase is explicitly recommended
is for parameters, so they know it must be a parameter.

"Use camelCase for parameters and PascalCase for everything else." That's
what I get out of reading the MS standards. camelCase may be messy, but
given this definition, it's so narrowly defined that it isn't a bid deal.

Mitchell S. Honnert
www.UltraID3Lib.com
 
C

CMM

I never said to use camelCase for Method names. I said use camelCase for
private method variables... "locals."

A parameter is a local. Who cares that it was "passed in." Like I said, I
have never in 17 years felt it necessary to care. A local is a local.

What I DO care about is whether the identifier I'm currently dealing with is
a local variable (my variable!), a static member of some imported namespace
(like System, or whatever), a property (setting a property rather than its
underlying *variable* might not be what I want to do!) or a global
subroutine defined in some global module (VB "Module").

It seems to me that nobody even understands what a variable, a static
member, or even a property is. It's all about "instantiation."


Mitchell S. Honnert said:
You make a good point about the code snippets. However, a precedent has
been set for MS correcting the format of their autogenerated code. For
example, when the 2003 VS.NET IDE autocompleted the property code, it
would use "Value" as the parameter name in the Set portion. "But wait,
Microsoft. In your naming guidelines, you tell me to name all of my
parameters using camelCase, yet your own autogenerated codes breaks this
rule and uses PascalCase." Then in VS.NET 05, this behavior was corrected
and "value" is used. Someone must have pointed out that MS wasn't eating
their own dogfood.

So, yes...it's a good idea to look at sample code and code snippets for
guidance on naming standards, it's not the end-all-be-all. Given the lack
of a definitive statement from MS that we should use camelCase for
variables defined within a method, I'm left with the subjective option of
what sounds reasonable to me. Given the fact that using camelCase would
render pointless the stated naming standard for parameters in combination
with the fact that PascalCase is used for everything else, using
PascalCase for these variables makes sense.

Something just occurred to me about naming method variables...
Herfried is saying that MS is telling everyone to use camelCase, but that
everyone shouldn't use camelCase.
I'm saying that MS doesn't say to use either camelCase or PascalCase, but
that everyone should use PascalCase.
And you're saying that Microsoft uses camelCase, so everyone should use
camelCase.

I think we have all of the bases covered! :)

Hmmm...I wonder what FxCop would have to say about all this?

- Mitchell S. Honnert

CMM said:
Also, to add to my other reply (concering your use of PascalCase on
locals... which I find fascinating... like driving by a car crash)...
Although Microsoft's naming guidelines doc concentrates on the public
object model of your classes... in every single Example in the Help
system and in MSDN and even (most notably) in the myriad of "Insert
snippet" snippets in VS2005 they use camelcase or all lowercase for local
method variables.

Really simple example: try Insert Snippet -> Filesystem -> Create
temporary file.
What do you see?
Now check out GetTempFileName topic in Help and see what the usage
example looks like. What do you see?


Mitchell S. Honnert said:
Why not just GoneBad? The naming standard for local, private variables
may have been stated somewhere is MS's guidelines, but I haven't found
it yet. But, in light of the fact that they say to use PascalCase for
*everything* in their spec except for parameters, I just use this style
for private variables as well.

In fact, if you name your private variable goneBad, you would be
rendering as useless the camelCase parameter naming convention. The
whole point of having only parameters be camelCase is that you can
identify at-a-glance variables that have been passed into a method. But
if you dimention new variables within the method using camelCase, you've
lost this benefit.

In regards to your "GoneBad", I've adopted what seems to be a common
convention of prefixing Boolean variables with "Is" or "Has". As in,
IsClosed or HasGoneBad. Maybe that's a little too close to Hungarian
notation, but it brings a certain level of consistency to the code.

- Mitchell S. Honnert

Oh, the only reason I do it for local variables is for easier
identification. It's easier to seperate out:
goneBad
than it is to seperate out:
gonebad


Herfried, I don't read German, so I haven't read your article, but I
do
have
a question about your first summarized point...
* Distinction of two identifiers (property, backing field) by case
only
can
lead to bugs in the implementation which cannot be easily
detected.
As far as I can tell, the only place in the .NET naming standard where
it
says to use camelCase is for parameters. (I think there may be have
been
one other variable type where they recommended camelCase, but if I
remember
correctly, it was very rarely used.) So, the point you are making
doesn't
appear to apply MS's naming standards.

In other words, MS never says to use camelCase for "backing field"
variables, as in the example...
Private firstName As String

At least, it never says it on any official MS web page that I have
found.
Here's where I have been looking.

http://msdn.microsoft.com/library/d...en-us/cpgenref/html/cpconnamingguidelines.asp

Is there some other reference that you are using? Do you have a
particular
link that says to use camelCase for variables other than parameters?
(I've
seen camelCase used inconsistently in MS's own VB.NET sample code, but
this
probably has more to do with the authors of the sample code being C#
people
than evidence of any particular naming standard.)

The problem I have is that MS states explicitly what naming convention
to
use for Classes, Namespaces, Parameters, Methods, and Properties, but
as
far
as I can tell, they don't say how to name private member variables
like
the
private "backing field" for a property. I use a "p_" prefix to
differentiate these private member variables as those used by
properties,
but this is just my convention that I use for lack of being able to
find
anything definitive from MS.

Regards,

- Mitchell S. Honnert


: > So after three years of working in .NET and stubbornly holding
on
to
my
: > old hungarian notation practices--- I resolved to try to rid
myself
of
: > the habit. Man, I gotta say that it is liberating!!! I love it.
:
: Well, I do not use type prefixes ("Systems Hungarian") because I
use
: 'Option Strict On' most of the time. However, I use type
prefixes
when
: dealing with late binding (variables typed as 'Object').
Additionally
: I use the 'm_' prefix to mark private fields, and I tend to use
Apps
: Hungarian because it still makes sense in strictly-typed
languages.
:
: On a side note: I still refuse to use camel case for the reasons
listed
: in <URL:http://dotnet.mvps.org/dotnet/articles/camelcase/>
(German
: article!).

Could you summarize the points being raised in this article for
those
of
us
who don't read German? Thanx,

The points made in the article are:

* Distinction of two identifiers (property, backing field) by case
only
can
lead to bugs in the implementation which cannot be easily
detected.

* By naming the property using pascal case and the backing field
using
camel case it's harder to visually detect that both belong to
each
other.
This argument is based on a human visual character recognition
model.

* The naming rules described in the .NET Framework Design
Guidelines
and the internal Guidelines published by Brad Abrams [MSFT]
cannot be
applied to VB.NET because VB.NET is not case-sensitive.

* The first character of a word/sentence serves an important role
for
word recognition. In classic typography the first letter has
often
been
written in upper-case and sometimes ornamented to underline its
importance. By starting identifiers' names with a lower-case
letter
while using upper-case letters inside the identifier this long
tradition
in typography is obeyed.

* Most naming guidelines are made by developers only instead of
consulting developers, psychologists, linguists, etc. who have
the
scientific background to optimize naming guidelines.
 
M

Mitchell S. Honnert

Even if you yourself like it... as developers I think we all have the duty
to think about people in the future who may have to maintain our code and
might be confused by your super-non-standard naming conventions.
"Super-non-standard"? Please, let's not get melodramatic here. I use the
p_ prefix in my own code, but I'll be the first to admit that you probably
wouldn't find it "in the wilds", so to speak.

As for the use of PascalCase, I think it's much more common in the VB world
than you think. Again, given the long history of PascalCase in Visual
Basic, it's my impression that the samples you are referring to have more to
do with the fact that the people writing the code are C# people rather than
VB people and less to do with any overall master plan on MS's part.

Don't make the mistake of thinking that just because you interpret a naming
standard in a particular way, that I'm dismissing the later developers who
might have to maintain my code. It's for the very reason that I've *been*
that developer who has had to maintain other people's code that I'm so
passionate about naming standards.

- Mitchell S. Honnert
 
C

CMM

Mitchell S. Honnert said:
As for the use of PascalCase, I think it's much more common in the VB
world than you think. Again, given the long history of PascalCase in
Visual Basic, it's my impression that the samples you are referring to
have more to
<snip>

I have seen some really bad coding practices in the last 11 years in the VB
world. I have never seen someone who used PascalCase to name local
variables.
do with the fact that the people writing the code are C# people rather
than VB people and less to do with any overall master plan on MS's part.

That's an assumption. The fact is that pretty much everybody everywhere
nowadays uses camelCase for variables (not just VB or C# but also Java...
obviously). I resisted it.... but a common standard is more important to me
than my own personal likes and dislikes. I'm not saying its perfect. I am
saying that it IS CONSISTENT.

At my job I have to maintain several VB and ASP.Classic apps. One VB
convention is followed in one (sThis, iThat) and another in the other app
(intThis, lngThat)... and worse (cmdThis, btnThat) and even worse
constructs. A common convention like today's camelCase for vars, PascalCase
for everything else, etc etc is very liberating and very consistent and will
make for much more maintainable body of work.
 
H

Herfried K. Wagner [MVP]

Mitchell S. Honnert said:
Herfried, am I looking in the right place?
http://msdn.microsoft.com/library/d...s/cpgenref/html/cpconfieldusageguidelines.asp

If so, then I still hold to my assertion that Microsoft doesn't state
definitively to use camelCase for variables defined within a method.
Admittedly, the sample code uses this convention, but as we both have
pointed out, this is most likely a result of the fact that the VB.NET
sample code was written by C# developers. Nowhere do I see a plain
statement by Microsoft that says, "Use camelCase for local variables in a
method."

ACK. *I* have *never* been talking about local variables and claiming that
Microsoft recommends camel case for them.
 
M

Martin

Phill W. said:
That's no problem - three letters gives 17,000-odd possibilities, and
there's
only 4,000-odd classes in the Framework... ;-)

And it's easier to read at a glance in the source code. btnOK is a lot more
clear than bOK ;-)
What makes you think that?

Well, I'm just beginning to leave my trusted VB6 for VB2005 and had to buy a
book because the VB2005 help system is utterly and totally useless. Of
course no time to read the entire book from cover to cover, but I did read
it somewhere in there.
And what's wrong with

For Each ctl As Control in Me.Controls

If TypeOf ctl Is TextBox Then
. . .
ElseIf TypeOf ctl Is ListBox Then
. . .
End If

Next

??

That looks pretty cool! Wish I had know that...
 
C

CMM

Well, I'm just beginning to leave my trusted VB6 for VB2005 and had to buy
a book because the VB2005 help system is utterly and totally useless. Of
course no time to read the entire book from cover to cover, but I did read
it somewhere in there.

I found Dan Appleman's (yeah the VB6 Guru API GOD) "Moving to VB.NET" book
to be extremely helpful as a fantastically concise primer illustrating the
"main differences" between VB.NET and VB.Classic.
<code snipped>
That looks pretty cool! Wish I had know that...

Didn't that work in VB4/5/6 also?
 
C

CMM

You're still sticking to good ol' typeName notation right (sThis, iThat or
strThis, txtThat)?
I was too until about two weeks ago. I suggest you give dropping it a try.

It's about time the VB community grew up and let go of a lot of its past. We
won't shed the "vb code is messy" and a kiddy, inconsistent, messy language
until we do. The mere fact that some us use "p_" for anything (ack!) and
other "personal preference" constructs is evidence of what gives VB a bad
name (IMO).
 
M

Mitchell S. Honnert

That's an assumption. The fact is that pretty much everybody everywhere
nowadays uses camelCase for variables (not just VB or C# but also Java...
obviously).
Now who's assuming? Because "everyone everywhere" that *you* see follows
your version of the naming standard, then anyone else is "bad" and
"super-nonstandard"? Look, naming standards in general are subjective. As
you pointed out, even Hungarian notation has different versions. (Is it
iCustomerNum or intCustomerNum?) My main assertion is that without an
objective statement from Microsoft, the naming conventions are left to the
subjective interpretation of the developer. You seem pretty adamant that
using PascalCase for local variables is a very bad thing. My take on it is
that there are pros and cons to any given standard and that short of a clear
statement from Microsoft, people are going to use what they think makes
sense. In my experience, people mostly ignore the specs that *are*
explicitly stated by MS anyway, so I'm lucky if the code I see has any
semblence of order to it.

- Mitchell S. Honnert
 
M

Martin

I'll have a look if I can find that book. The thing is... the country where
I currently live isn't very rich on these kind of books. I'm programming a
class library in VB2005 to replace our control and function library of VB6
with a Sybex book on my lap. The thing is.... this book is written for
VB.Net 2003. And it seems that especially in the area VB2005 has changed
significantly. The whole 'inherits' thing is in a seperate file now
(mycontrol.designer.vb) which doesn't seem to be intended for editing.
Therefore the examples in the book don't really work.

If I want to make a sub class of for instance the Textbox control, the book
tells me to create a user control and replace the 'inherits
system.wondows.forms.usercontrol' statement with 'inherits textbox' But the
inherits statement is in that hidden designer file. When I change it there,
it leads to a whole bunch of errors and can't open in the designer no
longer...

If you could give me a few pointers here, I'd really appreciate it.

Martin
 
H

Herfried K. Wagner [MVP]

CMM said:
You're still sticking to good ol' typeName notation right (sThis, iThat or
strThis, txtThat)?
I was too until about two weeks ago. I suggest you give dropping it a try.

I stick to "all pascal case" + 'm_' prefix for private fields. I only use
Systems Hungarian when working with 'Option Strict Off', in some late-bound
Office automation scenarios ('appExcel', 'docReadMe', etc.).
 
C

CMM

Mitchell S. Honnert said:
My main assertion is that without an objective statement from Microsoft,
the naming conventions are left to the subjective interpretation of the
developer.

Or the community as a whole.

Standards are great. But, norms are even better. Developers that don't
follow either are the cause of a lot of the blight in the programming world
(VB especially-- and unfortunately).
In my experience, people mostly ignore the specs that *are* explicitly
stated by MS anyway, so I'm lucky if the code I see has any semblence of
order to it.

Exactly my point.
 
M

Mitchell S. Honnert

ACK. *I* have *never* been talking about local variables and claiming
that Microsoft recommends camel case for them.
Understood. I think some of the side conversation got onto the topic of
local variables because of my comments about how I could only find one
direct recommendation by MS to use camelCase (for parameters).

If you don't mind me asking, what naming convention do you use for local
variables?

- Mitchell S. Honnert
 
C

CMM

To belabor my point. I'm not saying that modern convention is better than
"your" style... or better than "my" old hungarian notiation style (which I
loved and had utterly perfected!). I am saying that if I look at three
different projects in my day written by three different developers it HELPS
A LOT to see one standard convention used throughout them. Modern coding
standards (perfected in the Java world unfortunately and NOT the VB world to
nobody's surprise) is a good thing.

I hate XML. I think it's a stupid throwback-to-1993 and is bloated and
ill-conceived (I prefer variable-width binary files). But, I use XML... and
I use it alot. It's a standard and everyone understands it. Standards are
key... and maintaining them is key to any company having maintainable code.
 
M

Mitchell S. Honnert

Wow. I've gone from "super-nonstandard" to be a blight on the development
community. I know that we've reached the As-I've-Already-Stated phase of a
dying thread, but one last time... You may have a very clear and
unambiguous idea of what the "community as a whole" thinks about naming
conventions or whatever, but that doesn't make your interpretation the
truth.

It actually sounds like we both have the same feeling that a good set of
naming standards can be very beneficial. I guess I just wish that MS would
actually jump into the fray and give a definitive ruling rather than leaving
it up to assumptions (even reasonable ones) based on sample code.

That's it for me! Goodnight.

- Mitchell S. Honnert
 
H

Herfried K. Wagner [MVP]

Mitchell,

Mitchell S. Honnert said:
If you don't mind me asking, what naming convention do you use for local
variables?

Pascal case, except for variables like 'i', 'j', 's', 't', etc.
 
C

CMM

Mitchell S. Honnert said:
It actually sounds like we both have the same feeling that a good set of
naming standards can be very beneficial. I guess I just wish that MS
would actually jump into the fray and give a definitive ruling rather than
leaving it up to assumptions (even reasonable ones) based on sample code.

So forget samples... how about their actual FRAMEWORKS which implement their
Patterns & Practices and which they distribute as actual source code.
Here's an abridged piece of code (below) from their CompositeUI Block
released just last month.

Sure looks like camelCase for variables and FullNames for control class
names is the norm here!!!
(they even follow through on the concept to module level variables!).

----
Private Sub AddCustomerMenuItem()

Dim customerItem As ToolStripMenuItem = New ToolStripMenuItem("Customer")

workItem.UIExtensionSites(...).Add(customerItem)
workItem.UIExtensionSites.RegisterSite(...)

End Sub
----

Besides.. even without MS, the VB developer community should (somehow)
settle and evolve these standards. Other developer communities have.... and
quite well. Java most notably... but also others. Why can't we? This is one
of the reasons VB is derided. I shudder every time I have to open some large
new VB project that somebody else wrote. I never know what horrors await me.
 
C

CMM

How do you feel about MS's own internal guidelines (which reference VB not
just C#)
"Do use camelCasing for local variables"
http://blogs.msdn.com/brada/articles/361363.aspx

I guess they don't make this part of the official Guidelines, which stresses
only the public object model of your classes, for fear of throwing the
community into chaos.... though I think that's exactly what is happening.
 
C

CMM

And if the VB enterprise frameworks source code isn't enough... how about
their own internal guidelines (which reference VB as well not just C#)?
"Do use camelCasing for local variables"
http://blogs.msdn.com/brada/articles/361363.aspx

Like I said in another post concerning this document.... I guess they don't
make this part of the official Guidelines, which stresses
only the public object model of your classes, for fear of throwing the
community into chaos.... though I think the community (VB especially) is in
chaos.
 
C

Cor Ligthert [MVP]

Mitchel,

This discussion is almost 45 years old. (As long as there are symbolic
languages).

As Herfried has stated very well, done mostly by amateurs like you and me
who are just developers.

For the first time since long, it was enlighten me in this, when Herfired
wrote that we had to look for people who do this for profession.

What I have seen is that especially those who this preach this, are as well
those who the most often sin against this.

That the methods are still evaluating is probably because the previous are
wrong. There are a lot of people against camel case. That a person at
Microsoft has once proclaimed that, will not say that he is the messiah.

Just my thought,

Cor

Mitchell S. Honnert said:
ACK. *I* have *never* been talking about local variables and claiming
that Microsoft recommends camel case for them.
Understood. I think some of the side conversation got onto the topic of
local variables because of my comments about how I could only find one
direct recommendation by MS to use camelCase (for parameters).

If you don't mind me asking, what naming convention do you use for local
variables?

- Mitchell S. Honnert
 

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