9 ms·
Aside, C++ would have been so much nicer without the need for header files ...
by amelius 8y ago
Aside, C++ would have been so much nicer without the need for header files ...
- garaetjjte 8y agoThere is modules TS: http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2018/n4720.pdf http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2018/n472...
- grandmczeb 8y agoThe draft for the merged version expected to be in C++20 is here: http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2018/p1103r1.pdf http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2018/p110...
- flukus 8y agoIf java is any guide developers would go out of their way to add interfaces everywhere anyway, often they're essentially header files for the OO gods.
- kjeetgill 8y agoI haven't done any C++ in a while, can you swap out the implementation backing a header? I suppose at the linker layer maybe but even that is just once globally for the program. Right? The OOP God's demand polymorphism! If memory serves me, the C++ version is a class with all empty virtual functions.
- flukus 8y agoYeah, it can only be swapped out at link time (without crazy magic). That satisfies two very common cases though, when there is only one implementation (and the interface is a sacrifice to the OOP gods) and when the second implementation is for unit testing only. Those 2 plus other crazy rules (like only one interface defined per file) mean that many projects will end up with just as many interface files as a c++ project would header files.
- tjoff 8y agoIn principle I agree. An IDE should be able to automatically generate something like a header file regardless of language. But still, no IDE or tool I've seen does this better. A header file gives you a very nice overview, and it really isn't any hassle to speak of to keep them up to date. It takes getting used to (as with everything when starting out with a new language), but before you know it you might even start to miss them in other languages.
- int_19h 8y agoSeparation of module interface and module implementation is useful, but headers are a horrible way to do that. For an example of how it can be done right, look at Borland Pascal dialects (with "interface" and "implementation" section in each unit, where "interface" can be extracted if desired), or Ada, or ML.
- tech_tuna 8y ago>it really isn't any hassle to speak of to keep them up to date Dear lord, all those broken builds I've seen over the years would love to talk to you about that.
- setpatchaddress 8y agoThat has not been my experience in 35 years of dealing with headers in C and C++ in large-scale software projects. Ruby, Swift, and even Python (or Pascal if we want to go way back) are significantly easier to deal with for anything sophisticated.
- kazinator 8y ago> An IDE should be able to automatically generate something like a header file regardless of language. https://www.hwaci.com/sw/mkhdr/ https://www.hwaci.com/sw/mkhdr/
- pcwalton 8y agoHeader 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.
- muricula 8y agoHeaders allow you to ship a binary without the full source code. If you want to build a linux kernel module you don't need all of the linux sources, just the headers.
- fermienrico 8y agoIn principle you're right, but the notion that header file exposes just the "interface" is completely false. Class definition, private variables and functions, etc. are all exposed in header file. Header files are not a way to only expose the interface. You give up a lot more in C++. I've never had to deal with pesky header files until I started developing C and it immediately struct me as a royal pain in the ass. Even after couple of years of developing C/C++, I find the whole concept of header files archaic. Include preprocessor directive literally copy pastes stuff with no intelligence what-so-ever. The user is now burdened to ensure #includes are guarded to what I call a patchy half-baked hacked up solution - #IFDEF/#DEFINE/#ENDIF and #pragma in C++. It should be handled automatically by the compiler/preprocessor or IDE and I believe it is now being addressed in the C++17/20 spec with the advent of "modules". This thing should have been written up way back in 1989.
- jlarocco 8y ago> In principle you're right, but the notion that header file exposes just the "interface" is completely false. Sorry, but it is not "completely false". Doing it properly requires a carefully designed interface to hide internal data structures, and splitting out the end user headers from the internal headers, but it works. > I've never had to deal with pesky header files until I started developing C and it immediately struct me as a royal pain in the ass. It's like saying, "I've never had to deal with pesky .py files until I started developing Python."
- fermienrico 8y agoHow do you compare .py files with .h files? I am confused as to how you are drawing this analogy.
- jacobush 8y agoI use https://github.com/mjspncr/lzz3 https://github.com/mjspncr/lzz3 - it generates header files and source files. If feels quite weird and nice. :)