-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
Fix #15438, Add to General Formatting Guidelines for C and Julia #15439
Fix #15438, Add to General Formatting Guidelines for C and Julia #15439
Conversation
@@ -154,6 +154,7 @@ Make sure that [Travis](http://www.travis-ci.org) greenlights the pull request w | |||
- use lower case with underscores for method names | |||
- it is generally preferred to use ASCII operators and identifiers over | |||
Unicode equivalents whenever possible | |||
- function signature should not be followed by an empty 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.
specify end of functions too?
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.
something like no empty line before the end of a function
?
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.
or something like: no empty line before end
in julia and no empty line before }
in c?
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.
It would be good if the word end
is highlighted, in order to make it clearer.
Even this looks good enough too, however highlighting it would make it clearer IMO.
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 changed it, please check!
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.
Hey @Dawny33! I didn't read your note earlier. Highlighting wasn't added to the other lines, and so I assumed that I shouldn't add 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.
Yeah, I was skeptical with the suggestion too.
The current diff LGTM, can go ahead with it 👍
This is not quite correct. You can and should indent nested preprocessor macros (see e.g. this example in src/init.c), but the indentation comes after the |
@@ -154,6 +154,8 @@ Make sure that [Travis](http://www.travis-ci.org) greenlights the pull request w | |||
- use lower case with underscores for method names | |||
- it is generally preferred to use ASCII operators and identifiers over | |||
Unicode equivalents whenever possible | |||
- no newline after function signature | |||
- no newline before function end |
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.
Are these really necessary to spell out?
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.
Occasionally, I've found it more readable with a newline after long function signatures so I don't think we should add this rule.
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 came up in #15418.
In general, I think we should limit the style guide to things where there is significant disagreement among different programmers. More concretely, we only need to put rules in the style guide if we find that contributors are violating them. (Including too many rules makes it less likely that people will read the rules in the first place.) e.g. we write Similarly for the "no newline before function end" rule; it's not something that people seem to violate, so we hardly need to spell it out. And have we had a problem with contributors indenting cpp macros? |
People do add excess newlines or other nits that contributors who spend lots of time in the code end up cleaning up. I think the style guide should expand to include various things that we would want an auto formatter to enforce if we had one. Yes the current codebase has a few places in codegen and elsewhere that are inconsistent about indenting preprocessor directives, especially when code gets copy pasted from LLVM or libunwind or other projects with different style conventions. |
FWIW, I strongly disagree with "no newline after function signature". I make no claim to have better taste that anyone else, and at the end of the day, attempting to apply rationale to style is silly, so I'm not going to debate the issue. I was recently chastised for this blank line: https://github.com/JuliaLang/julia/blob/master/base/mapiterator.jl#L64. (Also I think the proposer means "no blank line" rather than no "newline") |
See also @tbreloff: #15418 (comment) |
Quoting your C# StyleCop link:
|
Re StyleCop's "exception to this rule"... True, but that is because in
|
Concretely, the vast majority of the existing code base does not have blank lines after signature, even when the body starts with a comment. Therefore, if we allow them we lose consistency an leave room for discussions, which wastes time when reviewing PRs. A simple rule without exceptions is better. |
Could we agree on a systematic rule here? Discussions regarding spacing in PRs are wasting everybody's time. See e.g. #15409. |
refer to #15438