|
-
Feb 6th, 2004, 04:26 AM
#1
Coding standards and naming conventions?
The more and more of .NET code I see I am beginning to wonder if people have scrapped naming conventions...
Do .NET coders still use obj, str, bln etc?
Also. In VB6:
VB Code:
Dim objWoof As New Object
The above can be done, but is frowned upon by some users. The following is how it's supposed to be done "correctly"
VB Code:
Dim objWoof As Object
'Blah blah blah
Set objWoof = New Object
Is this the case for .NET coz all code I have seen uses the Dim As New method...????
Any advantage in .NET of doing this?
Woka
-
Feb 6th, 2004, 04:41 AM
#2
Hungarian notation is dead in .NET - and nobody cried at the funeral.
Because there are so many type of thing and because everything is derived from an object you need to include the name of the object in the variable name - except for things like integers where that makes sense.
e.g.
VB Code:
Dim HeadOfficePrinterCollection As New PrinterCollection
Check out the FxCop application which you can download from Microsoft (MSDN) - It reports on your coding style and allows you to add/modify the rules for your own corporate standards. We use it a lot....
-
Feb 6th, 2004, 09:52 AM
#3
There is not really an advantage to Dim x As New in .NET other than it takes one less line, but there is also no perference hit like in VB6. So it is now fine to use New in the initialization line.
PascalCase has pretty much replaced Hungarian (thank God) or whatever in house rules you have.
PascalCase using CapitalLettersForMultipleWordsWithoutASpace. The following topics in the help explain more about naming 'Visual Basic Naming Conventions' and 'Coding Techniques'. They also suggest event naming conventions like Loading, Loaded and so on.
-
Feb 6th, 2004, 09:57 AM
#4
How would you do:
VB Code:
Private mstrConnString As String
Public Property ConnectionString() As String
Get
Return mstrConnString
End Get
Set(ByVal Value As String)
mstrConnString = Value
End Set
End Property
using correct naming convention.
Woka
-
Feb 6th, 2004, 10:29 AM
#5
Different people have different conventions for private variables I use the underscore _ but some use m_ or something else.
VB Code:
'I would use
Private _ConnectionString As String
Public Property ConnectionString() As String
Get
Return _ConnectionString
End Get
Set(ByVal Value As String)
_ConnectionString = Value
End Set
End Property
Here is some more information and a link to the sample Merrion mentioned:
http://www.irritatedvowel.com/Progra...Standards.aspx
Last edited by Edneeis; Feb 6th, 2004 at 10:32 AM.
-
Feb 6th, 2004, 10:44 AM
#6
bad underscore *slap*
I have just been critisised for my naming conventions for VB6 at work 
I did:
VB Code:
Private mlngUsername As String
Public Sub SetUsername(ByVal pstrUsername As String)
Dim strTemp As String
Dim strURL As String
On Error Goto ErrHandler
'Code here
ErrHandler:
'Err code
End Sub
This apparently should be:
VB Code:
Private m_lUsername As String
Public Sub SetUsername(ByVal sUsername As String)
Dim sTemp As String
Dim sURL As String
On Error Goto ErrHandler
'Code here
ErrHandler:
'Err code
End Sub
Not a happy sniffing shark 
Woka
-
Feb 6th, 2004, 11:52 AM
#7
Frenzied Member
I like your first way better. Either way, it's helpful to have a common standard when you have to work with other people's code.
I don't like the underscore because it looks too much like the line continuation character, and the second way leads to confusing names (lpszVar, and such).
-
Feb 6th, 2004, 12:21 PM
#8
Naming standards should be set by company and you really should have a manual/info document describing them. You cant be crisitsed if your not told .
Ive carried on with the Hungarian naming as I like it.
-
Feb 6th, 2004, 12:45 PM
#9
Originally posted by Wokawidget
bad underscore *slap*
I have just been critisised for my naming conventions for VB6 at work 
I did:
VB Code:
Private mlngUsername As String
Public Sub SetUsername(ByVal pstrUsername As String)
Dim strTemp As String
Dim strURL As String
On Error Goto ErrHandler
'Code here
ErrHandler:
'Err code
End Sub
This apparently should be:
VB Code:
Private m_lUsername As String
Public Sub SetUsername(ByVal sUsername As String)
Dim sTemp As String
Dim sURL As String
On Error Goto ErrHandler
'Code here
ErrHandler:
'Err code
End Sub
Not a happy sniffing shark 
Woka
And even then, that's bogus Woka...
If I saw, m_lUsername, I'd think it was a long int.... and not a string...

Originally posted by salvelinus
I like your first way better. Either way, it's helpful to have a common standard when you have to work with other people's code.
I don't like the underscore because it looks too much like the line continuation character, and the second way leads to confusing names (lpszVar, and such).
what's wrong with lpszVar? I can tell instantly what it is: a Long Pointer to a String Variable???? where the confusion?
TG
-
Feb 6th, 2004, 01:21 PM
#10
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|