This articleneeds additional citations forverification. Please helpimprove this article byadding citations to reliable sources. Unsourced material may be challenged and removed. Find sources: "Modular programming" – news ·newspapers ·books ·scholar ·JSTOR(June 2022) (Learn how and when to remove this message) |
Modular programming is asoftware design technique that emphasizes separating the functionality of aprogram into independent, interchangeablemodules, such that each contains everything necessary to execute only one aspect or"concern" of the desired functionality.
A moduleinterface expresses the elements that are provided and required by the module. The elements defined in the interface are detectable by other modules. Theimplementation contains the working code that corresponds to the elements declared in the interface. Modular programming is closely related tostructured programming andobject-oriented programming, all having the same goal of facilitating construction of large software programs and systems bydecomposition 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 structuredcontrol flow, and object-oriented programming to thedata use ofobjects, a kind ofdata structure.
In object-oriented programming, the use of interfaces as an architectural pattern to construct modules is known asinterface-based programming.[citation needed]
Modular programming, in the form of subsystems (particularly for I/O) and software libraries, dates to early software systems, where it was used forcode 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 ofstructured 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 byLarry Constantine; other key concepts wereinformation hiding (1972) andseparation of concerns (SoC, 1974).
Modules were not included in the original specification forALGOL 68 (1968), but were included as extensions in early implementations,ALGOL 68-R (1970) andALGOL 68C (1970), and later formalized.[1] One of the first languages designed from the start for modular programming was the short-livedModula (1975), byNiklaus Wirth. Another early modular language wasMesa (1970s), byXerox 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 (1980s). Modula's use of dot-qualified names, likeM.a
to refer to objecta
from moduleM
, coincides with notation to access a field of a record (and similarly for attributes or methods of objects), and is now widespread, seen inC++,C#,Dart,Go,Java,OCaml, andPython, among others. Modular programming became widespread from the 1980s: the originalPascal language (1970) did not include modules, but later versions, notablyUCSD Pascal (1978) andTurbo Pascal (1983) included them in the form of "units", as did the Pascal-influencedAda (1980). The Extended Pascal ISO 10206:1990 standard kept closer to Modula2 in its modular support.Standard ML (1984)[2] has one of the most complete module systems, includingfunctors (parameterized modules) to map between modules.
In the 1980s and 1990s, modular programming was overshadowed by and often conflated withobject-oriented programming, particularly due to the popularity of C++ and Java. For example, the C family of languages had support for objects and classes in C++ (originallyC 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; andPerl 5 (1994) includes support for both modules and objects, with a vast array of modules being available fromCPAN (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.
The termassembly (as in.NET languages likeC#,F# orVisual Basic .NET) orpackage (as inDart,Go orJava) is sometimes used instead ofmodule. In other implementations, these are distinct concepts; inPython a package is a collection of modules, while inJava 9 the introduction of thenew 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). Acomponent is a similar concept, but typically refers to a higher level; a component is a piece of a wholesystem, 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 inJava 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 includeunit, used inPascal dialects.
Languages that formally support the module concept includeAda,ALGOL,BlitzMax,C++,C#,Clojure,COBOL,Common Lisp,D,Dart, eC,Erlang,Elixir,Elm,F,F#,Fortran,Go,Haskell,IBM/360Assembler,Control Language (CL),IBM RPG,Java,Julia,MATLAB,ML,Modula,Modula-2,Modula-3, Morpho,NEWP,Oberon,Oberon-2,Objective-C,OCaml, severalPascal derivatives (Component Pascal,Object Pascal,Turbo Pascal,UCSD Pascal),Perl,PHP,PL/I,PureBasic,Python,R,Ruby,[3]Rust,JavaScript,[4]Visual Basic (.NET) and WebDNA.
In the Java programming language, the term "package" is used for the analog of modules in the JLS;[5] — seeJava package. "Modules", a kind of collection of packages, were introduced inJava 9 as part ofProject Jigsaw; these were earlier called "superpackages" were planned for Java 7.
Conspicuous examples of languages that lack support for modules areC and have beenC++ and Pascal in their original form,C andC++ do, however, allow separate compilation and declarative interfaces to be specified usingheader files. Modules were added to Objective-C iniOS 7 (2013); to C++ withC++20,[6] and Pascal was superseded byModula andOberon, which included modules from the start, and various derivatives that included modules.JavaScript has had native modules sinceECMAScript 2015.C++ modules have allowed backwards compatibility with headers (with "header units"). Dialects of C allow for modules, for exampleClang supports modules for the C language,[7] 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 theIntegrated Language Environment (ILE).
With modular programming,concerns are separated such that modules perform logically discrete functions, interacting through well-defined interfaces. Often modules form adirected 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 alsocompiled separately, viaseparate compilation, and then linked by alinker. Ajust-in-time compiler may perform some of this construction "on-the-fly" atrun 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.