Skip to main content

What's wrong with C++?

I whole heartedly agree with this article!!

What's wrong with C++?
by Bartosz Milewski

src: http://www.relisoft.com/tools/CppCritic.html
--------------------------------------------------
Some time ago NWCPP (Northwest C++ Users Group in Seattle) organized a public panel on the future of C++, with Scott Meyers, Herb Sutter, and Andrei Alexandrescu. I started thinking about C++ and realized that I wasn't that sure any more if C++ was the answer to all my problems. I wanted to ask the panelists some tough questions. But I was there for a big surprise--before I had the opportunity to say anything, they started the criticism of C++ in the earnest--especially Scott.

One of the big issues was the extreme difficulty of parsing C++. Java and C#, both much younger languages, have a multitude of programming tools because it's so easy to parse them. C++ has virtually nothing! The best tool one can get is Microsoft Visual Studio, which is really pathetic in that department (I haven't tried Eclipse). Apparently, VS uses a different (incomplete) parser for its browser than it does for its compiler, and that's probably why it can't deal with namespaces or nested classes. When you search for a definition of a function, you get a long list of possible matches that don't take into account any of the qualifications of the original query. Finding all callers of a method is so unreliable that it's better not to use it. And these are the most basic requirements for an IDE. By the way, the Help engine seems to be using yet another parser.

I talked to John Lykos at one of the conferences, and he told me that he would pay big bucks for a tool that would be able to tell what header files must be included in a given file. That was many years ago and to my knowledge there still isn't such a tool. On the other hand, there are languages in which the programmer doesn't even have to specify include files, so clearly this is not an unsurmountable problem and it's only C++ that makes it virtually impossible.

Complex programming problems require complex languages. An expressive language helps you deal better with the complexity of a problem. I believe there is some proportionality between the complexity of the problem and the complexity of the language. But if a language is disproportionately complex, it starts adding complexity to the problem you're trying to solve instead of reducing it. There are endless examples of unnecessary complexity in C++.

Accidentally, the parsing difficulties of C++ might be the biggest roadblock in its evolution. In principle, changing the syntax of the language shouldn't be difficult, as long as you can provide good translation tools. You can look at syntax as a matter of display, rather than its inherent part. Just like you have pretty printers that format your code, you could have a pretty viewer that shows C++ declarations using Pascal-like syntax. You could then switch between programming using the rationalized syntax and the traditional syntax.

As long as C++ gurus live in the clouds of the Olympus, they won't see the need for this kind of evolution. That's why C++ becomes more and more elitist. In the future, people who do NYT crossword puzzles and the ones who program in C++ will be in the same category.

Very smart people keep writing books with titles that read like "Esoteric Nooks and Crannies of C++", or "More Bizarre Pitfalls of C++". Or puzzles that start with "What's wrong with this code fragment that to all normal people looks perfectly OK?". You don't see such publications in the Java or C# community. C++ is becoming a freak language that's parading its disfigurements in front of mildly disgusted but curiously fascinated audience.
"So you have to put a space between angle brackets? How bizarre!"
"Are you telling me that you can't pass an instance of a locally defined class to an STL algorithm? How curious!"
"Talk to me dirty! Tell me more about name resolution!"
"Pardon my French, Is this specialization or overloading?"
--------------------------
Also see: http://www.alledegodenavnevaroptaget.dk/interview.html

Comments

Anonymous said…
"One of the big issues was the extreme difficulty of parsing C++."

It is ___provably___ impossible to write a correct C++ parser which will complete compilation with either success of failure because the C++ template system is Turing complete. This means that code generation is based on a turing complete program. Code generation in C++ isn't based on a program description, but an actual turing complete program.

As such, it is subject to the halting problem. Therefore, it is unknowable whether a compilation will complete, and unknowable if you are looking at a valid C++ program.

