5 ms·
You can't reduce C++'s complexity without eliminating core language features. This is precisely why people talk about “sane C++ subsets” (although the very idea
by catnaroek 10y ago
You can't reduce C++'s complexity without eliminating core language features. This is precisely why people talk about “sane C++ subsets” (although the very idea is silly). Of course, C++'s features were designed to address important use cases, so workable replacements must be provided in their stead:
(0) By far, the most important use case for templates is emulating parametric polymorphism. The solution is obvious: provide actual parametric polymorphism.
(1) The other important use case for templates is performing compile-time computation. This is done either by pattern matching on types (which parametric polymorphism forbids) or on values (e.g., integers) promoted to the type level. The latter feature is available in Haskell (`DataKinds`), and its design can be borrowed mostly as-is by systems languages.
(2) Classes combine, in a single language construct, features that ought to be separate: user-defined types, encapsulation (access specifiers), code reuse (inheritance), etc. Again, the solution is obvious: split these features into different language constructs: structs and enums, module-level privacy, parametric polymorphism, etc.
(3) Ad-hoc polymorphism is useful, but overloading as done in C++ is too unconstrained to support modular type checking of users of overloaded operators (templates). Again, the solution is known: type classes.