How can I split up my monolithic programs into smaller, separate files?

前端 未结 6 1828

In all the code I see online, programs are always broken up into many smaller files. For all of my projects for school though, I\'ve gotten by by just having one gigantic C sour

6条回答
  •  面向向阳花
    2021-02-20 13:56

    is it just for ease of reading?

    No, it can also save you a lot of time compiling; when you change one source file, you only recompile that file, then relink, instead of recompiling everything. But the main point is dividing a program into a set of well-separated modules that are easier to understand and maintain than a single monolithic "blob".

    For starters, try to adhere to Rob Pike's rule that "data dominates": design your program around a bunch of data structures (struct's, usually) with operations on them. Put all the operations that belong to a single data structure into a separate module. Make all functions static that need not be called by functions outside the module.

提交回复
热议问题