Hi,
I have some thoughs about “Qt coding standardsâ€. I've seen various standards, for example this link http://www.possibility.com/Cpp/CppCodingStandard.html and then code the Trolls wrote.
I'm wondering about naming conventions of members for example:
{
..
public:
void doSomeAction
(QString aAction
);
Q_SIGNALS:
void signalChanged(int);
void stateChanged(int);
private:
..
}
void JumpaWidget
::doSomeAction(QString aTodo
) {
..
if(aTodo == "Jump")
{
setState("Confused");
m_Error = "How high";
}
..
}
class JumpaWidget : public QWidget
{
..
public:
QString m_PublicMember;
void setState(QString state);
QString getState();
void doSomeAction(QString aAction);
Q_SIGNALS:
void signalChanged(int);
void stateChanged(int);
private:
..
QString mState;
QString mError;
QString* mpString;
}
void JumpaWidget::doSomeAction(QString aTodo)
{
..
if(aTodo == "Jump")
{
setState("Confused");
m_Error = "How high";
}
..
}
To copy to clipboard, switch view to plain text mode
The getter and setter methods (setXXXX and getXXXX) are fine and nice since code completion helps me and I know I want to set some variable/state in the class.
Attributes? sError, msError, m_ErrorString; If it were two error variables I would say m_ErrorCode and m_ErrorString for example.
Is it really important to ‘encode’ the variable type into the name? My guess is not really since we have type checking. But one should consider readability for the next person.
Indent/braces: Then when it comes to placing the braces:
if(foo){
bar();
}
if(foo){
bar();
}
To copy to clipboard, switch view to plain text mode
or
if(foo)
{
bar();
}
if(foo)
{
bar();
}
To copy to clipboard, switch view to plain text mode
I personally prefer the 2nd one since the code is (arugably) more readable, easier to scan "blocks" of code.
Please provide some feedback or give me some example of your 'correct' coding standard. I know that each person/organization has a personal touch but there are some 'best practice' conventions out there. I'm especially interested in the Qt world's coding habits.
Bookmarks