Built-in code style is not compatible to the Qt style guide



  • Hi there

    I'm wondering why the built-in code style in Qt-Creator is not like the one from Coding Guidelines.
    http://doc.qt.nokia.com/qtcreator-extending/coding-style.html

    I'm curious why the Qt Code Guideline is using the K&R style which was invented when people used to program with vt100 terminals.

    I'm more fan of the Allman style but since this violates the Qt Coding Guideline I try to switch to the K&R.
    http://en.wikipedia.org/wiki/Indent_style

    But as I mentioned in the beginning, why is the Qt built-in code style set to Allmann instead of K&R?
    It looks a little bit inconsistent.

    Best regards

    messi


  • Moderators

    I fail to see the problem:-)



  • Tobias Hunger
    I know this post sounds a little bit picky but it is not qt coding rules conform.

    This is in the Qt Creator Coding Rules:
    Braces

    As a base rule, place the left curly brace on the same line as the start of the statement:

    @if (codec) {
    ....
    }@

    NOT

    @ if (codec)
    {
    ....
    }@

    This is the built-in code style of the qt-creator:

    @void foo(int a, int b)
    {
    for (int i = 0; i < a; i++)
    {
    if (i < b)
    bar(i);
    else
    {
    bar(i);
    bar(b);
    }
    }
    }@


  • Moderators

    I never noticed that! My code looks just fine with the default settings in creator, so where does this effect you?



  • Actually it is not effecting me.
    But to be consistent in the rules of the build-it text under QtCrator -> Options -> C++ -> CodeStyle should like:

    @ for (int i = 0; i < a; i++) {
    if (i < b) {
    bar(i);
    } else {
    bar(i);
    bar(b);
    }
    }@

    and not like:

    @ for (int i = 0; i < a; i++)
    {
    if (i < b)
    bar(i);
    else
    {
    bar(i);
    bar(b);
    }
    }@

    Which is think is more readable then the first version.


  • Moderators

    I don't think this is too important: Why should an IDE enforce the coding style used to program itself on unrelated projects?



  • Then would be the question, how many people use qt-creator to program qt related stuff?


  • Moderators

    Note that the Qt Creator styleguide and the Qt styleguide do differ. So does the KDE style guide... and lots of other projects style guides, too.

    Anyway: I had not even noticed that the style displayed there differs and I use Creator rather regularly to code following the Qt Creator style guide, so I don't think this is an issue.



  • Sorry to say that but qt style guide and qt creator style guide are equal in that particular case.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.