It appears the generic-programming tag has been merged into generics. 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, whetherT
is instantiated toint
orstring
.- 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!
generics
are legitimately about generics (in Java and similar languages) and not about generic programming which is somewhat more niche.generic-programming
should be a distinct tag becausegenerics
would be inappropriate for questions about handling types/values "generically" in languages without type parameters?functional-programming
is a distinct tag fromfunction