Skip to content

Clang format#34

Open
cosunae wants to merge 3 commits intomasterfrom
clang-format
Open

Clang format#34
cosunae wants to merge 3 commits intomasterfrom
clang-format

Conversation

@cosunae
Copy link

@cosunae cosunae commented Jan 28, 2016

I think we need a common formatting as there is different people contributing to this project.
So I am adding this PR with the hope that you like the idea of using clang-format.
I find it quite convenient because it can be used from almost any editor, IDE, and it has tons of configuration possibilities. Me personally I dont mind which style, as far as we have a common one.

It only solves the problem for C++, but that is already a big chunk of code here.

We can integrate in our editors/IDEs and/or
http://clang.llvm.org/docs/ClangFormat.html

andyspiros and others added 3 commits January 26, 2016 15:53
Merging the changes of the last few weeks for release `0.1`.
bring boost bugfix from meteoswiss-apn
@pspoerri
Copy link

How do we use it?

@cosunae
Copy link
Author

cosunae commented Jan 28, 2016

With Qt creator you have to install the beautifier.
You only need to activate the beautifier and have this .clang-format in the root directory together with the CMakeLists.txt, where I put the file.
You can configure the keyboard shortcut to trigger the format of a file or selected section.

http://doc.qt.io/qtcreator/creator-beautifier.html

With vim, emacs there are instructions in the link I posted above.

@cosunae
Copy link
Author

cosunae commented Jan 28, 2016

you can also use it in a script fashion.
clang provides a clang-format binary that returns the formatted text according to the conf provided

@pspoerri
Copy link

Ah, great! I got it to run.

Can we have:

  • Braces around for loops. This should prevent bugs where incorrectly indented lines can be mistaken for a bug.
  • Newlines for the braces, because this will make the braces more clear.
  • () around multiple statements with logicals? Something like
bool DataFieldInfo::operator==(const DataFieldInfo &other) const {
    // Compare the least expensive elements first
    return (bytesPerElement_ == other.bytesPerElement_ && rank_ == other.rank_ &&

            iSize_ == other.iSize_ && jSize_ == other.jSize_ && kSize_ == other.kSize_ && lSize_ == other.lSize_ &&

            iMinusHalo_ == other.iMinusHalo_ && iPlusHalo_ == other.iPlusHalo_ && jMinusHalo_ == other.jMinusHalo_ &&
            jPlusHalo_ == other.jPlusHalo_ && kMinusHalo_ == other.kMinusHalo_ && kPlusHalo_ == other.kPlusHalo_ &&
            lMinusHalo_ == other.lMinusHalo_ && lPlusHalo_ == other.lPlusHalo_ &&

            name_ == other.name_ && type_ == other.type_ && metainfo_ == other.metainfo_);
}

(from DataFieldsInfo.cpp) Is really really hard to parse.

@clementval
Copy link

agree to use it ... we should find a common style.

@cosunae
Copy link
Author

cosunae commented Jan 29, 2016

I am not sure introducing {} or () can be done with a formatter, but I will try to look at that.
This could probably more for clang-tidy.

But please if you have preferences just commit this branch or create another PR with changes, as said, I dont care much which format or style as far as we have one

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants