The More Source Files, the Better?◀ The More Functions, the Better?▶ Global Variables Versus Local Variables Amazon
common conception is that breaking a program into several source files makes the program more modular and thus better. While this may not be a misconception you’ll need to examine your code more carefully to know which way is better.
If I have only several small classes inside my program, I put all of them in the file where main()
resides, along with other necessary helper functions. If I have many big classes, however, I may put them in separate files.
In any case, there doesn’t exist a rigid rule saying things should be done absolutely one way. Sometimes splitting a program into several files is a good idea; sometimes it isn’t. You become more experienced as you program more often.
If you are working with large open source code base you can take a look at how they do things. The following is a snippet of include directives from a popular code base:
As you can see popular code base usually organizes their code in terms of functionality. We should do the same!◀ The More Functions, the Better?▶ Global Variables Versus Local Variables