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

codingGuidelines.md: clarify some details about headers #400

Merged
23 changes: 16 additions & 7 deletions doc/codingGuidelines.md
Original file line number Diff line number Diff line change
Expand Up @@ -148,16 +148,22 @@ In general, macros should be avoided (see [Modern C++](https://docs.google.com/d
* Comments for users of classes and functions must be written in headers files. Comments in definition files are meant for contributors and maintainers.

### Include directive
For source files (.cpp) with an associated header file (.h) that resides in the same directory, it should be `#include`'d with double quotes and no path. This formatting should be followed regardless of with whether the associated header is public or private. For example:
Copy link
Contributor

Choose a reason for hiding this comment

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

Ah, sorry, this now reads "regardless of with whether" as opposed to "regardless of whether". :)

```cpp
// In foobar.cpp
#include "foobar.h"
```

All included public header files from outside and inside the project should be `#include`’d using angle brackets. For example:
```cpp
#include <pxr/base/tf/stringUtils.h>
#include <mayaUsd/nodes/stageData.h>
```

Private project’s header files should be `#include`'d using the file name when in the same folder. Private headers may live in sub-directories, but they should never be included using "._" or ".._" as part of a relative paths. For example:
Private project’s header files should be `#include`'d using double quotes, and a relative path. Private headers may live in the same directory or sub-directories, but they should never be included using "._" or ".._" as part of a relative path. For example:
```cpp
#include privateUtils.h"
#include pvt/helperFunctions.h"
#include "privateUtils.h"
#include "pvt/helperFunctions.h"
```

### Include order
Expand All @@ -166,14 +172,15 @@ Headers should be included in the following order, with each section separated b
1. Related header
2. C system headers
3. C++ standard library headers
4. Other libraries’ headers
4. Other external libraries’ headers
5. Autodesk + Maya headers
6. Pixar + USD headers
7. Your project’s headers
8. Conditional includes
7. All public headers from this repository (maya-usd)
8. All private headers
9. Conditional includes

```cpp
#include exportTranslator.h"
#include "exportTranslator.h"

#include <string>

Expand All @@ -187,6 +194,8 @@ Headers should be included in the following order, with each section separated b
#include <mayaUsd/fileio/shading/shadingModeRegistry.h>
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe add a group with a pxr header or two just before the mayaUsd ones for completeness?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Agreed that we should probably add a pxr header to help clarify... will hold off on doing that until we make a decision here, however.

Copy link
Contributor

Choose a reason for hiding this comment

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

Sounds good. I'm on board for option B.

#include <mayaUsd/fileio/utils/writeUtil.h>

#include "private/util.h"

#if defined(WANT_UFE_BUILD)
#include <ufe/ufe.h>
#endif
Expand Down