Modular programming

Short description: Organizing code into modules

Modular programming is a programming paradigm that emphasizes organizing the functions of a codebase into independent modules – each providing an aspect of a computer program in its entirety without providing other aspects.

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 contains the working code that corresponds to the elements declared in the interface.

## Contents

* 1 Related
* 2 History
* 3 Terminology
* 4 Language support
* 5 Key aspects
* 6 See also
* 7 References
* 8 External links

## Related

Modular programming differs from but is related to other programming paradigms, including:

Structured programming
Concerned with relatively low-level code structures for control flow.

Object-oriented programming
Like modular programming, concerned with facilitating software construction via decomposition but with specific focus on organizing code as objects that combine state with associated functionality.

Interface-based programming
The use of interfaces as an architectural pattern to construct modules.

## 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 (1968), but were included as extensions in early implementations, ALGOL 68-R (1970) and ALGOL 68C (1970), and later formalized.[1] One of the first languages designed from the start for modular programming was the short-lived Modula (1975), by Niklaus Wirth. 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 (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, 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)[2] 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, 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) or package (as in Dart, Go, or Java) is sometimes used instead of module. In other implementations, these are distinct concepts; in Python a package is a set of modules, while in Java 9 the introduction of the Java Platform Module System, in which a new module concept, involving a set of packages with enhanced access control, was implemented. (These packages are not the same as other sorts of packages in software, such as package manager packages.)

In Java, the term package is used for the module concept in the Java language specification.[3] The module, a kind of set of a package, was introduced in Java 9.

In some Pascal dialects, the term unit is used for the module concept.

A component is a similar concept, but typically refers to a higher level; a component is a piece of a whole system, 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 large-scale, where a module is a set of packages, which are in turn sets of files.

## Language support

Languages that formally support the module concept include Ada, ALGOL, BlitzMax, C++, C#, Clojure, COBOL, Common Lisp, D, Dart, eC, Erlang, Elixir, Elm, F, F#, Fortran, Go, Haskell, IBM/360 Assembler, IBM System/38 and AS/400 Control Language (CL), IBM RPG, Java, Julia, MATLAB, ML, Modula, Modula-2, Modula-3, Morpho, NEWP, Oberon, Oberon-2, Objective-C, OCaml, several Pascal derivatives (Component Pascal, Object Pascal, Turbo Pascal, UCSD Pascal), Perl, PHP, PL/I, PureBasic, Python, R, Ruby,[4] Rust, JavaScript,[5] Visual Basic (.NET) and WebDNA.

Conspicuous examples of languages that lack support for modules are C, and in their original forms, C++ and Pascal. C and C++ do, however, allow separate compilation and declarative interfaces to be specified using header files which is commonly considered modularization. Modules were added to Objective-C in iOS 7 (2013); to C++ with C++20,[6] and Pascal was superseded by Modula and Oberon, which included modules from the start, and various derivatives that included modules. JavaScript has had native modules since ECMAScript 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,[7] though the syntax and semantics of Clang C modules differ from C++ modules.

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

* Architecture description language - Standardized language on architecture description
* Cohesion (computer science) - Degree to which elements within a module belong together
* Component-based software engineering - Branch of software engineering
* Conway's law - Adage linking organization and system structure
* Coupling (computer science)
* Cross-cutting concern - Concept in aspect-oriented software development
* David Parnas
* Information hiding - Principle of computer program design
* Library (computing) - Collection of non-volatile resources used by computer programs
* List of system quality attributes - Non-functional requirements for system evaluation
* Modular design - Design approach
* Plug-in (computing) - Software component that adds a specific feature to an existing software application
* Snippet (programming) - Small region of re-usable source code, machine code, or text
* Structured analysis - Software engineering method

## References

