I know it makes little difference to a project but, assuming you use #defined header guards for your C++ code, what format do you use? e.g. assuming a header called f
I prefer this format:
#ifndef FOO_HPP
#define FOO_HPP
/* ... */
#endif // FOO_HPP
MYLIB_FOO_HPP
, and it helps to avoid naming conflicts.I use
<FILENAME_IN_ALL_CAPS>_<YYYYMMDD>
or
<FILENAME_IN_ALL_CAPS>_INCLUDED_<YYYYMMDD>
Keeping it synchronous with folder hierarchies is too annoying (friend of refactoring), GUIDs are too annoying, the date suffix is good enough. If I would have to equally named files on the same day, I would
<FILENAME_IN_ALL_CAPS>_<YYYYMMDD>a
<FILENAME_IN_ALL_CAPS>_<YYYYMMDD>b
<FILENAME_IN_ALL_CAPS>_<YYYYMMDD>...
I'd go with the filepath + the boost _INCLUDED
suffix plus the nowadays widely supported #pragma once
In alot editors (for me its sublime) you can also define some macros/snippets for this.
Here is one that does it for you:
<snippet>
<content><![CDATA[
#ifndef ${1:${TM_FILEPATH/(.*\/(include|src))*([^a-zA-Z0-9_]+)*([a-zA-Z0-9_]+)([.])*([a-zA-Z0-9_]+)*/\U$4_$6/ig}_INCLUDED}
#define $1
#pragma once
$0
#endif // $1
]]></content>
<tabTrigger>incguard</tabTrigger>
<description>include guard</description>
</snippet>
so yourproject/include/yourlib/yourfile.hpp
becomes YOURLIB_YOURFILE_HPP_INCLUDED
An additional external source code style checker tool could easily track consistency of your guards this way.
I always included the namespace or relative path in the include guard, because only the header name alone has proven to be dangerous.
For example, you have some large project with the two files somewhere in your code
/myproject/module1/misc.h
/myproject/module2/misc.h
So if you use a consistent naming schema for your include guards you might end up with having _MISC_HPP__
defined in both files (very funny to find such errors).
So I settled with
MYPROJECT_MODULE1_MISC_H_
MYPROJECT_MODULE2_MISC_H_
These names are rather long, but compared with the pain of double definitions it is worth it.
Another option, if you don't need compiler/platform independence you might look for some #pragma once stuff.
I always use INCLUDED_FOO_HPP
I wouldn't use the double underscore one, because starting things with double underscores is reserved.
I always use use
#ifndef FOOBAR_CPP