3 ms·
What kitchen sink was thrown in C++? The STL? That's the main reason I first fell in love with C++. Templates? Exceptions? RTTI? IMO the problem with C++
by kenjackson 16y ago
What kitchen sink was thrown in C++? The STL? That's the main reason I first fell in love with C++. Templates? Exceptions? RTTI?
IMO the problem with C++ is its C legacy (things like macros). These things make it harder to read code and make it harder to write great tools for it (ever seen really good code completion or static analysis for C++ code?).
- barrkel 16y agoThe kitchen sink comes from the conflict between the C ideology C++ inherited, and the requirement for OO language features. RTTI and exceptions are fine when you can rely on them, but C++ users don't always want to pay for those features, so you end up with some libraries that require them, others that forbid them, and some in between which reinvented their own exceptions and RTTI mechanisms. Trying to glue all these disparate things together where there's so little accepted as being in common is a pain. Languages built around platforms, like Java and C#, on the other hand, can assume that java.lang.Object / System.Object is the root of the inheritance hierarchy, that exceptions are used throughout for error handling, that reflection is available throughout (modulo security concerns), etc. The fact that you can rely on the base library, and that you can communicate between modules using containers / common interfaces in the box makes the job of integrating modules far easier. C++ included some of these features, but didn't make them mandatory. So you end up with a strange mix across the board. The other issue is that C++'s features aren't well thought out in an orthogonal sense. One example: the idea of exception safety doesn't mesh well with C++'s copy constructors, to the degree that you can't write a generic stack type whose pop method returns the value popped, because you can't get exception safety right on the mutation to the stack if the copy constructor on the returned value threw an exception.
- Silhouette 16y ago> What kitchen sink was thrown in C++? What wasn't? - Procedural programming - Structures and enumerations - Overloading of functions, including operators - Classes, object-oriented programming and run-time polymorphism - Generic programming, templates, compile-time polymorphism and metaprogramming - Text-based macros - Hacks and, from C++0x, built-in language support for in-line functions - Exceptions - Low-level memory access By my count, every one of those things interacts with almost every other one in some way. Often, there are deep connections, such as the RAII idiom, that are fundamental to using C++ effectively but not obvious to someone with a good general programming background but no expertise in C++ specifically. The real problem, though, is that C++ isn't really very good at any of those things in isolation. There are much better approaches to all of them, and there are tools available that take those approaches. They just don't fit together to form a coherent whole, where features are either orthogonal or blended together cleanly. It used to be the case that C++ offered a more powerful overall tool than most other languages because of the diversity of its features, but today's languages have had the benefit of decades more experience and hindsight to draw on. The very diversity that used to be a compelling reason to use C++ has now become the most compelling reason not to, IMHO.
- kenjackson 16y agoLets be clear... half of your list is from C: -Procedural programming -Structures and enumerations -Text based macros -Low-level memory access And for the items they actually added to C to make C++, none of them are all that unusual, save templates (not sure if there is any other language that does it compile time). IMO, Scala has more parts of the sink in it than C++. The problem with C++ isn't the kitchen sink. It's that its built on a language that isn't meant to hold the things that C++ would like to add to it. Maybe I'm being pedantic, but when I see "kitchen sink" I have a vision of a lot of features. But frankly C++ isn't all that feature rich. But its the interaction complexity that makes it problematic. This is not a problem of throwing the kitchen sink at it, but rather a design problem.
- hga 16y agoLet's put it this way: do you know of any successful C++ project of serious size that doesn't specify and stick to a subset of the language?
- kenjackson 16y agoSeveral that I've worked on. There were aspects of the language that we avoided, like export, because they weren't implemented. But in general, we didn't have ground rules about features to use or not use. At least not in the past 15 years. Back in '93ish we would be more careful, because the features were still evolving, but by 2002-2003 I don't think we had a lot of issue using the language.