1. ↑ Lindsey, Charles H. (Feb 1976). "Proposal for a Modules Facility in ALGOL 68". ALGOL Bulletin (39): 20–29. http://archive.computerhistory.org/resources/text/algol/ACM_Algol_bulletin/1061719/p19-lindsey.pdf. Retrieved 2014-12-01.
2. ↑ David MacQueen (August 1984). "Modules for Standard ML". pp. 198–207. doi:10.1145/800055.802036. https://dl.acm.org/doi/pdf/10.1145/800055.802036.
3. ↑ James Gosling; Bill Joy; Guy Steele; Gilad Bracha (2005). The Java Language Specification, Third Edition. ISBN 0-321-24678-0. In the Introduction, it is stated "Chapter 7 describes the structure of a program, which is organized into packages similar to the modules of Modula." The word module has no special meaning in Java.
4. ↑ "class Module - Documentation for Ruby 3.5". https://docs.ruby-lang.org/en/master/Module.html.
5. ↑ ECMAScript® 2015 Language Specification, 15.2 Modules
6. ↑ "N4720: Working Draft, Extensions to C++ for Modules". https://isocpp.org/files/papers/n4720.pdf.
7. ↑ "Modules". https://clang.llvm.org/docs/Modules.html.

## External links

* How To Decompose a System into Modules
* SMC Platform

* v
* t
* e

Programming paradigms

Imperative|

| Structured|

* Jackson structures
* Block-structured
* Modular
* Non-structured
* Procedural
* Programming in the large and in the small
* Design by contract
* Invariant-based
* Nested function

|

Object-oriented|

* Class-based, Prototype-based, Object-based
* Agent
* Immutable object
* Persistent
* Uniform function call syntax

Declarative|

| Functional|

* Recursive
* Anonymous function (Partial application)
* Higher-order
* Purely functional
* Total
* Strict
* GADTs
* Dependent types
* Functional logic
* Point-free style
* Expression-oriented
* Applicative, Concatenative
* Function-level, Value-level
* Monad

|

Dataflow|

* Flow-based
* Reactive (Functional reactive)
* Signals
* Streams
* Synchronous

Logic|

* Abductive logic
* Answer set
* Constraint (Constraint logic)
* Inductive logic
* Nondeterministic
* Ontology
* Probabilistic logic
* Query

Domain-
specific
language
(DSL)|

* Algebraic modeling
* Array
* Automata-based (Action)
* Command (Spacecraft)
* Differentiable
* End-user
* Grammar-oriented
* Interface description
* Language-oriented
* List comprehension
* Low-code
* Modeling
* Natural language
* Non-English-based
* Page description
* Pipes and filters
* Probabilistic
* Quantum
* Scientific
* Scripting
* Set-theoretic
* Simulation
* Stack-based
* System
* Tactile
* Templating
* Transformation (Graph rewriting, Production, Pattern)
* Visual

Concurrent,
parallel|

* Actor-based
* Automatic mutual exclusion
* Choreographic programming
* Concurrent logic (Concurrent constraint logic)
* Concurrent OO
* Macroprogramming
* Multitier programming
* Organic computing
* Parallel programming models
* Partitioned global address space
* Process-oriented
* Relativistic programming
* Service-oriented
* Structured concurrency

Metaprogramming|

* Attribute-oriented
* Automatic (Inductive)
* Dynamic
* Extensible
* Generic
* Homoiconicity
* Interactive
* Macro (Hygienic)
* Metalinguistic abstraction
* Multi-stage
* Program synthesis (Bayesian, by demonstration, by example, vibe coding)
* Reflective
* Self-modifying code
* Symbolic
* Template

Separation
of concerns|

* Aspects
* Components
* Data-driven
* Data-oriented
* Event-driven
* Features
* Literate
* Roles
* Subjects

Comparisons/Lists|

Comparison (multi-paradigm, object-oriented, functional), List (OO, by type)

0.00

(0 votes)

Original source: https://en.wikipedia.org/wiki/Modular programming. Read more

|

Retrieved from "https://handwiki.org/wiki/index.php?title=Modular_programming&oldid=3876527"
*[v]: View this template
*[t]: Discuss this template
*[e]: Edit this template