How should functions be apportioned among source files?

Q

How should functions be apportioned among source files?

✍: Guest

A

Usually, related functions are put together in one file. Sometimes (as when developing libraries) it is appropriate to have exactly one source file (and, consequently, one object module) per independent function. Other times, and especially for some programmers, numerous source files can be cumbersome, and it may be tempting (or even appropriate) to put most or all of a program in a few big source files. When it is desired to limit the scope of certain functions or global variables by using the static keyword, source file layout becomes more constrained: the static functions and variables and the functions sharing access to them must all be in the same file.
In other words, there are a number of tradeoffs, so it is difficult to give general rules.

2015-05-18, 1060👍, 0💬