14

It appears the tag has been merged into . I can't find any discussion on Meta from the time of this decision (only this unanswered/tangential question) but I'd like to propose un-merging them.

Generic programming is a different (and arguably opposite) concept than what most languages call generics; it's got more in common with what those languages typically call reflection (or introspection). The tag wiki for generics even specifically calls out this distinction:

This also means that generics are not well suited for generic-programming, which typically relies on an ability to tailor generic algorithms for specific parameter types (again using a C++ example, pointers are usable with any generic algorithm expecting arguments to be iterators).

Since people are asking, let me try to briefly describe the distinction as I see it.

  • Generics (aka type parameters or parametric polymorphism) is a specific language feature, present in many languages, which allows you to write functions and datatypes which are agnostic to the type of data that it's being applied to.
    • List<T> behaves uniformly, whether T is instantiated to int or string.
    • Generics are an abstraction tool; the parameterised code treats the type parameter opaquely.
  • Generic programming is a style of programming (not a single language feature) wherein operations are automatically derived for a given datatype, based on the type's structural properties or on the interface(s) it implements.
    • JSON serialisation libraries are often implemented in a generic programming style, for example. The C++ iterators example is also apt — various STL operations can be specialised to a given container as long as it implements the iterator interface.
    • Generic programming is about specialisation; generic code typically works by inspecting the datatype (at runtime or otherwise) for which it's being invoked.
  • Generic programming can be implemented using whatever (meta)programming tools the language has to hand. In C++ you might use template metaprogramming; in Python you might use introspection; in Agda you might use universes.
    • But, per the quote above, generics taken alone (ie, without extensions such as concepts/bounds) are typically a bad fit for generic programming since type parameters are treated uniformly.

Generic is clearly one of those terms which means different things depending who you're talking to. But that's a reason to remove the synonym, not retain it!

12
  • 1
    I suspect a large majority of the questions in generics are legitimately about generics (in Java and similar languages) and not about generic programming which is somewhat more niche. Commented May 7 at 3:42
  • 7
    Generic programming - "Generic programming is a style of computer programming in which algorithms are written in terms of data types to-be-specified-later that are then instantiated when needed for specific types provided as parameters. ... Early examples of this programming approach were implemented in Scheme and Ada, Commented May 7 at 10:44
  • 4
    cont' - although the best known example is the Standard Template Library (STL), which developed a theory of iterators that is used to decouple sequence data structures and the algorithms operating on them." ("STL is a software library ... for the C++ programming language that influenced many parts of the C++ Standard Library.") Commented May 7 at 10:47
  • 11
    What is generic programming and why does it need its own tag? I've never heard of the concept, but it sounds, well, generic. In fact, a quick bit of googling seems to indicate they are the same thing, at least if the Wikipedia page for generic programming is accurate.
    – TylerH
    Commented May 7 at 16:00
  • 5
    As Tyler pointed out, the wiki for Generic Programming describes "generics", they seem to be synonyms. Here is a PDF from 2001, "Design and Implementation of Generics for the .NET Common Language Runtime - Andrew Kennedy, Don Syme, Microsoft Research, Cambridge, U.K." that says, "Parametric polymorphism is a well-established programming language feature whose advantages over dynamic approaches to generic programming are well-understood", it seems that "generics" == "generic programming": microsoft.com/en-us/research/wp-content/uploads/2001/01/…
    – Evelyn
    Commented May 7 at 19:37
  • 2
    -1 because, as others have pointed out, Wikipedia seems to say that "generics" and "generic programming" are in fact the same thing, and this question doesn't explain the distinction between them that it claims exists. Maybe we critics are a bunch of idiots who are missing the point in our ignorance of programming theory, but if so, you should spell it out for us!
    – Mark Amery
    Commented May 8 at 18:51
  • Edited the question with an attempt to address this Commented May 8 at 19:59
  • 1
    So you're saying generic-programming should be a distinct tag because generics would be inappropriate for questions about handling types/values "generically" in languages without type parameters?
    – kmdreko
    Commented May 8 at 20:36
  • 3
    Yes: generic programming is a paradigm/style whereas generics are a language feature. Much as functional-programming is a distinct tag from function Commented May 8 at 20:46
  • 1
    @kmdreko Note that generic programming isn't a substitute for generics; they allow different, sometimes complementary things (for instance, the concrete implementations of a generic interface might be provided by using generic programming).
    – duplode
    Commented May 8 at 21:52
  • 3
    Generic programming is sometimes referred to, more verbosely but less ambiguously, as "datatype-generic programming". For instance, the relevant GHC User Guide section uses that in the for the first mention in the body of the text.
    – duplode
    Commented May 8 at 22:00
  • From what I can tell, "generic programming" is supposed to mean something like "writing algorithms that use the ad-hoc polymorphism". Which is separate from "generic" meaning "a parametric type". But it was C++ that both popularized the former and presented the first mainstream implementation of the latter. Although C++ programmers don't, as far as I can tell, call templates "generics". Commented May 9 at 19:50

1 Answer 1

-4

You are correct; as you say, "generics" as in Java are kind of the exact opposite of "generic programming" (with templates) in C++. So yes, they absolutely should not share a tag.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .