Generic programming: Difference between revisions

Content deleted Content added
m Generics in Ada: WP:LINKs: add, update-standardize. Proper noun > MOS:CAPS.
WP:LINKs: adds, update-standardizes, needless WP:PIPEs > WP:NOPIPEs. WP:BADEMPHASIS MOS:QUOTEMARKS > WP:ITALICs.
Line 2:
{{Distinguish|Genetic programming}}
{{Use dmy dates|date=November 2020}}
'''Generic programming''' is a style of [[computer programming]] in which [[algorithm]]s are written in terms of [[data type]]s ''to-be-specified-later'' that are then ''instantiated'' when needed for specific types provided as [[parameterParameter (computer programming)|parameters]]. This approach, pioneered byin the [[programming language]] [[ML (programming language)|ML]] programming language in 1973,<ref name="Lee2008">
{{cite book
| lastlast1=Lee
| firstfirst1=Kent D.
| date=15 December 2008
| title=Programming Languages: An Active Learning Approach
| url=https://books.google.com/books?id=OuW5dC2O99AC&pg=PA9
| date=15 December 2008
| publisher=Springer Science & Business Media
| isbn=978-0-387-79422-8
| pages=9–10}}</ref><ref>{{cite conference |last1=Milner |first1=R. |author1-link=Robin Milner |last2=Morris |first2=L. |last3=Newey |first3=M. |year=1975 |title=A Logic for Computable Functions with Reflexive and Polymorphic Types |book-title=Proceedings of the Conference on Proving and Improving Programs}}</ref> permits writing common [[functionFunction (computer science)|functions]] or [[typedata (computer science)|type]]s that differ only in the [[Set (mathematics)|set]] of types on which they operate when used, thus reducing [[duplicate code]].
 
Generic programming was introduced to the mainstream with [[Ada (programming language)|Ada]] in 1977. With [[Template (C++)|templates]] in [[C++]], generic programming became part of the repertoire of professional [[Library (computing)|library]] design. The techniques were further improved and ''parameterized types'' were introduced in the influential 1994 book ''[[Design Patterns]]''.<ref name="GoF">
{{cite book |last1=Gamma
|first1=Erich
Line 30:
}}</ref>
 
New techniques were introduced by [[Andrei Alexandrescu]] in his 2001 book ''[[Modern C++ Design|Modern C++ Design]]: Generic Programming and Design Patterns Applied]]''. Subsequently, [[D (programming language)|D]] implemented the same ideas.
 
Such software entities are known as ''generics'' in [[Ada (programming language)|Ada]], [[C Sharp (programming language)|C#]], [[Delphi (software)|Delphi]], [[Eiffel (programming language)|Eiffel]], [[F Sharp (programming language)|F#]], [[Java (programming language)|Java]], [[Nim (programming language)|Nim]], [[Python (programming language)|Python]], [[Go (programming language)|Go]], [[Rust (programming language)|Rust]], [[Swift (programming language)|Swift]], [[TypeScript]], and [[Visual Basic (.NET)]]. They are known as ''[[parametric polymorphism]]'' in [[ML (programming language)|ML]], [[Scala (programming language)|Scala]], [[Julia (programming language)|Julia]], and [[Haskell]]. (Haskell terminology also uses the term "''generic"'' for a related but somewhat different concept.)
 
The term ''generic programming'' was originally coined by [[David Musser]] and [[Alexander Stepanov]]{{sfn|Musser|Stepanov|1989}} in a more specific sense than the above, to describe a programming paradigm in which fundamental requirements on data types are abstracted from across concrete examples of algorithms and [[data structure]]s and formalized as [[Concept (generic programming)|concepts]], with [[generic function]]s implemented in terms of these concepts, typically using language genericity mechanisms as described above.
Line 106:
</syntaxhighlight>
 
The C++ <code>template</code> construct used above is widely cited{{Citation needed|date=May 2010}} as the genericity construct that popularized the notion among programmers and [[List of programming language researchers|language designers]] and supports many generic programming idioms. The D programming language also offers fully generic-capable templates based on the C++ precedent but with a simplified syntax. The Java programming language has provided genericity facilities syntactically based on C++'s since the introduction of [[Java Platform, Standard Edition]] (J2SE) 5.0.
 
[[C Sharp (programming language)|C#]] 2.0, [[Oxygene (programming language)|Oxygene]] 1.5]] (formerly Chrome) and [[Visual Basic (.NET)]] 2005 have constructs that exploit the support for generics present in Microsoft [[.NET Framework]] since version 2.0.
 
====Generics in Ada====