|
|
|
|
|
by mattnewport
3157 days ago
|
|
> (0) Macro, pardon my French, template expansion as a generic programming tool is super dumb. Better alternatives were known in the 70's. And yet C++ has better support for generic programming than most mainstream languages and it continues to improve. What's a language you think does generic programming 'right'? > (1) C++ classes are very poor abstract data types: You need arcane language design hacks like `friend` to abstract over two or more types at once. I don't really understand this comment. C++ has good support for static / compile time ADTs (the STL is very much built around the idea) and also supports 'runtime' ADTs through interfaces. In neither case is friend needed to abstract over types. > (2) C++ classes are also very poor object constructors: The language has no type for “all objects that have methods foo, bar, qux” (à la OCaml or Go). Static polymorphism in C++ currently relies on duck typing but this is what the Concepts TS is addressing. A major benefit of that will be improved error messages and a better generic programming experience. |
|
The most obvious examples are ML and its derivatives.
> C++ has good support for static / compile time ADTs (the STL is very much built around the idea) and also supports 'runtime' ADTs through interfaces. In neither case is friend needed to abstract over types.
The STL is built around ADTs in spite of the language's lack of support. If C++ had an actual notion of abstract types, then templates could be type-checked against ADT specifications (so-called “concepts”), rather than having to wait until instantiation time.
> In neither case is friend needed to abstract over types.
You can't encapsulate a single abstraction providing two or more ADTs without using `friend`. That's a fact.
> Static polymorphism in C++ currently relies on duck typing but this is what the Concepts TS is addressing.
This is a reply to the wrong thing. Concepts are ADT specifications, not object specifications.