4 ms·
Header files absolutely are a hassle to keep up to date. Besides, they're a terrible experience. You have to pay attention to include order! You have to write f
by pcwalton 8y ago
Header files absolutely are a hassle to keep up to date. Besides, they're a terrible experience. You have to pay attention to include order! You have to write forward declarations! You have to write include guards, in 2018!
They're also bad as an overview. They may have been good in the 1980s, but nowadays a proper documentation generator gives you better formatting, search features, and cross-references. Inline documentation is particularly obnoxious in header files: I like seeing function-level documentation alongside interface and implementation, but if I put the documentation in both the .cpp and the .h file it's duplicated in two places and easily gets out of date.
- westmeal 8y agoDoes #pragma once count as an include guard in your book?
- jchb 8y ago#pragma once is not in any C++ standard, although basically all modern compilers support it. The reason it is not in the standard is that its behaviour in the presence of symlinks may differ depending on the filesystem and compiler. Is it the unique combination of filename + content that should be included once or is it the file path? etc.
- josefx 8y ago> The reason it is not in the standard is that its behaviour in the presence of symlinks may differ depending on the filesystem and compiler I have the feeling that the difference matters to almost nobody and should be avoidable by the few people it actually affects. I had more issues with colliding include guards than I had with symlinks and I still end up replacing CLASSNAME_H with PROJECT_CLASSNAME_H in our own headers every now and then since the autogenerated guards are too naive.
- beached_whale 8y agoThe order of headers mattering is very rare though and not indicitive of normal C++ code. It's rare, but not unheard of unfortunately as most C code is also available to C++.
- tjoff 8y ago> You have to pay attention to include order! You have to write forward declarations! You have to write include guards, in 2018! Include order is a valid complaint, the others truly are non issues. I mean, we have other more pressing issues. Such as the fact that garbage collection is still a thing in 2018. > ...but nowadays a proper documentation generator gives you better... Examples of that? > I like seeing function-level documentation alongside interface and implementation, but if I put the documentation in both the .cpp and the .h file it's duplicated in two places and easily gets out of date. This is the only thing that I dislike about header files. And it is a constant reminder how bad IDEs are at handling this.
- omegote 8y agoDoxygen can generate a list of all class members, including those from all ancestors. If you wanna do that checking header files you'll have to keep jumping between files going from parent to parent class.
- tjoff 8y ago... doxygen, no. I'd rather take header files than doxygen. I hope he meant something else since he said "nowadays". Doxygen is ok if you haven't setup your build environment. But for when you actually are in the code (and somewhat familiar with it) I very much prefer just reading the header files than switching to a browser.
- enriquto 8y ago> Header files absolutely are a hassle to keep up to date. This happens because there is some redundancy between the header file and the source. You can often arrange your code so that there is no redundancy (or almost zero).
- jcelerier 8y ago> Header files absolutely are a hassle to keep up to date. how so ? every IDE I've used automatically changes the header if you change the cpp and conversely