Results 1 to 10 of 10

Thread: What is your coding style ??

  1. #1
    Join Date
    Jan 2006
    Location
    Gloucester, UK
    Posts
    18
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default What is your coding style ??

    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
    Qt Code:
    1. {
    2. stuff ...
    3. {
    4. stuff...
    5. }
    6. }
    To copy to clipboard, switch view to plain text mode 

    I don't like this
    Qt Code:
    1. some code {
    2. stuff here }
    To copy to clipboard, switch view to plain text mode 

    I prefer m_variablename for member functions


    What about you?

  2. #2
    Join Date
    Mar 2006
    Location
    The Netherlands
    Posts
    300
    Thanks
    9
    Thanked 29 Times in 29 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: What is your coding style ??

    Qt Code:
    1. class ClassName {
    2. public:
    3. void publicFunctionName();
    4.  
    5. private:
    6. void _privateFunctionName();
    7.  
    8. int _privateVariableName;
    9. };
    10.  
    11. void ClassName::publicFunctionName() {
    12. int localVariableName;
    13.  
    14. if (true) {
    15. localVariableName = _privateVariableName + 1;
    16. }
    17. }
    To copy to clipboard, switch view to plain text mode 
    "The strength of a civilization is not measured by its ability to wage wars, but rather by its ability to prevent them." - Gene Roddenberry

  3. #3
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 975 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: What is your coding style ??

    Qt Code:
    1. class ClassName
    2. {
    3. public:
    4. void publicFunctionName();
    5.  
    6. private:
    7. void privateFunctionName();
    8.  
    9. int _privateVariableName;
    10. };
    11.  
    12. void ClassName::publicFunctionName()
    13. {
    14. int localVariableName;
    15.  
    16. if( true ) {
    17. localVariableName = _privateVariableName + 1;
    18. }
    19. }
    To copy to clipboard, switch view to plain text mode 

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,363
    Thanks
    3
    Thanked 5,012 Times in 4,791 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: What is your coding style ??

    Qt Code:
    1. #include <GlobalInclude>
    2. #include "localinclude"
    3. /**
    4.  * @class ClassName
    5.  * @brief Short class description
    6.  *
    7.  * Long class description
    8.  * Long class description line 2
    9.  */
    10. class ClassName{
    11. public:
    12. int publicFunctionName(int);
    13. inline int privateVariableName(){ return m_privateVariableName; }
    14. inline void setPrivateVariableName(const int &theValue){ m_privateVariableName = theValue; }
    15. private:
    16. void privateFunctionName();
    17. int m_privateVariableName; ///< short variable description
    18. int _otherStyleOfPrivateVariableName;
    19. };
    20.  
    21. /**
    22.  * @brief Short description
    23.  *
    24.  * Long description
    25.  *
    26.  * @param argName description of argument
    27.  * @return description of value returned
    28.  */
    29. int ClassName::publicFunctionName(int argName){
    30. int localVariableName;
    31. if( true ){
    32. localVariableName = _privateVariableName + 1;
    33. }
    34. return localVariableName;
    35. }
    To copy to clipboard, switch view to plain text mode 

    For C Linux Kernel code I prefer the lower_case_with_underscore_naming_convention

  5. #5
    Join Date
    Mar 2006
    Location
    The Netherlands
    Posts
    300
    Thanks
    9
    Thanked 29 Times in 29 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: What is your coding style ??

    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.
    "The strength of a civilization is not measured by its ability to wage wars, but rather by its ability to prevent them." - Gene Roddenberry

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 975 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: What is your coding style ??

    @wysota: You got it all wrong!

    Qt Code:
    1. #include "localinclude"
    2.  
    3. #include <QSomething>
    4.  
    5. /**
    6.  * Short class description. More description.
    7.  */
    8. class ClassName
    9. {
    10. public:
    11. int publicFunctionName( int argName );
    12. int privateVariableName() const;
    13. void setPrivateVariableName( int privateVariableName );
    14.  
    15. private:
    16. void privateFunctionName();
    17.  
    18. int _privateVariableName; ///< short variable description
    19. };
    20.  
    21. inline int ClassName::privateVariableName() const
    22. {
    23. return _privateVariableName;
    24. }
    25.  
    26. inline void ClassName::setPrivateVariableName( int privateVariableName )
    27. {
    28. _privateVariableName = privateVariableName;
    29. }
    30.  
    31. ...
    32.  
    33. /**
    34.  * Short description. More description.
    35.  *
    36.  * @param argName description of argument
    37.  * @returns some value
    38.  */
    39. int ClassName::publicFunctionName( int argName )
    40. {
    41. int localVariableName;
    42.  
    43. if( true ) {
    44. localVariableName = _privateVariableName + 1;
    45. }
    46.  
    47. return localVariableName;
    48. }
    To copy to clipboard, switch view to plain text mode 

    And something to read: http://hem.passagen.se/erinyq/industrial/
    Last edited by jacek; 26th May 2006 at 21:26.

  7. #7
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,363
    Thanks
    3
    Thanked 5,012 Times in 4,791 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: What is your coding style ??

    Quote Originally Posted by Michiel
    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?

  8. #8
    Join Date
    Jan 2006
    Location
    travelling
    Posts
    1,116
    Thanks
    8
    Thanked 127 Times in 121 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: What is your coding style ??

    Qt Code:
    1. /*
    2. Copyright notice
    3. */
    4.  
    5. #include <QtCore>
    6.  
    7. #include "localstuff.h"
    8.  
    9. class MyClass : public SomeBaseClass
    10.  
    11. {
    12. public:
    13. MyClass();
    14. ~MyClass();
    15.  
    16. void someFunction();
    17.  
    18. private:
    19. int iVariable;
    20. bool bVariable;
    21. QString sName;
    22. MyManager *pManager;
    23. };
    To copy to clipboard, switch view to plain text mode 
    This looks good for an header, huh?
    Last edited by fullmetalcoder; 29th May 2006 at 09:14. Reason: damn it! indenting have to be done by hand inside code tag!!!
    Current Qt projects : QCodeEdit, RotiDeCode

  9. #9
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,363
    Thanks
    3
    Thanked 5,012 Times in 4,791 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: What is your coding style ??

    Qt Code:
    1. private:
    To copy to clipboard, switch view to plain text mode 

  10. #10
    Join Date
    Jan 2006
    Location
    travelling
    Posts
    1,116
    Thanks
    8
    Thanked 127 Times in 121 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: What is your coding style ??

    Yep that would be ugly for sure but hopefully I rarely use QAbstractTextDocumentLayout, even less in an header, and in such case :
    Qt Code:
    1. private:
    To copy to clipboard, switch view to plain text mode 
    Current Qt projects : QCodeEdit, RotiDeCode

Similar Threads

  1. Current KDE/Windows style
    By donmorr in forum Qt Tools
    Replies: 1
    Last Post: 19th May 2006, 17:49
  2. Is there any cool style for windows?
    By SkripT in forum Qt Programming
    Replies: 7
    Last Post: 31st March 2006, 12:51
  3. QToolBox and style
    By Maxilys in forum KDE Forum
    Replies: 6
    Last Post: 26th March 2006, 15:07
  4. Bugs, style changes in 4.1.0?
    By simk in forum Qt Programming
    Replies: 13
    Last Post: 13th February 2006, 11:05
  5. Qt style...
    By Sergey B. in forum Qt Programming
    Replies: 10
    Last Post: 21st January 2006, 22:48

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.