-
Notifications
You must be signed in to change notification settings - Fork 275
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
clang-format #882
clang-format #882
Conversation
@srajangarg Could you also update this https://github.com/symengine/symengine/blob/master/doc/style_guide.md (design guide)? Will also help in reviewing this PR. Lot's of changes here. |
@srajangarg I'm going through this PR slowly. Could you tell me tell me if there is maximum character limit for a line? |
return Mul::from_dict(p->second, std::move(d2)); | ||
} | ||
} | ||
if (is_a<Pow>(*p->first)) { | ||
insert(m, rcp_static_cast<const Pow>(p->first)->get_base(), | ||
rcp_static_cast<const Pow>(p->first)->get_exp()); | ||
rcp_static_cast<const Pow>(p->first)->get_exp()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this suggested by clang-format
? What rule is this, so that I can document it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The next line should start from (
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
whenever braking a function call, clang-format will align the arguments properly, i.e. the arguments in the new line will match the start of the arguments in the above line.
GOOD
my_func(mqwe, pter, lolqw,
acc, cccs)
BAD
my_func(mssad, pwqe, loadsl,
adsa, casd)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed. But how do you decide where exactly to move to next line?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think clang-format won't mind as long as they are aligned, and below the column limit. For our own sake, we can ask the users to fit as many arguments on the initial line before moving to the next.
@srajangarg Thank you for this patient work. I have left some comments above, could you address them? From what I understand, what you have taken care of is
The same for namespaces and classes.
The code sure is more uniform now. I still have following doubts
@certik @isuruf Could you also go through this, atleast my comments to decide on decisions where there is doubt. |
The longest limit of a line is indeed 115, but clang-format gives us another option of It also checks for trailing whitespaces. I'm still not sure about comments and how they are being handled here. |
I will address the remaining comments/modifications soon. |
Standard: Cpp11 | ||
TabWidth: 4 | ||
UseTab: Never | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This line is not needed.
@Sumith1896 @certik @isuruf Can you review this quickly? Everytime master changes, merge conflicts arise! |
@srajangarg We'll try to block other PRs before this gets merged. Don't worry. |
|
||
public: | ||
public: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this necessary?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can change it, if needed.
@@ -129,6 +131,7 @@ matrix: | |||
install: | |||
- source bin/install_travis.sh | |||
script: | |||
- bin/travis_clang.sh |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be run only on one Travis job
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How should I do that?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Set an environment variable (eg: TEST_CLANG_FORMAT) to true in one of the jobs and check that the variable is true before calling this script.
…l single line functions except empty functions'
@srajangarg thanks for adding this. Let me play with this as well. E.g. I don't like for the functions to have |
@srajangarg, @Sumith1896, here is a plan for this PR that I propose:
That way it should be painless. I am now installing llvm-3.7 and clang-3.7 from source and will play with this myself. |
if [ $? -ne 0 ]; then | ||
echo "[!] INCORRECT FORMATTING! $FILE" >&2 | ||
RETURN=1 | ||
fi |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are mixing tabs and spaces here. Use spaces.
I would like the column limit to be 80. However, when I changed: --- a/.clang-format
+++ b/.clang-format
@@ -20,7 +20,7 @@ BreakBeforeBinaryOperators: All
BreakBeforeBraces: Linux
BreakBeforeTernaryOperators: true
BreakConstructorInitializersBeforeComma: false
-ColumnLimit: 130
+ColumnLimit: 80
ConstructorInitializerAllOnOneLineOrOnePerLine: false
ConstructorInitializerIndentWidth: 4
ContinuationIndentWidth: 4 it still has longer lines than 80... I see, one also has to do the following change: --- a/.clang-format
+++ b/.clang-format
@@ -43,7 +43,7 @@ PenaltyBreakBeforeFirstCallParameter: 19
PenaltyBreakComment: 22312
PenaltyBreakFirstLessLess: 120
PenaltyBreakString: 2123
-PenaltyExcessCharacter: 2
+PenaltyExcessCharacter: 1000000
PenaltyReturnTypeOnItsOwnLine: 60
PointerAlignment: Right
SpaceAfterCStyleCast: false Now it works as expected. @srajangarg I suggest to do these two changes. |
Another issue that I found is minor, e.g. this in
should be this:
Possible workaround: use |
Besides the column limit, I don't have any other suggestions. The |
Another issue that I found is that when I install |
@certik Don't you feel 80 characters is a bit too less? I know it is the defacto standard, but still. Also what about lines which are just longer than 80 characters? What do you suggest about the |
I don't think 80 is too narrow. Here is the patch: srajangarg#2, the code looks great. I don't understand your question about a line longer than 80 characters. I don't think there is any. If you want some pointers why 80 is a good choice (in the past and today), see e.g.: https://www.emacswiki.org/emacs/EightyColumnRule It really is a great choice. As to
and if so, use it. Otherwise fail. (We can possibly even skip the version detection in step 2.) |
Use 80 characters column limit
@certik, considering all the inputs on this, should I go ahead with a new PR? |
@srajangarg looks like you addressed all the issues raised in the PR? If so, I would go ahead and create a nice, clean new PR off top of the latest master as I suggested above. |
Adresses #866 . Also fixes the trailing whitespace problem @Sumith1896 .
I will soon link a wiki page for the workflow to be followed.
Edit : Here it is https://github.com/symengine/symengine/wiki/Development-workflow-for-SymEngine