Rantings of a skinny man..

wyrd

Well-known member
Joined
Aug 23, 2002
Messages
1,408
Location
California
Im not sure I understand why, but a lot of people coming from VB6 seem to have a hard time ditching their old ways and using the .NET coding style. A few examples;

lblItem, txtItem, etc.. I hated that darn coding style in VB6 and was more then happy to do away with it.

Another example is people just blatantly using the VisualBasic namespaces to use legacy VB6 methods and properties. Just today I saw someone using UCase() :eek: Len() :eek: and FileOpen() :eek:

I just dont get it and just had to make a minor rant about it. :(

BTW.. the examples I used were from other forums I visit so please do not think Im putting anyone from this forum down. :)
 
Just the naming convention as a whole..

strString, dblDouble, intInteger, etc..

Hungarian notation I think it is. I hate it. *stomps on Hungarian notation*. Microsoft suggests using camelCase and PascalCase for .NET (depending on what youre naming).
 
I personally always use hungarian notation for controls (makes it
easier to tell what control is what type), and camelCase for variables.
 
I dont use Hungarian notation, but I wont lose any sleep over using Hungarian notation. Ive never heard of this camelCase & PascalCase, so I probably dont use it... I like my variables short and descriptive. :)
 
I still use Hungarian for controls, but I realized recently that I no longer like it for variables.
I find myself using camelCase in C# and PascalCase in VB. No good reason, it just turned out that way.
 
The VS.NET help collection (the .NET framework SDK help) lists
many different coding techniques and conventions. Although I
still use Hungarian, even for my variables, I might move more
towards the combination suggested from this help file excerpt:

Since most names are constructed by concatenating several words, use mixed-case formatting to simplify reading them. In addition, to help distinguish between variables and routines, use Pascal casing (CalculateInvoiceTotal) for routine names where the first letter of each word is capitalized. For variable names, use camel casing (documentFormatType) where the first letter of each word except the first is capitalized.

Sometimes I use really short names for short-lived
variables (like fs and sr for FileStream and StreamReader classes,
respectively), and of course i, j, k, etc. for loops (although now I
find it much easier to use For-Each loops for arrays). Is this
necessarily a good idea?
 
Is this necessarily a good idea?

Absolutely! :) At least I think it is. I loop through arrays using For-Each Loops almost all the time now. Much more clear to read IMO. :cool:

The quote for the naming guidelines you gave is pretty much what I follow.
 
My question was referring to short, indescriptive variable names...
But I do agree that For Each loops are great to use. I also heard
that in VB6 they are faster than For Next loops, but Im not sure if
this holds true in VB.NET.
 
Well everyone uses i, s, j, c, r etc etc for looping. The fs and sr variables are descriptive enough IMO. No less descriptive then a variable named int ;)
 
I do the same for short lived variables. (x,y,z, fs, sr).

For Each is supposed to be faster in .NET.
 
I always use g for Graphics. It just seems right.

For loops I use i or j.
 
Oh... I use PascalCase... my variables are always capitalized unless other wise... lower case variables bug me...

And I use:
LV, Xf, Yf, N, in for loops and OV, Ol, WF in for each loops.
I, J, and K are reserved for physics. X and Y are standard and so I dont use them... sometimes I declare A B C and D variables... they are all the same type (usually string), often recycled, and used to handle string parsing.
 
How do you distinguish member vars?

I gotta say, I recently finished a contract in an envirnoment with a dozen other programmers (.NET) and we all used each others classes, these types of naming convensions were very helpful.
 
Above you said that you use PascalCase for VB.NET (well, Hungarian for Controls) and camelCase for C#. I use PascalCase except for non-public variables which I use camelCase for, where you (and your team) use m_PascalCase for member variables.

Just something about Hungarian notation that erks me (along with the hole m_ thing, but isnt that considered Hungarian notation as well?).. I cant explain it. :p Just seems like so much needless extra typing, especially in VB.NET where you can put your mouse over just about anything and get detailed information on it by the intellisense.
 
I agree with the str, int, dbl thing for local variabes, it looks ugly
and more typing for nothing. But in the last project I did, there
were so many objects, sometimes they were passed to be used
locally and sometimes they were instanciated in the constructors,
it wouldve been very hard to follow if not for the m_ . Just my
opinion. :)
 
I typically use hungarian for all variables, and just prefix member variables with an underscore.

Code:
Dim strThing As String
Dim _intIndex As Integer

As long as youre consistent, it matters little what notation you use. Unless youre part of a collaboration of developers of course, in which case you should force your notation on every one else (in my case, hehe).
 
Back
Top