7 ms·
Why is it every time I see a new article about C++ features my eyes glaze over? Am I just getting old, or has C++ jumped the shark?
by mark-r 8y ago
Why is it every time I see a new article about C++ features my eyes glaze over? Am I just getting old, or has C++ jumped the shark?
- moron4hire 8y agoI had a similar feeling. As a long-time C# programmer (how old is C#? That many years), I look at this and get really wide-eyed, "how is that at all a good idea?!" A lot of these features seem like ways to hack around the fact that C++ templates are not generics, they are literally templates for writing copies of classes. It seems like features like this are going to make code size explode. A lot of the examples also seem very smelly from an OOP perspective. We should one class be able to have different fields depending on template parameters? That seems like something one should do in a subclass.
- mattnewport 8y agoI'm very familiar with C++ and C# and overall I find I like C++ a lot better. There are a few nice convenience features of C# but knowing both languages I tend to find whenever they differ I feel like C++ made the better design choice. And C# going all in on OOP is a part of that. It's reasonably clear now that OOP was mostly a big mistake and a dead end. C++ is less infected by going all in on it as it has always been a multi paradigm language.
- adrianN 8y agoI'm not sure what you mean by generics if you think that C++ templates are not a kind of generics. Do you prefer that everything happens at runtime? Similarly, subclasses as opposed to templates carry a runtime cost. Virtual function calls are not free. Why pay that cost if you can deduce the right code from the types at compiletime? Besides, and this is probably a matter of opinion, I find code hard to follow that uses inheritance heavily.
- Retra 8y agoBy "generics", I presume they mean template parameters which are checked at declaration, not at use.
- mattnewport 8y agoThat sounds like concepts, as used extensively in the OP.
- steveklabnik 8y agoOne significant difference with concepts is that they are optional.
- mattnewport 8y agoGradual typing is mostly a good thing for metaprogramming I think. Even if it was just a compromise for backwards compatibility I'd still take it over C#'s rather limited generics.
- steveklabnik 8y agoI think C# is a good language, but I also am not sure that it's a poster child for this particular language feature. (I mean this literally; I don’t have enough experience to really know how it compares to the usual suspects in this area.)
- mattnewport 8y agoA bit of a test case for me, coming from the domain of games / 3D graphics programming, as to whether a language has a 'sufficiently powerful' generics feature set is whether it is possible to implement a generic 'short vector' type as used in any type of graphics programming. I think 'good' generics / metaprogramming support should let you meet most of these goals in a generic 'short vector' type: - Support 'n' dimensional vectors (2, 3 and 4 are the only ones commonly used in 3D graphics and games). - Support a choice of underlying element type (at least float, double and int but it's handy to be able to support custom types like a fixed point or rational type too). - Support operator overloading for natural expression of things like adding two vectors. - Be very close or identical in performance to the equivalent hand written variant for every combination of dimension / element type (excluding optimizations for particular SIMD element widths etc.) - Not be significantly worse for debugging than the equivalent hand written code (this is as much a tooling issue as a language issue). It's possible to meet all of these requirements in modern C++ without using any particularly exotic metaprogramming functionality. It's impossible in C#. I don't know of any other language that meets these requirements as well as C++ although I'm not really familiar with the facilities offered by e.g. Rust.
- seanmcdirmid 8y agoC++ supports generic through template/macro expansion, rather than through parametric polymorphism.
- dasloop 8y agoProbably because you are used to the paralysed C++ pre C++11. Nothing happens for years and now we have new functionalities every three years supported by all major compilers. But, also, many new functionalities are not for global consumption. The audience of many meta programming functionalities are library developers for example.
- jupp0r 8y agoIsn't every developer in a non-trivial software project a library developer? As soon as you have a common piece of functionality you want to reuse - that's a library.
- maxxxxx 8y agoI guess there are different levels of libraries. Something like boost is a different thing from encapsulating business logic into a library.
- deleted 8y ago[deleted]
- MichaelSalib 8y agoI think that's dependent on language culture. Because the C++ community doesn't take language simplicity or comprehensibility seriously, there are lots of C++ developers who can't use or reason about surprisingly large parts of the language. So the community has rallied around the notion that "library" developers need to understand everything and that most developers will just glue together bits that the library devs made. I mean, how many C++ developers actually write serious template code? How many of them could reliably explain what the keywords in post do? The idea that every developer is a library author (or the lisp extension that every developer is a language author) is common in many other language communities but it relies on the community working hard to make mastery of the language feasible for lots of people. The C++ community never bought into that notion; they inherited a very stratified class structure from Bell Labs.
- deleted 8y ago
- munchbunny 8y agoIt's because C++ is coming up with more complex ways to solve emergent problems from C++'s own complexity. So to appreciate why a proposal exists in the first place, first you have to catch up on the context that current C++ practitioners already have.