473,383 Members | 1,853 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,383 software developers and data experts.

What's the correct variable naming methodology?

VM
What's the correct variable naming in C#? How should a form be called (eg.
Frm_myForm)? or an int variable (eg. Int_Var) or a DataGrig (eg. DG_myGrid)?
I'm writing an application but I would like to name variables, objects,
etc... corectly so everyone knows what the variable is and what it holds
when they look at it and make the code easier to read.
Thanks.
Nov 15 '05 #1
4 4407

"VM" <None> wrote in message
news:e7**************@tk2msftngp13.phx.gbl...
What's the correct variable naming in C#? How should a form be called (eg. Frm_myForm)? or an int variable (eg. Int_Var) or a DataGrig (eg. DG_myGrid)? I'm writing an application but I would like to name variables, objects, etc... corectly so everyone knows what the variable is and what it holds when they look at it and make the code easier to read.
Thanks.


Please follow this MSDN guide to naming conventions:
http://tinyurl.com/2cun [MSDN]

Note that this applies to externally visible members
like Method names, Properties, etc.

Internally, you can use whatever you want, but remember
that maintainability is a big part of software
development and I strongly urge you, and I know
this will spawn flaming, not to use Hungarian Notation
since there are maintainability issues with it.
It's best not to specify the type of object in the
variable name. For Windows controls, there's some
grey area. txtUserName or userNameTextBox are
usually good, but for every string doing things like
strUserName or pobjsysstrUserName or anything
crazy like that.

Also, every reference in .NET is essentially
a pointer to an Object-based class, so labelling
it pobj is pointless and redundant. Please think
of us maintenance programmers before you do
something like that :) (I just got off a contract
where they labelled everything with obj******
and it drove me nuts)

-c
Nov 15 '05 #2
You might read this:

Hungarian notation specifies that a prefix be added to each variable to
indicate its type. However, not every type was given a standard prefix. In
addition, as other languages were introduced and new types created, new
prefixes had to be created. This is why even if you go into a shop that
employs Hungarian notation, you might see some prefixes you're not
accustomed to seeing. (By the way, the term "Hungarian notation" comes from
the fact that the prefixes make the variables look as if they are written in
a language other than English; plus, Mr. Simonyi is from Hungary.)
Perhaps the most important publication that encouraged the use of Hungarian
notation was the first book read by almost every Windows and OS/2 developer:
Charles Petzold's Programming Windows (Microsoft Press), which used a
dialect of Hungarian notation throughout its demo applications. In addition,
Microsoft employed the notation in its own development. When MFC was
released, a bunch of new prefixes specific to C++ development were released
with its source code, thereby guaranteeing the continued use of Hungarian
notation.
So why not simply continue using Hungarian notation? Because Hungarian
notation is useful in situations where it's beneficial to know the type, or
scope, of a variable being used. However, as you'll see in more detail in
the next chapter, all types in C# are objects and based on the .NET
System.Object class. Therefore, all variables have a basic set of
functionality and behavioral characteristics. For this reason, the need for
Hungarian notation is lessened in the .NET environment.

I would however not agree with the last sentence in the last paragraph. I
believe it is still very useful to know a variables type even if it does
inherit from the base Object type.

HTH
Steve

"VM" <None> wrote in message news:e7**************@tk2msftngp13.phx.gbl...
What's the correct variable naming in C#? How should a form be called (eg.
Frm_myForm)? or an int variable (eg. Int_Var) or a DataGrig (eg. DG_myGrid)? I'm writing an application but I would like to name variables, objects,
etc... corectly so everyone knows what the variable is and what it holds
when they look at it and make the code easier to read.
Thanks.

Nov 15 '05 #3
>
Not to mention the (IMO) stupid 'tbl' prefix om SQL Server tables. I can't
stand that - they're all tables, get it?


tbl is too much, but "t" is justified.

There is other objects like "v" and "f" which could look the same looking at
T_SQL.

And here is example:

tCustomer would contain data about customer only

And
view vCustomer would contain Data with foreign keys looked up.
Nov 15 '05 #4

"Anders Borum" <na@na.na> wrote in message
news:eO**************@TK2MSFTNGP09.phx.gbl...

<snip: Hungarian Notation>
Not to mention the (IMO) stupid 'tbl' prefix om SQL Server tables. I can't stand that - they're all tables, get it?

(stepping down from the soap box)


JOOC, how do you name user objects in SQL?

I would say that objects in SQL are slightly
different than variables in code. In T-SQL,
it can be difficult to distingush, say,
between a stored proc and view.

What would you recommend?

-c
Nov 15 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: F. Da Costa | last post by:
Hi, Could it be correct that the following code does *not* work because i'm not using the var arr = new Array("a","b","c"); methodology?? Read through...
5
by: Bill Willyerd | last post by:
I have been looking for some documentation that would support or reject my opinion on Production -vs- Development naming conventions. I believe that each environment should be housed on separate...
7
by: Newbie_sw2003 | last post by:
Where should I use them? I am giving you my understandings. Please correct me if I am wrong: MACRO: e.g.:#define ref-name 99 The code is substituted by the MACRO ref-name. So no overhead....
12
by: Chad Z. Hower aka Kudzu | last post by:
Object MyOnject = new Object; What does the signify? -- Chad Z. Hower (a.k.a. Kudzu) - http://www.hower.org/Kudzu/ "Programming is an art form that fights back"
6
by: Mark Broadbent | last post by:
this might sound like an obvious question but I have found that usually these two evolve at the same time. One of the biggest reasons for creating the abstraction in the first place (in my...
5
by: Amelyan | last post by:
I am struggling here trying to determine what is a good programming practice as far as referencing your URLs. When you use Response.Redirect, do you use 1) Hard-coded string --...
4
by: **Developer** | last post by:
I looked at MSDN and a book and both described the naming convention for parameters should be camel style. The book used camel, except for Set (ByVal Value as ...) There it always used an...
14
by: rsine | last post by:
I did a recent post about what the standard was for naming a string builder object. My concern was that I did not what to use "str" prefix since this is used for strings but did not know what to...
12
by: Ant Grinyer | last post by:
Having worked in software development for over 15 years in many organisations using different development methodologies such as waterfall, RUP, Scrum and XP, I'm still not sure if there is a...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.