cesium-native icon indicating copy to clipboard operation
cesium-native copied to clipboard

Decide on #include style

Open lilleyse opened this issue 1 year ago • 4 comments

We're not totally consistent with how we include headers. What about something like this?

  • Use quotation marks for header files in the same directory e.g. #include "Library.h"
  • Use angle braces for everything else e.g. #include <CesiumUtility/JsonValue.h>

It would be great if clang-format could enforce this. In any case, once we agree on something it should go in the C++ Style Guide.

lilleyse avatar Nov 13 '24 16:11 lilleyse

Previous issue about this: https://github.com/CesiumGS/cesium-native/issues/80 Which pretty much came to the same conclusion that you wrote above. I think that's been the decision all along, we just haven't enforced it, or retroactively converted all code to that style.

In theory we don't need to put this in the Style Guide, because it's already in the C++ Core Guidelines, which are included by reference. 🤷 https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#sf12-prefer-the-quoted-form-of-include-for-files-relative-to-the-including-file-and-the-angle-bracket-form-everywhere-else

kring avatar Nov 14 '24 03:11 kring

CC https://github.com/CesiumGS/cesium-native/pull/1114#discussion_r1967378895

We used to use quotation marks for headers in the same directory, but lately we've just been using angle brackets with the fully qualified name for consistency.

Since this is a change from SF.12 it should be included in the style guide.

lilleyse avatar Feb 24 '25 15:02 lilleyse

CC #1114 (comment)

We used to use quotation marks for headers in the same directory, but lately we've just been using angle brackets with the fully qualified name for consistency.

Since this is a change from SF.12 it should be included in the style guide.

Doesn't this suppress clang-tidy checking, warnings as errors, etc. in these local header files?

timoore avatar Feb 24 '25 15:02 timoore

Just to add a little bit to this... We used to do this thing where public header files would include other public header files from the same library with quotes and a relative path. There's nothing wrong with that, except it was a special rule that we constantly forgot to follow, and it wasn't really buying us anything, anyway. At one point, Ashley wrote a tool to go through and fix all of our includes, and that tool used angle brackets and the qualified path instead, which I thought was just fine. For example, this:

#include "Library.h"

became:

#include <Cesium3DTilesSelection/Library.h>

I don't mind going back to the old pattern, but it seemed much more trouble than it was worth.

However, there is another place where we previously used quotes, and that shouldn't change. In a .cpp file, when including a private header in the same directory, quotes are absolutely the right thing to use. That shouldn't - and perhaps can't - change.

kring avatar Feb 25 '25 00:02 kring