Search code examples
pascalfpc

What is the standard practice of organizing programs in files in Pascal?


I want to know how source file trees are organized in Pascal. From the Language Reference Guide from FPC, it seems that programs and units must be entirely contained in single files (unless the ${INCLUDE} directive is used).

I can think of several ways of organizing my programs:

  • Stick everything in one huge file (really don't like that),
  • Write several big unit files,
  • Write many small unit files (might turn into a spaghetti of dependencies),
  • Write several big units but split them into files using ${INCLUDE}

Using ${INCLUDE} at all seems like a bit of a hack to me, since a proper module system should make it unnecessary. On the other hand, I'm afraid that single-file modules would get big enough to be unwieldy.

How is this usually done in actual projects? Is there some option I have missed?


Solution

  • If you design your application properly then each UNIT should be a reasonable size and have a single well-defined purpose. Dependencies should be somewhat hierarchical and you can always group any number of closely related UNITs into a library if your application is large enough to warrant it.