Modular programming is a
software design
Software design is the process of conceptualizing how a software system will work before it is implemented or modified.
Software design also refers to the direct result of the design process the concepts of how the software will work which co ...
technique that emphasizes separating the functionality of a
program into independent, interchangeable modules, such that each contains everything necessary to execute only one aspect or
"concern" of the desired functionality.
A module
interface expresses the elements that are provided and required by the module. The elements defined in the interface are detectable by other modules. The
implementation
Implementation is the realization of an application, execution of a plan, idea, scientific modelling, model, design, specification, Standardization, standard, algorithm, policy, or the Management, administration or management of a process or Goal ...
contains the working code that corresponds to the elements declared in the interface. Modular programming is closely related to
structured programming and
object-oriented programming
Object-oriented programming (OOP) is a programming paradigm based on the concept of '' objects''. Objects can contain data (called fields, attributes or properties) and have actions they can perform (called procedures or methods and impl ...
, all having the same goal of facilitating construction of large software programs and systems by
decomposition into smaller pieces, and all originating around the 1960s. While the historical usage of these terms has been inconsistent, "modular programming" now refers to the high-level decomposition of the code of an entire program into pieces: structured programming to the low-level code use of structured
control flow, and object-oriented programming to the ''data'' use of
objects, a kind of
data structure
In computer science, a data structure is a data organization and storage format that is usually chosen for Efficiency, efficient Data access, access to data. More precisely, a data structure is a collection of data values, the relationships amo ...
.
In object-oriented programming, the use of interfaces as an architectural pattern to construct modules is known as
interface-based programming.
History
Modular programming, in the form of subsystems (particularly for I/O) and software libraries, dates to early software systems, where it was used for
code reuse. Modular programming per se, with a goal of modularity, developed in the late 1960s and 1970s, as a larger-scale analog of the concept of
structured programming (1960s). The term "modular programming" dates at least to the National Symposium on Modular Programming, organized at the Information and Systems Institute in July 1968 by
Larry Constantine; other key concepts were
information hiding (1972) and
separation of concerns (SoC, 1974).
Modules were not included in the original specification for
ALGOL 68
ALGOL 68 (short for ''Algorithmic Language 1968'') is an imperative programming language member of the ALGOL family that was conceived as a successor to the ALGOL 60 language, designed with the goal of a much wider scope of application and ...
(1968), but were included as extensions in early implementations,
ALGOL 68-R
ALGOL 68-R was the first implementation of the Algorithmic Language ALGOL 68.
In December 1968, the report on the Algorithmic Language ALGOL 68 was published. On 20–24 July 1970 a working conference was arranged by the International Federati ...
(1970) and
ALGOL 68C (1970), and later formalized. One of the first languages designed from the start for modular programming was the short-lived
Modula
The Modula programming language is a descendant of the Pascal language. It was developed in Switzerland, at ETH Zurich, in the mid-1970s by Niklaus Wirth, the same person who designed Pascal. The main innovation of Modula over Pascal is a mo ...
(1975), by
Niklaus Wirth
Niklaus Emil Wirth ( IPA: ) (15 February 1934 – 1 January 2024) was a Swiss computer scientist. He designed several programming languages, including Pascal, and pioneered several classic topics in software engineering. In 1984, he won the Tu ...
. Another early modular language was
Mesa (1970s), by
Xerox PARC, and Wirth drew on Mesa as well as the original Modula in its successor,
Modula-2 (1978), which influenced later languages, particularly through its successor,
Modula-3
Modula-3 is a programming language conceived as a successor to an upgraded version of Modula-2 known as Modula-2+. It has been influential in research circles (influencing the designs of languages such as Java, C#, Python and Nim), but it ha ...
(1980s). Modula's use of dot-
qualified names, like
M.a
to refer to object
a
from module
M
, coincides with notation to access a field of a record (and similarly for attributes or methods of objects), and is now widespread, seen in
C++,
C#,
Dart,
Go,
Java
Java is one of the Greater Sunda Islands in Indonesia. It is bordered by the Indian Ocean to the south and the Java Sea (a part of Pacific Ocean) to the north. With a population of 156.9 million people (including Madura) in mid 2024, proje ...
,
OCaml, and
Python, among others. Modular programming became widespread from the 1980s: the original
Pascal language (1970) did not include modules, but later versions, notably
UCSD Pascal (1978) and
Turbo Pascal (1983) included them in the form of "units", as did the Pascal-influenced
Ada (1980). The Extended Pascal ISO 10206:1990 standard kept closer to Modula2 in its modular support.
Standard ML (1984) has one of the most complete module systems, including
functors (parameterized modules) to map between modules.
In the 1980s and 1990s, modular programming was overshadowed by and often conflated with
object-oriented programming
Object-oriented programming (OOP) is a programming paradigm based on the concept of '' objects''. Objects can contain data (called fields, attributes or properties) and have actions they can perform (called procedures or methods and impl ...
, particularly due to the popularity of C++ and Java. For example, the C family of languages had support for objects and classes in C++ (originally
C with Classes, 1980) and Objective-C (1983), only supporting modules 30 years or more later. Java (1995) supports modules in the form of packages, though the primary unit of code organization is a class. However, Python (1991) prominently used both modules and objects from the start, using modules as the primary unit of code organization and "packages" as a larger-scale unit; and
Perl 5 (1994) includes support for both modules and objects, with a vast array of modules being available from
CPAN (1993).
OCaml (1996) followed ML by supporting modules and functors.
Modular programming is now widespread, and found in virtually all major languages developed since the 1990s. The relative importance of modules varies between languages, and in class-based object-oriented languages there is still overlap and confusion with classes as a unit of organization and encapsulation, but these are both well-established as distinct concepts.
Terminology
The term
assembly (as in
.NET languages like
C#,
F# or
Visual Basic .NET) or
package (as in
Dart,
Go or
Java
Java is one of the Greater Sunda Islands in Indonesia. It is bordered by the Indian Ocean to the south and the Java Sea (a part of Pacific Ocean) to the north. With a population of 156.9 million people (including Madura) in mid 2024, proje ...
) is sometimes used instead of module. In other implementations, these are distinct concepts; in
Python a package is a collection of modules, while in
Java 9 the introduction of the
new module concept (a collection of packages with enhanced access control) was implemented.
Furthermore, the term "package" has other uses in software (for example
.NET NuGet packages). A
component is a similar concept, but typically refers to a higher level; a component is a piece of a whole
system
A system is a group of interacting or interrelated elements that act according to a set of rules to form a unified whole. A system, surrounded and influenced by its open system (systems theory), environment, is described by its boundaries, str ...
, while a module is a piece of an individual program. The scale of the term "module" varies significantly between languages; in Python it is very small-scale and each file is a module, while in
Java 9 it is planned to be large-scale, where a module is a collection of packages, which are in turn collections of files.
Other terms for modules include unit, used in
Pascal dialects.
Language support
Languages that formally support the module concept include
Ada,
ALGOL,
BlitzMax,
C++,
C#,
Clojure,
COBOL,
Common Lisp,
D,
Dart, eC,
Erlang,
Elixir
An elixir is a sweet liquid used for medical purposes, to be taken orally and intended to cure one's illness. When used as a dosage form, pharmaceutical preparation, an elixir contains at least one active ingredient designed to be taken orall ...
,
Elm,
F,
F#,
Fortran,
Go,
Haskell,
IBM/360 Assembler,
Control Language (CL),
IBM RPG,
Java
Java is one of the Greater Sunda Islands in Indonesia. It is bordered by the Indian Ocean to the south and the Java Sea (a part of Pacific Ocean) to the north. With a population of 156.9 million people (including Madura) in mid 2024, proje ...
,
Julia,
MATLAB,
ML,
Modula
The Modula programming language is a descendant of the Pascal language. It was developed in Switzerland, at ETH Zurich, in the mid-1970s by Niklaus Wirth, the same person who designed Pascal. The main innovation of Modula over Pascal is a mo ...
,
Modula-2,
Modula-3
Modula-3 is a programming language conceived as a successor to an upgraded version of Modula-2 known as Modula-2+. It has been influential in research circles (influencing the designs of languages such as Java, C#, Python and Nim), but it ha ...
, Morpho,
NEWP,
Oberon,
Oberon-2,
Objective-C
Objective-C is a high-level general-purpose, object-oriented programming language that adds Smalltalk-style message passing (messaging) to the C programming language. Originally developed by Brad Cox and Tom Love in the early 1980s, it was ...
,
OCaml, several
Pascal derivatives (
Component Pascal,
Object Pascal,
Turbo Pascal,
UCSD Pascal),
Perl,
PHP,
PL/I,
PureBasic,
Python,
R,
Ruby,
Rust,
JavaScript
JavaScript (), often abbreviated as JS, is a programming language and core technology of the World Wide Web, alongside HTML and CSS. Ninety-nine percent of websites use JavaScript on the client side for webpage behavior.
Web browsers have ...
,
Visual Basic (.NET) and WebDNA.
In the Java programming language, the term "package" is used for the analog of modules in the JLS; — see
Java package. "
Modules", a kind of collection of packages, were introduced in
Java 9 as part o
Project Jigsaw these were earlier called "superpackages" were planned for Java 7.
Conspicuous examples of languages that lack support for modules are
C and have been
C++ and Pascal in their original form,
C and
C++ do, however, allow separate compilation and declarative interfaces to be specified using
header files. Modules were added to Objective-C in
iOS 7 (2013); to C++ with
C++20, and Pascal was superseded by
Modula
The Modula programming language is a descendant of the Pascal language. It was developed in Switzerland, at ETH Zurich, in the mid-1970s by Niklaus Wirth, the same person who designed Pascal. The main innovation of Modula over Pascal is a mo ...
and
Oberon, which included modules from the start, and various derivatives that included modules.
JavaScript
JavaScript (), often abbreviated as JS, is a programming language and core technology of the World Wide Web, alongside HTML and CSS. Ninety-nine percent of websites use JavaScript on the client side for webpage behavior.
Web browsers have ...
has had native modules since
ECMAScript
ECMAScript (; ES) is a standard for scripting languages, including JavaScript, JScript, and ActionScript. It is best known as a JavaScript standard intended to ensure the interoperability of web pages across different web browsers. It is stan ...
2015.
C++ modules have allowed backwards compatibility with headers (with "header units"). Dialects of C allow for modules, for example
Clang supports modules for the C language,
though the syntax and semantics of Clang C modules differ from C++ modules significantly.
Modular programming can be performed even where the programming language lacks explicit syntactic features to support named modules, like, for example, in C. This is done by using existing language features, together with, for example,
coding conventions,
programming idioms and the physical code structure.
IBM i also uses modules when programming in the
Integrated Language Environment (ILE).
Key aspects
With modular programming,
concerns are separated such that modules perform logically discrete functions, interacting through well-defined interfaces. Often modules form a
directed acyclic graph (DAG); in this case a cyclic dependency between modules is seen as indicating that these should be a single module. In the case where modules do form a DAG they can be arranged as a hierarchy, where the lowest-level modules are independent, depending on no other modules, and higher-level modules depend on lower-level ones. A particular program or library is a top-level module of its own hierarchy, but can in turn be seen as a lower-level module of a higher-level program, library, or system.
When creating a modular system, instead of creating a monolithic application (where the smallest component is the whole), several smaller modules are written separately so when they are composed together, they construct the executable application program. Typically, these are also
compiled separately, via
separate compilation, and then linked by a
linker. A
just-in-time compiler may perform some of this construction "on-the-fly" at
run time.
These independent functions are commonly classified as either program control functions or specific task functions. Program control functions are designed to work for one program. Specific task functions are closely prepared to be applicable for various programs.
This makes modular designed systems, if built correctly, far more reusable than a traditional monolithic design, since all (or many) of these modules may then be reused (without change) in other projects. This also facilitates the "breaking down" of projects into several smaller projects. Theoretically, a modularized software project will be more easily assembled by large teams, since no team members are creating the whole system, or even need to know about the system as a whole. They can focus just on the assigned smaller task.
See also
*
*
*
*
*
*
* (encapsulation)
*
*
*
*
*
*
*
*
References
External links
How To Decompose a System into ModulesSMC Platform
{{DEFAULTSORT:Modular Programming
Programming paradigms
Programming