Skip to content
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

Open
wants to merge 7 commits into
base: master
Choose a base branch
from

Conversation

warp-core
Copy link
Contributor

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.

@TomGoodIdea
Copy link
Member

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.

@TomGoodIdea TomGoodIdea added the standalone A PR that doesn't require an endless-sky PR to be merged. label Sep 16, 2024
Copy link
Contributor

@mOctave mOctave left a 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.
Copy link
Contributor

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.

Copy link
Contributor Author

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.

Copy link
Contributor

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.
Copy link
Contributor

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?

Copy link
Contributor Author

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?

Copy link
Contributor

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`

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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.
Copy link
Contributor

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?

Copy link
Contributor Author

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.

Comment on lines 112 to 132
## 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 &lt;SDL/SDL.h&gt;

#include &lt;set&gt;
```
It is helpful but not required to alphabetize the lines within each "paragraph" of #includes.

Copy link
Contributor

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.
Copy link
Contributor

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.

Copy link
Contributor Author

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).

Copy link
Contributor

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.

}
}
```
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.
Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this look correct?
image

}
```

## Function definitions
Copy link
Contributor

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.
Copy link
Contributor

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?

Copy link
Contributor Author

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
Copy link
Contributor

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?

wiki/C++-Style-Guide.md Outdated Show resolved Hide resolved
@warp-core
Copy link
Contributor Author

In general, I'm not inclined to change the content of the style guide in this PR, only the formatting.
You can already propose changes to it in the repository for the website at https://github.com/endless-sky/endless-sky.github.io.

@mOctave
Copy link
Contributor

mOctave commented Sep 17, 2024

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.

Copy link
Contributor

@mOctave mOctave left a 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.

wiki/C++-Style-Guide.md Outdated Show resolved Hide resolved

## File extensions

All C++ files should use ".h" and ".cpp" for their extensions.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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".
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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_".
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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_`.

Copy link
Contributor Author

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.

wiki/C++-Style-Guide.md Outdated Show resolved Hide resolved
wiki/C++-Style-Guide.md Outdated Show resolved Hide resolved
wiki/C++-Style-Guide.md Outdated Show resolved Hide resolved
wiki/C++-Style-Guide.md Outdated Show resolved Hide resolved
wiki/C++-Style-Guide.md Outdated Show resolved Hide resolved
@warp-core
Copy link
Contributor Author

I'm not so sure about putting things that aren't code (file names, for example) in in-line code blocks instead of quotes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
standalone A PR that doesn't require an endless-sky PR to be merged.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants