-
Notifications
You must be signed in to change notification settings - Fork 273
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
C++ headers with separate declarations/definitions #996
Comments
If you're going to the trouble of breaking them out like that, it's worth, for each one, asking if it really belongs in the corresponding cpp file ~ in other words, asking why was this inline in the first place? |
Definitely, though a lot of them are templates so they need to be in the header files. I think these functions probably do not need to be inlined:
Should I move those into the .cpp file in the PR? |
I agree on all of them except the constructor, that's preferably inlined no need to take a possible cache line load on such a common op |
Ah yes, sorry; for some reason I was under the impression that constructors were not inlined. I'll move the other ones to the .cpp file. |
I checked in a change to remove these functions from the headers in the PR:
|
Re-opening this issue since I think it would be a nice quality of life improvement for C++ developers. Especially if we add API documentation to the C++ headers at some point, moving the inline functions outside of the class declaration will remove noise and help readability. Here's a link again to one of the OpenEXR headers that follows this pattern: Unlike my previous PR I would suggest that a new PR should only separate the inline function definitions and declarations to keep it manageable. Additional work like determining whether functions should be inline or not could be done with follow up PRs. |
Currently a number of the C++ headers have the function declarations combined with the definitions, i.e.:
As a C++ developer it would be nicer to browse the class API if the function definitions were separated, i.e.:
This example is trivial but with large classes with a lot of implementation code it can obscure the class API. OpenEXR does this fairly consistently:
https://github.com/AcademySoftwareFoundation/openexr/blob/master/src/lib/OpenEXR/ImfChannelList.h
The code changes would be cosmetic only, no functionality would be changed. I'll submit a PR to show what this looks like for a couple of header files, if the changes sound reasonable I can update the rest of them. However if this seems like too large of a change I'm also fine to close this issue.
The text was updated successfully, but these errors were encountered: