Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

I have a project where my files have gotten out of hand because of the volume of them. I have started to combine classes of similar types in single header files because you can, and it still is good practice, now can i do the them same for those classes functions, that are declared in the source files.

Is it a good idea to combine several classes functions in a single source file, if the classes are say all sub classes of the same super class?

share|improve this question
3  
What is the question? –  Klaim Apr 27 '12 at 1:40
    
can i, and is it a good idea to combine several classes functions in a single source file, if the classes are say all sub classes of the same super class. –  Tucker Morgan Apr 27 '12 at 1:45
1  
You should put the question in the...question description. –  Klaim Apr 27 '12 at 2:07
2  
You have to think about how it may impact your build. If it's a complex project you could be forcing the build of sections that haven't changed. That extra build time can add up. I worked on a project with 5 million lines of code and it took a long time to build. We didn't want to build sections that didn't change. –  jmq Apr 27 '12 at 2:51
    
add comment

2 Answers

It is not bad practice to do so, just make sure that if the user only want a part of the system, he can include only one header and get the necessary bits. Having several definitions of class and other things in one header is fine and can even help compilation time if well done. If not well done, it can kill the build time in a bad way. So, just make sure each header gather elements that cannot be separated and that represent one (sub)module.

Look at readable C++ standard library implementation (most are not, depends on the provider) and/or better, look at boost code as good examples of this practice.

share|improve this answer
    
I wouldn't exactly recommend reading STL sources as an example of neat project organisation... –  tdammers Apr 27 '12 at 8:29
    
Depends on the implementation. I'll modify a bit. –  Klaim Apr 27 '12 at 8:37
add comment
I have started to combine classes of similar types in single header files..

It is good approach to implement library, but If it is your implementing client does not require the another extra classes for implementation. for example your header file contain 1 million lines of code after integrating similar type of classed then it took a long time to build.

As per my experience with library design and the standards that i follow in Microsoft technology Library Design Guidelines. In case of .Net platform it does not matter much, but In case of c++ that i got on the apple development Dynamic Library Design Guidelines is that library should maintain these following factor of implementation.

  • Focused
  • Easy to use
  • Easy to maintain

Try to make your header files smaller and concise so that it will be easy to understand and increase the compile time. Sometime i prefer to have single class in single file, some experts suggest to follow this approach. You can combine classes those are much coupled to each other in single file.

Ref:
Multiple classes in a header file vs. a single header file per class
Google C++ Style Guide

share|improve this answer
    
Try to make your header files smaller and concise so that it will be easy to understand and increase the build time. Is that a typo? Why would it increase the build time? –  BЈовић Apr 27 '12 at 7:58
    
i have explored more on it .. and changed it little bit.. –  Niranjan Kala Apr 27 '12 at 8:12
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.