Modular programming: Difference between revisions

Content deleted Content added
Reverted 1 edit by Wukuendo (talk): Rv cross article edit warring. Get talk page consensus to proceed
 
(8 intermediate revisions by 3 users not shown)
Line 1:
{{Short description|SoftwareOrganizing designcode techniqueinto modules}}
{{More citations needed|date=June 2022}}
'''Modular programming''' is a [[software designdevelopment]] techniquemindset that emphasizes separatingorganizing the functionality[[function (programming)|functions]] of a [[Computer program|programcodebase]] into independent, interchangeable '''modules''', such that{{endash}} each containsproviding everything necessary to execute only one aspect oran [[separationSeparation of concerns|"concern"aspect]] of thea [[computer program]] in its entirety without providing desiredother functionalityaspects.
 
A module [[interfaceInterface (computing)|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. Modular programming is closely related to [[structured programming]] and [[object-oriented programming]], all having the same goal of facilitating construction of large software programs and systems by [[Decomposition_Decomposition (computer_sciencecomputer science)|decomposition]] into smaller pieces, and all originating around the 1960s. While the historicalhistoric usageuse of these terms has been inconsistent, "''modular programming"'' now refers to the [[High-level programming language|high-level]] decomposition of the code of ana entirewhole program into pieces: ''structured programming'' to the [[Low-level programming language|low-level]] code use of structured [[control flow]], and ''object-oriented programming'' to the ''data'' use of [[Object (computer science)|objects]], a kind of [[data structure]].
 
In object-oriented programming, the use of interfaces as an architectural pattern to construct modules is known as [[interface-based programming]].{{citation needed|date=June 2015}}
Line 12:
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.<ref>{{cite journal |last=Lindsey |first=Charles H. |author-link=Charles H. Lindsey |date=Feb 1976 |title=Proposal for a Modules Facility in ALGOL 68 |url=http://archive.computerhistory.org/resources/text/algol/ACM_Algol_bulletin/1061719/p19-lindsey.pdf |url-status=dead |journal=ALGOL Bulletin |issue=39 |pages=20–29 |archive-url=https://web.archive.org/web/20160303230037/http://archive.computerhistory.org/resources/text/algol/ACM_Algol_bulletin/1061719/p19-lindsey.pdf |archive-date=2016-03-03 |access-date=2014-12-01}}</ref> 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 (programming language)|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 name]]s, like <code>M.a</code> to refer to object <code>a</code> from module <code>M</code>, 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 Sharp (programming language)|C#]], [[Dart (programming language)|Dart]], [[Go (programming language)|Go]], [[Java (programming language)|Java]], [[OCaml]], and [[Python (programming language)|Python]], among others. Modular programming became widespread from the 1980s: the original [[Pascal (programming language)|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 (programming language)|Ada]] (1980). The Extended Pascal ISO 10206:1990 standard kept closer to Modula2 in its modular support. [[Standard ML]] (1984)<ref>{{cite conference |author=David MacQueen |date=August 1984 |title=Modules for Standard ML |url=https://dl.acm.org/doi/pdf/10.1145/800055.802036 |book-title=LFP '84 Proceedings of the 1984 ACM Symposium on LISP and functional programming |pages=198–207|doi=10.1145/800055.802036 }}</ref> has one of the most complete module systems, including [[Standard ML#Module system|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 [[Object (computer science)|objects]] and [[Class (computer programming)|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 [[Package manager|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 (CLI)|assembly]] (as in [[.NET Framework|.NET]] languages]] like [[C Sharp (programming language)|C#]], [[F Sharp (programming language)|F#]], or [[Visual Basic (.NET)]]) or [[Package (package management system)manager|package]] (as in [[Dart (programming language)|Dart]], [[Go (programming language)|Go]], or [[Java (programming language)|Java]]) is sometimes used instead of '''module'''. In other implementations, these are distinct concepts; in [[Python (programming language)|Python]] a package is a collectionset of modules, while in [[Java 9]] the introduction of the [[Java Module System|new module concept]] (a collectionset of packages with enhanced access control) was implemented.
 
Furthermore, the term "package" has other uses in software (for example [[NuGet|.NET [[NuGet]] packages]]). A [[software component|component]] is a similar concept, but typically refers to a higher level; a component is a piece of a whole [[software system|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 planned to be large-scale, where a module is a collectionset of packages, which are in turn collectionssets of files.
 
Other terms for modules include '''unit''', used in [[Pascal (programming language)|Pascal]] dialects.
 
==Language support==
Languages that formally support the module concept include [[Ada (programming language)|Ada]], [[ALGOL]], [[BlitzMax]], [[C++]], [[C Sharp (programming language)|C#]], [[Clojure]], [[COBOL]], [[Common Lisp]], [[D (programming language)|D]], [[Dart (programming language)|Dart]], eC, [[Erlang (programming language)|Erlang]], [[Elixir (programming language)|Elixir]], [[Elm (programming language)|Elm]], [[F (programming language)|F]], [[F Sharp (programming language)|F#]], [[Fortran]], [[Go (programming language)|Go]], [[Haskell]], [[IBM/360]] [[IBM Basic assembly language and successors|Assembler]], [[Control Language]] (CL), [[IBM RPG]], [[Java (programming language)|Java]], [[Julia (programming language)|Julia]], [[MATLAB]], [[ML (programming language)|ML]], [[Modula]], [[Modula-2]], [[Modula-3]], Morpho, [[NEWP]], [[Oberon (programming language)|Oberon]], [[Oberon-2]], [[Objective-C]], [[OCaml]], several [[Pascal (programming language)|Pascal]] derivatives ([[Component Pascal]], [[Object Pascal]], [[Turbo Pascal]], [[UCSD Pascal]]), [[Perl]], [[PHP]], [[PL/I]], [[PureBasic]], [[Python (programming language)|Python]], [[R (programming language)|R]], [[Ruby (programming language)|Ruby]],<ref>{{Cite web|url=https://docs.ruby-lang.org/en/master/Module.html|title=class Module - Documentation for Ruby 3.5}}</ref> [[Rust (programming language)|Rust]], [[JavaScript]],<ref>[http://www.ecma-international.org/ecma-262/6.0/#sec-modules ECMAScript® 2015 Language Specification, 15.2 Modules]</ref> [[Visual Basic (.NET)]] and WebDNA.
 
In the Java programming language, the term "package" is used for the analog of modules in the JLS;<ref>James Gosling, Bill Joy, Guy Steele, Gilad Bracha, ''The Java Language Specification, Third Edition'', {{ISBN|0-321-24678-0}}, 2005. 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.</ref> — see [[Java package]]. "[[Java Module System|Modules]]", a kind of collectionset of packages, were introduced in [[Java 9]] as part of [http://openjdk.java.net/projects/jigsaw/ Project Jigsaw]; these were earlier called "superpackages" were planned for Java 7.
 
Conspicuous examples of languages that lack support for modules are [[C (programming language)|C]] and have been [[C++]] and Pascal in their original form, [[C (programming language)|C]] and [[C++]] do, however, allow separate compilation and declarative interfaces to be specified using [[header file]]s. Modules were added to Objective-C in [[iOS 7]] (2013); to C++ with [[C++20]],<ref>{{cite web|url=https://isocpp.org/files/papers/n4720.pdf|title=N4720: Working Draft, Extensions to C++ for Modules}}</ref> and Pascal was superseded by [[Modula]] and [[Oberon (programming language)|Oberon]], which included modules from the start, and various derivatives that included modules. [[JavaScript]] has had native modules since [[ECMAScript]] 2015. [[Precompiled header#Modules (C++)|C++ modules]] have allowed backwards compatibility with headers (with "header units"). Dialects of C allow for modules, for example [[Clang]] supports [[Modules (C++)#Clang C modules|modules for the C language]],<ref>{{Cite web|url=https://clang.llvm.org/docs/Modules.html|title=Modules|website=clang.llvm.org}}</ref> 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).
Line 47:
* {{Annotated link|Conway's law}}
* {{Annotated link|Coupling (computer science)}}
* {{Annotated link|Cross-cutting concern}}
* {{Annotated link|David Parnas}}
* {{Annotated link|Information hiding}} (encapsulation)
* {{Annotated link|Library (computing)}}
* {{Annotated link|List of system quality attributes}}
Line 54 ⟶ 55:
* {{Annotated link|Plug-in (computing)}}
* {{Annotated link|Snippet (programming)}}
* {{Annotated link|Structured Analysisanalysis}}
* {{Annotated link|Structured programming}}
* {{Annotated link|Cross-cutting concern}}
 
==References==