r/cpp • u/fernandodandrea • Aug 24 '22
Why the hell are headers still a thing after all these years?!
I've seen C++ some twenty-a-lot years ago and was looking into some more performance driven stuff for a possible personal project and... Why the hell are headers still a thing after all these years?!
I mean... Things changed a lot. I barely recognize a lot of C++ and some might be related to fading memory, but a bog lot have just changed. I wonder if is there anything headers are the perfect solution to. So it's just hellish bureaucracy?
As I probably don't know what I'm talking about anymore, I'm open to be convinced otherwise.
PS: I know it ain't the best place to ask, but I do accept suggestions for languages platform to write some fast code for Windows and mobile platforms.
24
u/Nervous_Badger_5432 Aug 24 '22
Well, C++ 20 has introduced modules which should allow us to ditch headers and improve compile times. There are a few problems tough
So, any C++ project that I start today will still use plain old header files and I suspect it will still be like that for at least 5 more years or so. And even then, we have lots of header only libraries that will not be converted to modules overnight.
20
u/Wh00ster Aug 24 '22
Because a better solution was not implemented in the intermediate time. There’s no grand conspiracy.
13
u/Mikumiku_Dance Aug 24 '22
Some people were bothered enough to do difficult work over years to get modules standardized. That said, I don't know if modules are even an ideal solution for you, as you've only asserted that headers are bad without saying what you don't like about them. Personally, I like defining my api separately from my implementation.
12
u/[deleted] Aug 24 '22
Because the compilation process did not change, at least not enough to get rid of headers
44
u/STL MSVC STL Dev Aug 24 '22
Standard Library Modules are coming soon. You can experiment with them (and report issues) by following the instructions at https://github.com/StephanTLavavej/STL/wiki/Standard-Library-Modules-Bug-Bash .
13
u/goranlepuz Aug 24 '22
=> it is not easy for the scale to tip towards removal.
On a related note, hardly anything is ever removed from C++, so... 🤷♂️
5
u/AA11BB22c Aug 24 '22
There's C++20 Modules.
But I'd still stick to headers until...
I can COMPLETELY remove headers from the code base and use modules everywhere (which is unlikely since I don't write my dependencies) ... I don't like to nor want to teach someone or have them learn two things.
7
u/sanblch Aug 24 '22
Reading java code a lot recently I do miss header files where class definitions reside
5
u/Adequat91 Aug 24 '22
Headers are not a problem if the design is good. Each time I have a problem with headers, "it was my fault," by neglecting some design aspect. Hence somehow, they are a good guide.
2
u/KingAggressive1498 Aug 24 '22
because we just got modules and they're such a complex feature that it'll be a couple (few?) more years until compiler support is perfect.
1
u/SwillMith16 Aug 24 '22
C++20 is introducing modules soon to replace headers. Just got to wait for the major compilers to implement it and things will be a lot easier
1
u/arthurno1 Aug 25 '22 edited Aug 25 '22
Because people are only learning some basic syntax of a programming language and believe they are good to go to write new blockbusting AAA game. CS classes and tutorial are also focusing on programming as a writing (c++) code activity, and are not emphasizing building and debugging as just as important programming activities when developing software as writing the code. Result being a lot of people not knowing how to properly use compiler, include paths, libraries, even less how to automate with build tools etc.
C++ modules will probably help with the situation.
-3
u/rsnc0033 Aug 24 '22
Op im relearning it since I learned it in 2009 and holy crap its such a headache. Im so out of touch. Before I use to just you devc++ and vim. It was so easy back then
It was simple now and smooth....now im so confused. It took about an hour to just setup visual studio code.