-
Notifications
You must be signed in to change notification settings - Fork 18
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.
|
||
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. |
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...
|
||
## Using declarations | ||
|
||
Do not put any using declarations in any header file. |
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 have enough C++ experience for this, but does this mean that this:
private:
double rotation = 0.;
Point position;
double zoom = 1.;
bool isTargetingFlagship = true;
double radius = 15.;
const Color *color;
would be illegal?
I'm presuming not, but in that case the style guide should maybe specify that it's namespace declarations that matter.
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 see a using declaration in that code snippet, and nothing else about it looks like incorrect syntax to me.
This part of the style guide relates to use of the using
keyword in header files (outside of class definitions, which should perhaps be added).
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.
Oh, whoops. I somehow missed the word "using." You can ignore this comment, then.
wiki/C++-Style-Guide.md
Outdated
} | ||
} | ||
``` | ||
If you are used to putting spaces before the parentheses, rather than trying to adjust your typing you might find it easier to just do a find/replace before committing your code, e.g. replacing "if (" with "if(", etc. You can also grep the svn diff of your changes for "^+.*\ (" to check if you missed anything. |
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.
Same issue with blue text here.
Plus, I don't think anyone's "grepped the svn diff" in the last nine? ten? years.
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 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 <[email protected]>
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 <[email protected]>
I'm not so sure about putting things that aren't code (file names, for example) in in-line code blocks instead of quotes. |
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.