Topic: abstract data type
Topic: function signature
Topic: generic operations and polymorphism
Topic: interface type
Topic: language extension via macros
Topic: macros
Topic: object-oriented methods
Topic: object-oriented prototypes
Topic: reusable programming
Topic: type parameter
| |
Summary
A template is a class with type parameters. A template may use methods and variables of the type. A container is a class that contains typed classes. A container may be restricted to a specific type via a template. A generic is a class with interface and module parameters. The C++ standard template library (STL) is a good example of templates.
A template or generic generates code for each combination of type parameters. They are like macros, without syntactic oddities. It may be difficult to debug templates since the code may be distant from the correspond template definitions.
An interface is a list of type signatures. Interfaces can take the place of templates or generics. (cbb 5/01)
Subtopic: templates
Quote: a template with type arguments expresses a commonality across types [»stroB_1991]
| Quote: templates capture abstractions while retaining performance; at instantiation, compiler has the calling and called context; instantiated only if needed [»dosrG1_2006]
| Quote: templates and type inheritance need each other. Without templates, derivation of similar class is tedious; without inheritance, templates lead to massive replication
| Quote: C++ Standard Template Library is good example of generic programming; data containers for user types; allows composition; compile time conversion of abstract type to concrete structures [»dehnJC4_1998]
| Quote: a C++ template is like a macro that obeys the scope, naming, and type rules of C++; the generated code is like separately compiled code [»stroB_1991]
| Quote: templates should not depend on global information; they will be used for unknown types in unknown contexts [»stroB_1991]
| Quote: use 'const', 'inline', and 'template' in place of macros and C's preprocessor constructs
| Quote: a Cornell_Program_Synthesizer template is a fixed, formatted pattern of keywords, punctuation, and indentation [»teitT9_1981]
| Quote: Cornell_Program_Synthesizer templates are abstract computational units; high level of abstraction; user never mired in syntactic detail [»teitT9_1981]
| Quote: a procedure template is a sequence of delimiters and parameter markers; for procedure calls by simple sentences [»grovLJ11_1982]
| Subtopic: container classes
Quote: a container class holds objects of another type (e.g., lists, arrays, sets); the type is irrelevant to the definer and crucial to the user [»stroB_1991]
| Quote: a base class is commonly used for container classes such as set, vector, and list; the container may be homogeneous or heterogeneous
| Quote: define a container class with a type parameter; e.g., a C++ template
| Quote: Eiffel's Data Structure Library defines a taxonomy for data structures by access method, traversing, and storage; e.g., CONTAINER class [»meyeB9_1990]
| Quote: represent a separate idea as a class; a separate entity as an object; commonality between classes as a base class; and a container of objects as a template
| Subtopic: function object
Quote: parameterize with function objects; inlined; no code for unused template functions; much faster than function pointers [»stroB12_2004]
| Subtopic: concept checking
Quote: want separate checking of templates and their uses; if check the template and its uses against the template's parameter concepts, then instantiations should type check [»dosrG1_2006]
| Quote: within a template, x*x is a dependent name that depends on the type parameter; * is an implicit parameter [»dosrG1_2006]
| Subtopic: Modula's generics for modules and interfaces
Quote: Modula-3's generics interact with interfaces and modules, not with the type system; avoids complications of every construct accepting every kind of entity as a parameter [»nelsG_1991]
| Quote: in the theory of dependent types, Modula-3's generic interface is a function from module-values to module-types and a generic module is a function from module-values to module-values [»nelsG_1991]
| Quote: a generic module in Module-3 only takes interfaces as parameters; independent, typechecked compilation [»nelsG_1991]
| Subtopic: mixins vs. templates
Quote: how to add first-class generic types to Java or C#; mixins fully type checked, unlike templates [»alleE10_2003]
| Subtopic: efficiency
Quote: high performance code using templates and arithmetic types such as FixPoint16; low-level details encoded in constants [»stroB12_2004]
| Quote: parameterize with function objects; inlined; no code for unused template functions; much faster than function pointers [»stroB12_2004]
| Subtopic: problems
Quote: templates and type inheritance need each other. Without templates, derivation of similar class is tedious; without inheritance, templates lead to massive replication
| Quote: templates can lead to mysterious compiler errors; debugging is difficult [»grayDN5_1998]
| Quote: while abstract, vector and string templates are a perilously thin veneer over a mass of complexity; too easy to punch through the veneer [»briaM1_2001]
|
Related Topics
Topic: abstract data type (64 items)
Topic: function signature (21 items)
Topic: generic operations and polymorphism (67 items)
Topic: interface type (50 items)
Topic: language extension via macros (23 items)
Topic: macros (22 items)
Topic: object-oriented methods (42 items)
Topic: object-oriented prototypes (39 items)
Topic: reusable programming (77 items)
Topic: type parameter (34 items)
|