I talked to my instructor the other day and asked him this question. He told me that I could go for smaller projects, but I'm starting a chess program and I was wondering what Stack Overflow thinks about this issue. Should I include all headers into one file, or separate them?
Normally, you want separate headers.
Including more than necessary does a few potentially bad things.
This is single greatest cause of slow compile times. Unnecessary inclusion of extra headers slows down compilation, since each source file has to worry about more info than it needs. It starts as a small problem, and before you know it hundreds of developers are wasting dozens to hundreds of hours each because the problem got too far out of hand to fix. Even though you're working on small problems, it's important to understand proper separation of headers - it's easy to get right the first time but very hard to fix later if you ignore it.
You lose the ability (depending on compiler/IDE) to correctly handle dependencies, and wind up building more information than you need to build.
You lose maintainability. It's more difficult to maintain software when you have large, single files, than when you have lots of small, concise files.
You make the code more difficult to understand, hence more prone to bugs. By having everything in one file, it's easier to get "lost" in the huge header.
There are some times when this practice is useful:
Pre-compiled header files with code that really doesn't change that often.
APIs
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With