• Constants and variables
  • If-then-else-elseif statements
  • Procedures and loops
  • The very fact that a program is comprised of two or more files (instead just from one large file)

Each one of these features indicates "modularity" but what really makes a program modular by any rigorous standard of computer science (if there is one)?

  • 4
    $\begingroup$ Why would constants, variables or conditional statements indicate modularity? Anyway, no, there's no precise definition of modularity. $\endgroup$
    – Juho
    Jul 25, 2021 at 20:48
  • $\begingroup$ @Juho because they are "pieces" that can be used in basically any other "file", I would assume. $\endgroup$ Jul 25, 2021 at 20:49
  • $\begingroup$ But they don't necessarily do that whereas maybe using multiple source code files do. $\endgroup$
    – Juho
    Jul 26, 2021 at 11:51
  • $\begingroup$ @Juho I am sorry, I didn't understand the second part of your comment whereas maybe using multiple source code files do please try to rephrase this (I am not a native speaker of English, this might be the reason?). $\endgroup$ Jul 26, 2021 at 15:56
  • $\begingroup$ What I meant was that even if you use constants, variables and conditional statements, your code is not necessarily modular at all. But if you split your code to multiple source files, then that's more likely a sign of modularity. $\endgroup$
    – Juho
    Jul 26, 2021 at 16:07

2 Answers 2


Barbara Liskov has done research in the area of modularity:

  • A program is a collection of modules
  • Each module has an interface, described by a specification
    • A module’s implementation is correct if it meets the specification
    • A using module depends only on the specification

Modules provide the advantage of:

  • Local reasoning
  • Modifiability
  • Independent development

So modules is what make a program modular. You can identify modules by finding units of code that fulfill the above criteria.

For instance, a sort function that sorts an array is a module. The sort function has a clear specification (that can be stated formally easily). You should be able to shows its correctness or develop and modify it independently of the rest of the program and only by considering that specification.

If you have identified a module, you should also be able to replace the entire module with another implementation following the same specification without changing the semantics or correctness of your program.

However, not all programs feature equally good modularity. In the 70s the only type of modules were procedures and programs would often be hard to reason about.

According to Liskov this led to the development of Abstract Data Types:

  • Abstract data types
    • A set of operations
    • And a set of objects
    • The operations provide the only way to use the objects

Obviously, these are also characteristics of object-oriented programming, which is indeed a later implementation of the same ideas.

To give another example: A class implementing a dictionary (hash table). You can specify which operations (e.g. set, get, delete) should be provided, what these operations do, what their time complexity is etc. and then develop this module independently of the rest of the program. Note, that you do not need classes to do that.

Liskov also somewhat famously said:

Modularity based on abstraction is the way things are done.

Abstraction here means not exposing or requiring unnecessary details. For instance, a dictionary specification in a scripting language (Python for example) should not specify the exact number of bytes required to store each element. This doesn't help users of the module and makes it harder to develop the module.

However, the level of abstraction depends on the application. When developing a spacecraft the right level of abstraction might indeed require specifying the amount of bytes used.

When people speak about modularity in software development today, they will typically mean the "modularity based on abstraction" Liskov describes. If modules are not abstracted properly, it might even be almost impossible to identify them.


A remarkable definition of modularity from a paper about Ecology:

Modularity is a system property which measures the degree to which densely connected compartments within a system can be decoupled into separate communities or clusters which interact more among themselves rather than other communities.

As for software design, this Wikipage says, that:

... modularity refers to a logical partitioning of the "software design" that allows complex software to be manageable for the purpose of implementation and maintenance. The logic of partitioning may be based on related functions, implementation considerations, data links, or other criteria.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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