-
Notifications
You must be signed in to change notification settings - Fork 28
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
Copy the C++ style guide into the wiki #47
base: master
Are you sure you want to change the base?
Copy the C++ style guide into the wiki #47
Conversation
I'd prefer the website redirecting here, or having some method to sync automatically (but there's format difference). Hosting it on both places makes it harder to modify. |
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.
Quite a few comments on this.
Most of my comments have to do with changes to the styleguide itself (or changes to our current practices), so may be best dealt with in a separate PR. The biggest ones here stem from the fact that this style guide hasn't been updated in a decade or so, and I think Endless Sky switched which platform it was hosted on two or three times in that period?
The other two things I've noticed is that, since markdown has this
, we should probably use it instead of MZ's "double-quoted code," and that I think code blocks might need an extra line after their preceding paragraph in order to work possibly.
Also, we might want to make edits now that this isn't a list where you click to expand points. It seems to mostly work as-is, though.
Finally, I would very much support moving this over to only be on the wiki. I think the fact that this is so very outdated emphasizes how little people actually use the website, especially when writing code (or making sweeping changes to little things like the version of C++ ES uses!)
this program. If not, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
``` | ||
If you make substantial additions or changes to a file, please add your name to the copyright list. |
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.
Haha, very funny MZ. This should probably either be removed, or we should go back and actually start doing copyright headers properly in the first place.
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.
Can you elaborate on what it would mean to do them properly?
As I understand it, the current approach is indeed for people who make substantial changes to a file, or create new code in a new file, to add their name to the copyright at the beginning, though this is perhaps more common in relation to data files than it is to the source code.
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.
As far as I'm aware, people's names only get put in the copyright header when they're the one who makes it, for ES. At least, that's the rules I've been playing by. I think, according to the GPL license, every single contributor to the file should have their name in the header. We definitely aren't doing 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.
I know for certain that people who have made significant additions to data files have been added to the copyright header.
I don't know about the C++ files, but it's possible that no one has made sufficient changes to a single file that they did not create to get to that point, at least not in one go, or they just didn't want to put their name there, or I'm just forgetting instances where it has happened.
I can't see where the GPL says that. It certainly references "authors". I don't think every contribution to a file constitutes "authorship".
|
||
Within a .h file, the #includes should be broken into "paragraphs" each separated by a single blank line: | ||
1. Classes that this file's class inherits from. | ||
2. Other files in the "endless-sky" code base. |
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.
Any reason why this is "endless-sky"
, rather than Endless Sky
or even just endless-sky
?
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 don't know why it was originally written that way. As mentioned, this PR just copies the content of the existing style guide and reformats it from xml.
Do you think there is something wrong with the way it is right now?
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.
Not particularly anything wrong, this could just be something to change in a follow-up PR.
Or, it could be formatted as
`endless-sky`
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.
2. Other files in the "endless-sky" code base. | |
2. Other files in the `endless-sky` code base. |
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 would this change the appearance and why do you think it would be an improvement?
class Angle; | ||
class Sprite; | ||
``` | ||
It is helpful but not required to alphabetize the lines within each "paragraph" of #includes. |
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.
Maybe we should require this? Is there any place where we don't do this?
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.
In practice, we do require it. This can be changed.
wiki/C++-Style-Guide.md
Outdated
## Order of #includes in a .cpp file | ||
|
||
Within a .cpp file, the #includes should be broken into "paragraphs" each separated by a single blank line: | ||
1. This file's corresponding .h. | ||
2. Other files in the "endless-sky" code base. | ||
3. Non-standard third-party libraries. | ||
4. Standard libraries. | ||
|
||
For example, a .cpp file might contain the following #includes: | ||
```c++ | ||
#include "MyClass.h" | ||
|
||
#include "Angle.h" | ||
#include "Sprite.h" | ||
|
||
#include <SDL/SDL.h> | ||
|
||
#include <set> | ||
``` | ||
It is helpful but not required to alphabetize the lines within each "paragraph" of #includes. | ||
|
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't help but feel like this could be combined with the section above...
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 could, but would that be an improvement?
} | ||
``` | ||
|
||
## Function definitions |
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.
Blue text again
|
||
## No compiler warnings | ||
|
||
Code should compile with -Wall without any warnings. |
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 already get compilation warnings every time I build for MacOS. Are we still following this guideline, or can we safely ignore specific compilation warnings?
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.
As far as I know, no warnings are produced in the CI/CD MacOS builds.
Building using supported tools should not produce warnings with -Wall.
Consider opening an issue providing more details if this is not consistent with your experience.
|
||
|
||
|
||
# C++11 |
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.
We should maybe have a section for later versions of C++, too?
In general, I'm not inclined to change the content of the style guide in this PR, only the formatting. |
Co-authored-by: mOctave <73318970+mOctave@users.noreply.github.com>
Yeah, that makes sense. I still would suggest taking it off the website, though, since the website in general is the last place anyone looks for anything. Also, I'm pretty sure I didn't catch all the quoted text that should be changed. I can go through it again and find some more if you'd like. |
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 this is all of them, now.
|
||
## File extensions | ||
|
||
All C++ files should use ".h" and ".cpp" for their extensions. |
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.
All C++ files should use ".h" and ".cpp" for their extensions. | |
All C++ files should use `.h` and `.cpp` for their extensions. |
|
||
## One class per file | ||
|
||
Each class "MyClass" should have its own .h and .cpp files, and they should be named "MyClass.h" and "MyClass.cpp". |
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.
Each class "MyClass" should have its own .h and .cpp files, and they should be named "MyClass.h" and "MyClass.cpp". | |
Each class `MyClass` should have its own .h and .cpp files, and they should be named `MyClass.h` and `MyClass.cpp`. |
|
||
## Names for files with no classes | ||
|
||
If a file does not contain any classes (such as "main.cpp" or "shift.h"), its name should be lower-case. |
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.
If a file does not contain any classes (such as "main.cpp" or "shift.h"), its name should be lower-case. | |
If a file does not contain any classes (such as `main.cpp` or `shift.h`), its name should be lower-case. |
|
||
## Header file guards | ||
|
||
All header files should have #define guards, and they should be in the format "#ifndef MY_CLASS_H_". |
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.
All header files should have #define guards, and they should be in the format "#ifndef MY_CLASS_H_". | |
All header files should have #define guards, and they should be in the format `#ifndef MY_CLASS_H_`. |
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 need to update lines about header guards anyway, so this will be removed.
Co-authored-by: mOctave <73318970+mOctave@users.noreply.github.com>
I'm not so sure about putting things that aren't code (file names, for example) in in-line code blocks instead of quotes. |
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.
Let's just finish the migration for now. Any updates to the guide contents themselves that aren't already present in the old version should be properly discussed in their own separate PRs after the migration is complete.
All header files should have #define guards, and they should be in the format "#ifndef MY_CLASS_H_". | ||
The C++ standard technically does not allow source code files to define macros that start with an underscore or contain a double underscore. |
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.
endless-sky/endless-sky.github.io@a4afddd
All header files should have #define guards, and they should be in the format "#ifndef MY_CLASS_H_". | |
The C++ standard technically does not allow source code files to define macros that start with an underscore or contain a double underscore. | |
All header files should have #pragma once guards. | |
The C++ standard technically does not allow #pragma once, but all major compilers support it. It is also much easier to use than regular header guards. |
8. private variables | ||
Anything not listed here (e.g. public non-constant variables, protected variables, etc.) should not be used. | ||
Here is an example class definition, with extra comments added to point out aspects of the formatting: |
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.
8. private variables | |
Anything not listed here (e.g. public non-constant variables, protected variables, etc.) should not be used. | |
Here is an example class definition, with extra comments added to point out aspects of the formatting: | |
8. private variables | |
Anything not listed here (e.g. public non-constant variables, protected variables, etc.) should not be used. | |
Here is an example class definition, with extra comments added to point out aspects of the formatting: |
|
||
## Function names | ||
|
||
Function names should be CapitalizedCamelCase |
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.
Function names should be CapitalizedCamelCase | |
Function names should be CapitalizedCamelCase. |
|
||
## Single-line loop bodies | ||
|
||
You do not need to use braces if a loop or conditional body is a single expression. |
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.
endless-sky/endless-sky.github.io@c541362
You do not need to use braces if a loop or conditional body is a single expression. | |
You should not use braces if a loop or conditional body is a single expression. |
if(theThing != done) | ||
DoTheThing(); | ||
``` | ||
You can also forgo the braces for something like this: |
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 can also forgo the braces for something like this: | |
You should also forgo the braces for something like this: |
if(vec[i]) | ||
sum += i; | ||
``` | ||
And, you can also do this: |
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.
And, you can also do this: | |
And, you should also do this: |
New content
Summary
It has been suggested on occasion that the C++ style guide (available on the website) should be inside the wiki.
This PR copies and reformats that content into a markdown file within the wiki.