-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
order of includes and include protections #156
Comments
Commented by nslagle on 4 Oct 41823686 05:04 UTC |
Commented by nslagle on 1 Apr 41825626 14:06 UTC
In the ''do_stuff_ever_impl.hpp'', add a check for the single use ''#define'' from above:
|
Commented by rcurtin on 15 May 41833892 12:59 UTC If the user is brash enough to define Also, I'll be picky and say that the actual format of the include guards should be I've started to implement your original solution for protecting |
Commented by rcurtin on 31 Mar 41833893 06:09 UTC |
Commented by nslagle on 10 Sep 41833980 17:04 UTC The extra layer forces a user to define an otherwise undefined macro before using it, at which point they'd see the prohibition statement in ''#error''. |
Commented by rcurtin on 13 Feb 41834151 07:18 UTC In other words, I can't see a possible case where the simpler approach fails to prevent unwanted behavior. The only issue we need to catch is where someone includes file_impl.hpp before file.hpp, or, when they include file_impl.hpp but not file.hpp. The simple approach catches that in every case. |
Commented by jcline3 on 30 Jan 41834267 12:50 UTC If you're worried about people adding to mlpack itself, they should just include our core.h, and that should pull in all the pieces they need. Any other includes they have would be for the things they are specifically working on, not features already in the library, which should be included via core.h. |
Commented by nslagle on 24 Jun 41834991 01:58 UTC Another solution adopted by others in the C++ template camp is to use a different extension for the ''stuff_impl.hpp'' file, perhaps ''stuff.impl'' (I can't remember the suffix exactly.) @jc: Is our solution to simply provide one gigantic include for the entire library, including all of the methods? I see that armadillo does something similar with its global include, though I'm not sure about doing this in production code, at least not internally. ''An advantage in reducing your include dependencies to the minimum necessary to accomplish the task is to ease understanding of the dependencies.'' Namespaces ostensibly help us with this, but we often mitigate this with ''using namespace ohWell;''. Admittedly, we haven't the time right now to discover exactly which armadillo dependencies we're using (though likely we aren't using very many of them), but we don't necessarily have to follow the same sloppy paradigm, at least not internally. Take KDE for instance; I don't really need everything available in core.h, so probably I can just add three to five internal includes, and anyone looking at the code immediately understands the dependencies. Thus, the curious reader can look at the KDE header to see that ''spacetree.hpp, hrectbound.hpp, range.hpp,'' and ''log.hpp'' are necessary to make it work. Externally, for the babes in the woods, we can provide the all-inclusive-every-header-on-the-system approach, though that still seems like overkill to me. The rule we followed in developing simulator C code is to blob together includes only when they form a chain of dependencies necessary to make the final target run (much like our ''do_stuff.hpp'' and ''do_stuff_impl.hpp'' dependencies.) |
Commented by rcurtin on 3 Apr 41835037 15:27 UTC
I've never seen that; the _impl.hpp or _impl.h is fine with me. I don't see what problem that would solve.
This is reasonable:
But this is superfluous:
And, like I stated earlier, this is why: If someone is dumb enough to define SOME_FILE_HPP but not include some_file.hpp, then there is no helping them. It's not our problem. And none of this is about encouraging proper usage. You don't want someone to include some_file_impl.hpp because there may be declarations in some_file.hpp which aren't present in some_file_impl.hpp (such as an inline function) and now everything breaks. In fact there's even a third solution which is even simpler:
It isn't our problem if our users our stupid, but it is our problem if our library is counterintuitive and poorly designed. In my opinion the USE_SOME_FILE_HPP method is trying to compensate for idiotic users, which shouldn't be our problem. I almost like the solution I just proposed (the just-in-case include) more. Why inundate our users with errors when we don't need to? Their C++ style is their own problem, and it's definitely common knowledge that you shouldn't be including the _impl.hpp files. One more thing:
Well, in a large library like ours that isn't really the right thing to do. Instead I would expect a user to write
Modifying our core.h to only include parts of Armadillo is a bad idea. A user including MLPACK methods is able to assume that Armadillo is included, and if some methods aren't available because not everything is included, things break. Yes, we may lose compile time as a result, but really this is a can of worms we should not open. |
Commented by jcline3 on 26 Jul 41836061 04:52 UTC
I don't see the point in that, since any method they #include will #include core.h, and thus everything anyway. |
Commented by mamidon on 27 Dec 41836432 22:27 UTC
|
Commented by jcline3 on 6 Nov 41836592 03:21 UTC
You're right. Somehow I got it into my head that core.h includes all the methods as well. |
Commented by rcurtin on 5 Feb 41954245 16:07 UTC |
Reported by nslagle on 8 Aug 41823682 22:04 UTC
A little nitpicky, but I prefer includes appearing in a file to appear in four blocks:
In each separate block, alphabetize the listing by header name. Also, headers appearing in block IV should appear using quotes to indicate a ''lesser'' status, if you will. Of course, this ''lesser'' status within this file might be (and hopefully is) a higher status in other more distant source files.
By our templating convention, we create the intermediary ''do_stuff_ever_impl.hpp'' file to house complicated template methods for the class ''DoStuffEver''. We typically include this implementation intermediary at the conclusion of the top header file for the class.
This type of include falls under ''BLOCK IV'', so use ordinary double quotes rather than angled brackets.
Finally, in the file ''do_stuff_ever_impl.hpp'', do not use any ''#includes''; simply begin the file with
Restricting this file to contain no additional includes further protects us from including the file improperly; any ''includes'' required for this file can appear in ''do_stuff_ever.hpp'' above.
The text was updated successfully, but these errors were encountered: