views:

164

answers:

8

what is the best way to declare variable names.... in uppercase ...? .. lowercase? in which area must be declared in any case ... and what name is appropriate depending on the roll of the standard variable ... there are some variables to declare?...sorry for the question..I'm new to the world of programming ... I hope not bother .... =)

+3  A: 

Well here are some links for the coding standards for various languages..
This has standards for variable naming and a lot more.

C# coding standards
C++ coding standards
Java coding standards

And here is generic coding standards article that explains the reasoning behind the coding standards.

Binoj Antony
+1  A: 

Atleast for C and C++ we can use Hungarian notation

Alphaneo
And we should read this question answers before doing that http://stackoverflow.com/questions/111933/why-shouldnt-i-use-hungarian-notation
sharptooth
There are good arguments for and against Hungarian notation (both types). Things to take into consideration include: the IDE you use and the language you're programming in. But ultimately, it falls to personal preference and the particular situation in question.
Calvin
+1  A: 

If:

  • the language doesn't dictate it; and
  • your coding standards don't dictate it,

then just make it as readable as possible. Hordes of developers in the future will sing praises to your name for not inflicting horrible code on them.

My personal favorite is all uppercase and underscores for constants (IQ_LIMIT) and camel case for everything else (getItembyId(), itemCount). But that's personal preference, not something written on stone tablets.

paxdiablo
+1  A: 

It really depends on the programming language you use, and any coding conventions that are followed by a group.

For example, there is the GNU coding standards for writing C code which covers variable names down to the indentation of lines.

For languages, the Code Conventions for the Java Programming Language lays out some coding conventions for capitalization and naming of variables, packages, classes, methods, etc in the Java programming language.

coobird
+1  A: 

When in Rome, do as the Romans. Each language usually has its own idioms with respect to these sorts of things.

Rob Scott
A: 

IMO, knowing the scope of a variable is the most important thing. You should know at a glance how much code can effect a variable and how much code will be effected by your changing it. In this way encapsulation (and your sanity) can be maintained. You won't accidentally change a global variable and mysteriously hose the whole program. Also they should stand out like a sore thumb just begging to be refactored away.

Therefore upper-case the first letter for globals (where "global" is any variable that can be seen by more than one function) and lower-case the first letter for every else. Constants traditionally get all caps.

So in studlyCaps style it would be:

  • GlobalVariable
  • localVariable
  • CONSTANTVARIABLE

And using under scores:

  • Global_Variable
  • local_variable
  • CONSTANT_VARIABLE

Whether you use studlyCaps or under scores depends on your programming language and local style (I prefer under scores for their readability and no confusion about capitalization).

Schwern
A: 

In C#, we use PascalCase for properties and methodnames and camelCase for other members. For constants we use CAPS_WITH_UNDERSCORE. For the html elements hungarian notation is used. (I think these are Microsoft standards.)

Rashmi Pandit
A: 

A corollary to "When in Rome..." is to do as the previous coder has done. When you are working on another developers code or project, you should match your style to the existing style. While seeing a weird convention is puzzling and hard to deal with at first, it is nothing compared to sorting out a file that switches notation and style every couple of functions.

When working on your own project, or as a single developer you can do what is most comfortable within reason.

Gary.Ray