-flan, who doesn't care to have a blogger account.
Anonymous said…
oops, the C++ spec allows implementations to terminate compiles if they recurse too deeply. Nevermind.
Exciting blog. The site out did itself and will be
back! I love surfing the internet for blogs that are
exactly like this blog.
Search for my blog, please!
outa-time said…
Enchanting blog. Your site was off the chain and I
will return! I peep the web for blogs just like this
one.
I was in love with your 1800contacts coupon codes blog site.
Wondrous blog. Your site was very pleasing and I
will go back again! I like surfing the net for blogs
as good as yours.
Please take a journey to my 1800contacts com coupon blog.
dat-girl said…
Enchanting blog. Your site was off the chain and I
will return! I peep the web for blogs just like this
one.
I'm looking at the possibility of checking your 1800contacts coupon codes blog.
stunned said…
Creative blog. I just kept looking at it over and
over! Im always looking for blogs like this!
In my spare time I will look for your 1800contacts coupon codes blog.
Great blog. I'm always finding blog like yours. It
got my attention and I will go to the site again!
Go by and hit my 1800contacts com coupon blog, you'll be glad you did.
Powerful blog. The site was incredible and will be
back again! Web surfing helps to find good blogs like
this one.
In an efford of finding the right info, check for my 1800contacts com coupon blog site.
Terrific blog. I search the internet everytime I
get a moment to find blogs. Its better than cold iced
tea and I have to visit it one more time!
If your look to uncover information, please visit my coupon codes 1800contacts blog
Unbelievable blog. I can hardly wait to vist this
site again.I'm consistently looking up blogs like
this.
I want you to look for my 1800contacts coupon code blog.
Terrific blog. I search the internet everytime I
get a moment to find blogs. Its better than cold iced
tea and I have to visit it one more time!
Where you been? You have got to look at my coupon codes 1800contacts blog!
Sensational blog. I took pleasure in the site and I
will go back! Surfing online for blogs like this one
is worth my time.
Go by and hit my free plastic surgery blog, you'll be glad you did.
Hype blog. And I admire your site and plan on
returning to it! When I web surf it always helps me to
find great blogs.
Check out my plastic surgery gone bad blog, please!
Anonymous said…
yr
Matt Kukowski said…
I COMPLETELY AGREE! There are programmers out there that think they are genius because they can write code that is so CONVOLUTED and pointless, just because they think they are smart to do so. I Think C++ is ok when it comes to BASIC class use, but as soon as one convoluted the code with more and more crap... it makes programming a CHORE instead of being fun, and having the kick in the discovery your program DOES SOMETHING USEFUL. Not just saying, Oh I can code THIS and you can't follow it without spending hours trying to DECODE the CODE.

Popular posts from this blog

Multi-dimensional arrays in C++11

What new can be said about multi-dimensional arrays in C++? As it turns out, quite a bit! With the advent of C++11, we get new standard library class std::array. We also get new language features, such as template aliases and variadic templates. So I'll talk about interesting ways in which they come together.

It all started with a simple question of how to define a multi-dimensional std::array. It is a great example of deceptively simple things. Are the following the two arrays identical except that one is native and the other one is std::array?

int native[3][4];
std::array<std::array<int, 3>, 4> arr;

No! They are not. In fact, arr is more like an int[4][3]. Note the difference in the array subscripts. The native array is an array of 3 elements where every element is itself an array of 4 integers. 3 rows and 4 columns. If you want a std::array with the same layout, what you really need is:

std::array<std::array<int, 4>, 3> arr;

That's quite annoying for two r…

Folding Monadic Functions

In the previous two blog posts (Understanding Fold Expressions and Folding Functions) we looked at the basic usage of C++17 fold expressions and how simple functions can be folded to create a composite one. We’ll continue our stride and see how "embellished" functions may be composed in fold expressions.

First, let me define what I mean by embellished functions. Instead of just returning a simple value, these functions are going to return a generic container of the desired value. The choice of container is very broad but not arbitrary. There are some constraints on the container and once you select a generic container, all functions must return values of the same container. Let's begin with std::vector.
// Hide the allocator template argument of std::vector. // It causes problems and is irrelevant here. template <class T> struct Vector : std::vector<T> {}; struct Continent { }; struct Country { }; struct State { }; struct City { }; auto get_countries…

Covariance and Contravariance in C++ Standard Library

Covariance and Contravariance are concepts that come up often as you go deeper into generic programming. While designing a language that supports parametric polymorphism (e.g., templates in C++, generics in Java, C#), the language designer has a choice between Invariance, Covariance, and Contravariance when dealing with generic types. C++'s choice is "invariance". Let's look at an example.
struct Vehicle {}; struct Car : Vehicle {}; std::vector<Vehicle *> vehicles; std::vector<Car *> cars; vehicles = cars; // Does not compile The above program does not compile because C++ templates are invariant. Of course, each time a C++ template is instantiated, the compiler creates a brand new type that uniquely represents that instantiation. Any other type to the same template creates another unique type that has nothing to do with the earlier one. Any two unrelated user-defined types in C++ can't be assigned to each-other by default. You have to provide a c…