Common notation

Started by
39 comments, last by SiCrane 18 years, 3 months ago
Hey :) I was wandering, is there any commonly accepted notation? Like, for example, typing class names all in caps. I've been notating classes like "_blah" most of the time, though I don't have any special way of notating functions and variables. Should I get more habits like that? And what would be the most commonly accepted ways for notating classes/functions/variables/(somethin else?)? EDIT: Yes, I am using C++ :)
Advertisement
Assuming C++, then prefixing your class names with an underscore is big bad mojo. Identifiers with leading underscores are reserved in the global scope and with leading underscores followed by capital letters are reserved in any scope, so you can get many weird problems with your class names if you use that practice.
I write my variables with the first word lowercase and the first letter of the following words in uppercase, for example:
sampleVarName

For functions and custom data types, I capitalize the first word as well:
CustomClassName

Thats what I do, whats most important is consistancy, whatever you do, do it the same way throughout a project.
"Are you threatening me, Master Jedi?" - Chancellor Palpatine
there are many notations that are "common" ...

they are almost completely specific to which language / domain you are programming in.

The Java world has a fairly standard notation, direct from the Sun example.

The .NET (especially in C#) world has a common style / notation, with only a few areas left open for the programmer to decide on their own ... you can go to the msdn.microsoft.com website and look for programming and style guidelines for .net (google is easier).

In C++ there are probably 3-4 main competing styles depending on domain (Old windows MFC programmers, UNIX / LINUX programmers, part-time Java programmers, .NET programmers, and people like me (who come up with their own mix-match style to meet their own guidlines for consistency).

These last 2-4 years have seen a lareg convergence of styles in C derived languages (C++, C#, Java) ... so that I would say the most commonly agreed upon thing is that people usually use:

PascalCase for things like class names. And the people who do this also use PascalCase for namespaces too. Functions are usually done in either camelCase or PascalCase by these people (they don't all agree on which to use), and variable names are almost always done in camelCase, sometimes with things like m_ added to the front of member variables, or a trailing _ appended.

As mentioned already, DO NOT start any non-members with an underscore, it just makes life easier (some people do start member variables with an underscore ... which is ok).

Then there are the people who follow the C++ standard example, and use lower_case_with_underscores for just about everything ...
Quote:Original post by Xai
As mentioned already, DO NOT start any non-members with an underscore, it just makes life easier (some people do start member variables with an underscore ... which is ok).

Underscore followed by a capital letter is not ok, even for member variables.
How I roll:

classes and functions:
ThisIsAClass

member variables:
thisIsAMemberVariable

defines:
THISISDEFINED

brackets:
(on my own I do this because I like it more)
function{
}
(however at work and in larger groups I conform to this standard)
function
{
}

comments:

Section heading comments
/*********************************\
| major comments appear like this |
\*********************************/

function description blocks
//Just simple
//one-line
//comments

I refrain from multi-line comments wherever they are not necissary because they can screw up attempts to comment out code blocks which gets annoying in some cases.


Tabs: I use 3 spaces in my own projects, but at work and in groups I use a standard 4 space tab character.
_____________________


Anyhow, nothing revolutionary, basically keep things smooth and consistant and whatever style it is probably won't offend me.
_______________________"You're using a screwdriver to nail some glue to a ming vase. " -ToohrVyk
Thanks guys :D
Ahh, and I would never have guessed that underscores could be that evil. I'll start writing classes in all caps from now on. Functions LikeThis look nice and variables likeThis too, so I'll try getting into using them.
Oh, and I have always used functions like this
function {
}

function
{
}
looks rather ugly to me.

Rating++ to all :D, if anyone else has something to contribute, please do.
Quote:Original post by ZadrraS
I'll start writing classes in all caps from now on.


I wouldn't, if I were you. One of the most common conventions among C and C++ programmers is to use all caps for constants and macros.
I'm just a beginner programmer but I tend to prefix all my classes, functions and variables for easy identifying with either C, F or V

e.g.

CThisIsMyClass

FThisIsMyFunction

I tend to write variables like this

Vthisismyvariable

I don't know if this is good or bad but it is helping me learn, not sure what others would think though.
Mordt: I'm just a beginner C++ programmer so take my advice with a grain of salt.Krayven Entertainment
FWIW, here's my style:

don't use "C" in front of the class' name, because it makes the names ugly. use as few comments as possible, name as well as possible.bool dont_fear_long_variable_names = true;variables are in lowercase, separated with an underscore _ if they are localmember variables have 'its' before them: itsstylestatic variables have 'static_' in before their namesglobal variables SHOULD BE FEW and clearly be flagged. all DATA should be WELL DOCUMENTED as well as CLEARLY named (can't stress this enough)value-like types are named all_lowerscore.'complex' types which have special construction/destruction semantics, are NamedLikeSo.private/protected member functions begin lowercase and the first letters of following words are uppercasepublic/global functions are NamedLikeThisglobal and static constants are ALL_UPPERCASEintend carefully, and use braces {} for all loops and if-conditions

This topic is closed to new replies.

Advertisement