Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

I'm 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 don't 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 I'm putting anyone from this forum down. :)

Gamer extraordinaire. Programmer wannabe.
Posted

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 you're naming).

Gamer extraordinaire. Programmer wannabe.
  • *Experts*
Posted

I personally always use hungarian notation for controls (makes it

easier to tell what control is what type), and camelCase for variables.

  • Leaders
Posted
I don't use Hungarian notation, but I won't lose any sleep over using Hungarian notation. I've never heard of this camelCase & PascalCase, so I probably don't use it... I like my variables short and descriptive. :)

Iceplug, USN

One of my coworkers thinks that I believe that drawing bullets is the most efficient way of drawing bullets. Whatever!!! :-(

  • Moderators
Posted

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.

Visit...Bassic Software
  • *Experts*
Posted

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?

"Being grown up isn't half as fun as growing up

These are the best days of our lives"

-The Ataris, In This Diary

Posted

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.

Gamer extraordinaire. Programmer wannabe.
  • *Experts*
Posted

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 I'm not sure if

this holds true in VB.NET.

"Being grown up isn't half as fun as growing up

These are the best days of our lives"

-The Ataris, In This Diary

Posted
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 ;)
Gamer extraordinaire. Programmer wannabe.
  • Leaders
Posted

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 don't 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.

Iceplug, USN

One of my coworkers thinks that I believe that drawing bullets is the most efficient way of drawing bullets. Whatever!!! :-(

  • Moderators
Posted

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.

Visit...Bassic Software
Posted

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 isn't that considered Hungarian notation as well?).. I can't 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.

Gamer extraordinaire. Programmer wannabe.
  • Moderators
Posted

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 would've been very hard to follow if not for the m_ . Just my

opinion. :)

Visit...Bassic Software
  • *Gurus*
Posted

I typically use hungarian for all variables, and just prefix member variables with an underscore.

 

Dim strThing As String
Dim _intIndex As Integer

 

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

MVP, Visual Developer - .NET

 

Now you see why evil will always triumph - because good is dumb.

 

My free .NET Windows Forms Controls and Articles

  • Leaders
Posted

Actually, the 3 letter prefix is a modern isation of Hungarian notation, which originally defined single character prefixes. The change came about as the range of object and control types grew. There are only 26 letters in the Alphabet after all. I use the original single character notation for variables but the modern 3 character one for controls.

 

I personally hate using underscores in code. I just find them really awkward to type quickly. For member variables I just prefix "m". So a private string variable becomes:

 

msVariableName

Those who live by the sword get shot by those who don't!
  • *Gurus*
Posted

I use single-letter prefixes for common types:

 

iInteger

sString

pIntPtr

 

and double-letter prefixes for structures, classes and uncommon types:

 

scMain (instance of Subclass)

dtTime (instance of DateTime class)

 

I mean come on... do you really need 3 letters?

Posted

Well, I can accept different coding styles and naming conventions. I just personally hate Hungarian. :p

 

Anyway, my rant was more or less towards the usage of legacy VB6 compatability namespaces to use methods such as UBound() etc. To make it worse, the namespace is imported by default. *mumbles* I so need to write a little add-on that automatically sets Option Strict to On and removes the import to Microsoft.VisualBasic when you create a new application.

 

I probably should of worded my original post better, but when some of you actually said you still use Hungarian for certain things (or a minor form of it) it just came as a shock to me. I still refuse to believe.. :D

Gamer extraordinaire. Programmer wannabe.
  • *Gurus*
Posted

While I agree with you on the Microsoft.VisualBasic issue for the most part, it needs to be said that some of the functions located there are fine to use. That's not to say that many of them are fine to use however. Functions such as FileOpen, Val and StrReverse should just be shot though. Also, while you can remove the Imports Microsoft.VisualBasic statement, that assembly will still need to be referenced nomatter what. The compiler will re-reference it for you if you remove it.

 

Option Strict: Absolutely. Turn it on, no excuses.

Imports MS.VB: Use with partial prejudice.

Posted

Posted this in the wrong thread yesterday.. LOL. Anyway..

 

Funny enough I was browsing through gotdotnet.com forums and came upon these links from the MSDN library;

 

Main Link:

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

 

Naming Guideline Links:

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

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

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

 

I know they're guidelines etc and of course everyone has their own set of guidelines in the work place. I just figured since we were talking about it so much some of you might find these links interesting at the very least.

Gamer extraordinaire. Programmer wannabe.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...