Archived

This topic is now archived and is closed to further replies.

johnnyBravo

Conventions in c++? eg capitals on methods etc

Recommended Posts

at college we are using java and my teacher said not to use capitals on methods. But on microsoft c++ examples etc they seem to use capitals on methods. So do i use capitals on the method or not for c++? eg void Calculate() or void calculate() ?

Share this post


Link to post
Share on other sites
It is completely up to you. Everyone has their own coding style, so there is no right or wrong way. Eventually after coding for a while you will pick up your own style.

Share this post


Link to post
Share on other sites
When coding independently feel free to use whatever coding conventions you like, as long as you are comfortable with it. The only time you may have to conform to a standard would be when working in a more formal environment, such as a company.

Share this post


Link to post
Share on other sites
Some decisions in software development are the kind of decisions where WHAT you decide is not nearly as important as the fact that you MAKE a definite decision. Coding style is one of these; the primary aim of a coding style is standardization. Readability and elegance are important, but secondary, concerns. Pick a code convention when you begin a project and stick to it throughout that project''s life. If you want suggestions, a google search for "C++ coding standard" will turn up quite a few results.


How appropriate. You fight like a cow.

Share this post


Link to post
Share on other sites
My style as an example



namespace MyProject { namespace SubNamespace
{

struct IMyInterface
{
};

class MyClass
{
private:
int m_instanceVar;
static int s_staticVar;

public:
void ClassMethod(int in_inputParamter, int & out_outputParameter)
{
int localVar;
}
};

// end of namspace
}}


During my study we are working with Java, which has e.g. the convention to make methods having small letters. I don't like that style as this makes local variables and methods look alike.

Regards,
VizOne


[edited by - VizOne on October 11, 2003 4:14:28 AM]

Share this post


Link to post
Share on other sites
Yep it''s the nearly standard way Viz. I don''t like m_ (looks MFC) but I apply it tho except for small classes like vectors(x,y,z) etc...

Share this post


Link to post
Share on other sites
MS C++ example most likely use hungarian notation which is just a code convention where you have to do things like put C on the front of classes (CPlayer) and you have to add letters to variable names to describe what the variable ie (i.e. m_iHealth would be an integer that is a member of a class). If you want to learn more about hungarian notation google it.

For what you should use just do whatever you're comfortable with though for your assignments it may be a good idea to use whatever your teacher likes.

[edited by - Monder on October 11, 2003 4:46:17 AM]

Share this post


Link to post
Share on other sites
quote:
Original post by Charles B
Yep it''s the nearly standard way Viz. I don''t like m_ (looks MFC) but I apply it tho except for small classes like vectors(x,y,z) etc...


Well, I use m_ to seperate instance variables from local ones. As local vars may shadow instance variables this is a source for nasty bugs.

What I really don''t like is hungarian notation. It is a relict from former times If the data type changes for a variable complete refactoring is neccessary (or inconsistency between name and type).

Besides m_, s_, in_, out_ and io_ I try to stick to the MS .NET convention (e.g. No class prefix like CMyClass)

Regards,
VizOne

Share this post


Link to post
Share on other sites
quote:
Original post by VizOne
Well, I use m_ to seperate instance variables from local ones.
...
What I really don''t like is hungarian notation. It is a relict from former times


So is the m_varName prefix. The proper OO way to indicate this is using ''this->varName''. m_ prefixes are just annoying and ugly.

Share this post


Link to post
Share on other sites