C++ – Is having C++ header files without extension a good practice

cnaming

I have an argument with a collegue of mine regarding the C++ guidelines to follow.

He currently designs all his libraries that way:

  • He uses inconsistently uppercase and lowercase letters in his filenames
  • Some of his headers don't have any extension

I believe that having no extension is something reserved for C++ standard files and that using uppercase letters is error prone (espcially when you deal with code which is meant to work on both Windows and Linux).

His point is that he follows Qt conventions (even for code that doesn't uses Qt) and keep saying : "If Qt does it that way, then it can't be bad."

Now I try to keep an open-mind, but I really feel bad when I have to work on/with his libraries. Is there a common established set of rules regarding this ? Does the standard tell something about it ?

Thank you very much.

Best Answer

The extension (or lack of) isn't going to, as far as I know, cause you issues. I would say that dropping the extension altogether is inconvenient as it makes it difficult to search header files (for example with the wildcards *.h and *.hpp) and it makes it more difficult to identify the contents of a file (for example if your editor relies on the extension to choose the proper syntax highlighting mode).

From a code point of view it doesn't make much difference, even the casing is not problematic so long as you use a consistent case everywhere and don't rely on case differences alone to differentiate files. From a convenience point of view it's easier to stick to lower case and have an extension (either .h or .hpp).

More important that any of the above, however, is to pick one convention for your entire development team and stick to it. It is far worse to have to look up how a file is cased, named and what extension it uses whenever you want to include something - all of these should be "guessable" with knowledge of the thing you are trying to use.