4 ms·
A solution might be a minimal subset of C++, so with STL containers, some syntactic sugar, easier and faster to compile (modules), etc. Basically what go and r
by jokoon 10y ago
A solution might be a minimal subset of C++, so with STL containers, some syntactic sugar, easier and faster to compile (modules), etc.
Basically what go and rust have achieved, except you keep most of the C/C++ syntax "taste", and you remove too high level stuff like templates and inheritance. Honestly I don't think templates are so useful, since most programmers already re-use STL containers, which are templates, but nobody really write relevant template classes.
> That's probably the C++ community's fault
The problem with C++ is backward compatibility with C and big corporations trying to not break their codebase. It makes it very hard to make the language evolve. For example D is a very good language, but it can't gain momentum as long as it doesn't have a real way to gain presence. We just have to wait that corporation clean their codebase to make room for C++ compilers to adapt, and then things should improve.
- tines 10y agoYou can't have the STL containers without templates though. If you want to special-case them in the compiler, then what about the algorithms library? If you want to keep the algorithms library, then what about your own code that implements a higher-level algorithm using the lower-level ones in the algorithms library? Without templates you have to write your algorithm once for every type of container, or else use indirect function calls which would not be good. So this won't really work well I think. For me, the only selling point of C++ is templates, and I've never written a nontrivial program that didn't use them (and I like to think that I don't just use them frivolously).
- sgeisenh 10y agoParametric polymorphism is a powerful abstraction. Makes for much more readable programs than ad-hoc polymorphism a la vanilla C.
- deleted 10y ago[deleted]
- 72deluxe 10y agoYou do realise that STL containers fundamentally rely on templates, right? We use loads of template classes at where I work. Our code would not be maintainable without them.
- jokoon 10y agoI know, but that doesn't change the fact that other languages don't have templates and still have containers, meaning maps, vectors, etc.
- jimktrains2 10y agoSure, and those without templates, or at least generics, aren't type-safe.
- pjmlp 10y agoThey have simplified templates, aka generics. The biggest difference is that templates are more expressive, allowing for compile time meta-programming.
- pkolaczk 10y agoI'd rather say templates are a hack to get generics in C++, because C++ lacks real generics contrary to eg. Java, C#, Haskell or Scala. Templates used as generics are limited in a way that the typechecker can't reason about generic types, only concrete types, which leads to horrendeous error messages and makes it impossible to prove generic library code type-safety. Type templates are templates, not types. On the other hand templates used as a metaprogramming tool fall behind any modern macro system.
- fjrieiekd 10y agoRust is getting there but still lacks type-level integers, and macros are waiting for macros 2.0. It would also be neat to have the ability to run any function at compile time, but I don't think that's in the cards.