PDA

View Full Version : What is your coding style ??



guestgulkan
26th May 2006, 20:13
For example how do you name your functions
like this myFunctionName as in QT ?
i'm not the world's best typist so i prefer lowercase and underscores function_name

I prefer to layout my braces like this

{
stuff ...
{
stuff...
}
}

I don't like this

some code {
stuff here }

I prefer m_variablename for member functions


What about you?

Michiel
26th May 2006, 20:23
class ClassName {
public:
void publicFunctionName();

private:
void _privateFunctionName();

int _privateVariableName;
};

void ClassName::publicFunctionName() {
int localVariableName;

if (true) {
localVariableName = _privateVariableName + 1;
}
}

jacek
26th May 2006, 20:31
class ClassName
{
public:
void publicFunctionName();

private:
void privateFunctionName();

int _privateVariableName;
};

void ClassName::publicFunctionName()
{
int localVariableName;

if( true ) {
localVariableName = _privateVariableName + 1;
}
}

wysota
26th May 2006, 20:53
#include <GlobalInclude>
#include "localinclude"
/**
* @class ClassName
* @brief Short class description
*
* Long class description
* Long class description line 2
*/
class ClassName{
public:
int publicFunctionName(int);
inline int privateVariableName(){ return m_privateVariableName; }
inline void setPrivateVariableName(const int &theValue){ m_privateVariableName = theValue; }
private:
void privateFunctionName();
int m_privateVariableName; ///< short variable description
int _otherStyleOfPrivateVariableName;
};

/**
* @brief Short description
*
* Long description
*
* @param argName description of argument
* @return description of value returned
*/
int ClassName::publicFunctionName(int argName){
int localVariableName;
if( true ){
localVariableName = _privateVariableName + 1;
}
return localVariableName;
}

For C Linux Kernel code I prefer the lower_case_with_underscore_naming_convention

Michiel
26th May 2006, 21:00
For big projects, I also use JUnit-style documentation.

What sort of stuff do you put in the global include? I've never needed to include anything into every file.

jacek
26th May 2006, 21:07
@wysota: You got it all wrong! ;)


#include "localinclude"

#include <QSomething>

/**
* Short class description. More description.
*/
class ClassName
{
public:
int publicFunctionName( int argName );
int privateVariableName() const;
void setPrivateVariableName( int privateVariableName );

private:
void privateFunctionName();

int _privateVariableName; ///< short variable description
};

inline int ClassName::privateVariableName() const
{
return _privateVariableName;
}

inline void ClassName::setPrivateVariableName( int privateVariableName )
{
_privateVariableName = privateVariableName;
}

...

/**
* Short description. More description.
*
* @param argName description of argument
* @returns some value
*/
int ClassName::publicFunctionName( int argName )
{
int localVariableName;

if( true ) {
localVariableName = _privateVariableName + 1;
}

return localVariableName;
}

And something to read: http://hem.passagen.se/erinyq/industrial/

wysota
27th May 2006, 01:23
What sort of stuff do you put in the global include? I've never needed to include anything into every file.

"Global includes" are system-wide header files, like <iostream>, <QApplication>, etc. whereas "local includes" are files internal to the project.

@jacek: did I? :)

fullmetalcoder
29th May 2006, 09:12
/*
Copyright notice
*/

#include <QtCore>

#include "localstuff.h"

class MyClass : public SomeBaseClass

{
public:
MyClass();
~MyClass();

void someFunction();

private:
int iVariable;
bool bVariable;
QString sName;
MyManager *pManager;
};


This looks good for an header, huh?

wysota
29th May 2006, 09:16
private:
QAbstractTextDocumentLayout qatdlVariable;
;)

fullmetalcoder
29th May 2006, 09:22
:D Yep that would be ugly for sure but hopefully I rarely use QAbstractTextDocumentLayout, even less in an header, and in such case :


private:
QAbstractTextDocumentLayout docLayout;