Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you name member variables in VB.NET?

I am generally not one to engage in subjective arguments over matters like variable naming, code formatting, etc. So I have no intention of starting an argument here.

I just came across this (old) blog post which recommends not prefixing member variable names:

Do not use a prefix for member variables (_, m_, s_, etc.). If you want to distinguish between local and member variables you should use "this." in C# and "Me." in VB.NET.

For C#, yeah, I get it: member variables can be lower camelCase, and public properties/methods can be PascalCase. But VB.NET is case-insensitive, so you can't really give a private member the same name as a public property except with a lower case first letter.

I've generally prefixed member variables with an underscore, but I've been told that's not idiomatic.

So really I'm just curious: how do you name your member variables in VB.NET? And is there a "standard" way?

I'm not asking because I believe there's a "right" way or because I particularly want to change my style, and certainly not because I have any desire to tell others they're "wrong." Like I said, I'm just curious.

like image 775
Dan Tao Avatar asked Jun 09 '10 13:06

Dan Tao


People also ask

How do you name variables in Visual Basic?

Naming VariablesEdit Variable names in Visual Basic are made up of letters (upper and lower case) and digits. The underscore character, "_", is also permitted. Names must not begin with a digit. Names can be as long as you like.

What are the rules of variable name in VB?

Use the following rules when you name procedures, constants, variables, and arguments in a Visual Basic module: You must use a letter as the first character. You can't use a space, period (.), exclamation mark (!), or the characters @, &, $, # in the name. Name can't exceed 255 characters in length.


2 Answers

It's personal preference, although there's widespread support for having some distinction. Even in C# I don't think there's one widely used convention.

Jeff Prosise says

As a matter of personal preference I typically prefix private fields with an underscore [in C#] ... This convention is used quite a lot in the .NET framework but it is not used throughout.

From the .NET Framework Design Guidelines 2nd Edition page 73.

Jeffrey Richter says

I make all my fields private and I prefix my instance fields with "m_" and my static fields with "s_" [in C#]

From the .NET Framework Design Guidelines 2nd Edition page 47. Anthony Moore (BCL team) also thinks using "m_" and "s_" is worth consideration, page 48.

like image 106
MarkJ Avatar answered Oct 05 '22 09:10

MarkJ


I personally use m_ for member variables.

Although with automatic properties in VS 2010 I haven't needed to for any new code I've written recently.

like image 43
Justin Wignall Avatar answered Oct 05 '22 07:10

Justin Wignall