The Problem With C++

Bjarne really sums it up with this quote:

“Often, when people have trouble with C++, the real problem is that they don’t have appropriate libraries–or that they can’t find the libraries that are available”

When people say C# is high level or Java is high level what they really mean is that extensive class libraries are provided by the language vendor (.NET etc).

I’m tired of hearing that C++ is an unproductive language. It depends on the libraries that are available to you. I can be just as productive, and maybe even a little more productive, using c++ with Qt for builing GUI apps than with java. C++ certainly isn’t the best tool for every job, but most people who dislike it are a bunch of goddam whinners. If you think C++ will work for you for a specific task, then use it. If not, use something else. And even if you end up using java, c#, perl, etc. 99% of the time, you should learn to write code in a language like c++ or c to enhance your knowlege of how software works. One of these days when I have enough spare time, I’m planning on learning assembly just for the sake of having a better understanding of how software works. I may never use assembly for real world code, but it might help me write better code in other languages. If nothing else, learning a low level language will give you another tool to use in the future in case you do end up having to do some low level stuff.

Several people have mentioned this, but all the software I use on a regular basis is written in C++, and I can’t imagine what it would be like if they were written in some .NET language or Java or worse.

Firefox, Thunderbird, all the video games I play, music and video players, word processor, spreadsheet, audio recorder, Visual C++ Express, VS 2003, etc.

I could go on, but most of these applications task my processor, and would not be as snappy or responsive if written in anything other than C++. For awhile I was using Paint.NET, but it’s slow, and I get annoyed with that, so I don’t use it. Azureus, the Java bittorrent client, can’t hold a candle to the C+±based candidates.

I program video games. There’s no question about what language I use for that. Most next-gen consoles are faster than desktop computers, and those games will all be written in C++. Microsoft is pushing the XNA/C# thing for the XBOX 360, which is fine for hobbyists, but commercial game programmers know they can’t use a runtime that freezes all threads to do extensive garbage collection and memory compacting for longer than 20 milliseconds. It kills the frame rate.

I estimate 98% of the time I am interacting with a computer, the software I am using was written in C++ and this is probably true for most people. So, how is the importance of C++ diminished?

How well does C++ protect me from myself? Well, I don’t aim at my feet, so I rarely shoot them. In other words, when I instantiate objects on the heap, I allow smart pointers or STL containers to keep track of them and deal with memory management. I’ve worked on C# projects that need weird hacks to keep the runtime from freeing memory that is still being used. The .NET runtime with go ahead blow your leg off for you.

C and C++ aren’t powerful, they are primitive. Because of this you have to work more, can create dangerous bugs more easily and will need more time to create a working application. Of course you can do everything in those languages - like you can in Assembler. And sometimes they may even be necessary - like Assembler. But that’s not a sign of power.

All this “If C/C++ is to hard then you are to weak” gibberish only shows that those people never tried to create real applications in different languages. It’s now about being ‘hard’, it’s about getting the job done. People who choose the wrong tools simply aren’t professionals.

I’m an old C++ programmer having cut my teeth with Borland’s initial incarnations of the language and moving up to MS C++.

C++ is still useful however, in my opinion, there are better solutions for high level apps.

The good thing is that you can write libraries in it for the stuff that has to be fast, efficient or whatever weird thing it has to do and then bind them to your C#, VB, Java or whatever high level language.

I think that’s the way the majority of C++ development will go in the future.

Regards,

He stated that people don’t know where to find libraries that exist. So, for student that is currently using C++ where is there a good place to find such libraries. For example if I wanted to create a Btree. Is there a library out there which contains a template for this type of file structure? I guess what I am saying is that the STL for C++ needs to be updated.

My own experience with people having to implement something, let’s call them ‘developers’, is that they are struggling with the concepts, not so much the language. Take the concept of a virtual base class, of an asynchronous event, or a reference-counted pointer. some languages let you side-step these because they have their management built-in (e.g. java for reference counting) but if you need to optimize for memory usage, you need to still understand this concept so that you can (e.g. java) set the object to ‘null’ so the garbage collector can take it away when come its time. Pointer aliasing exists in Java, Perl as well, it’s just less apparent. And these are the things that fresh students have a harder time to wrestle with, and therefore leading to poorly implemented code, whatever the language. I think that is what Bjarne was mentioning, just that he looked at it from the C++ perspective where these fault very quickly end up in segmentation faults and the likes. In Java, this ends-up as the 250MB resident RAM application, in Perl as the garbage sorted hash, and maybe as an exception in Python. It’s like explaining a car’s manual shift gearbox to somebody having driven an automatic all along. You’ll have a hard time explaining the usefulness of the clutch…

“If a language is deemed “easier” it automatically requires less brains to do the job.”

A wise programmer will always use an “easier” language when it meets his or her needs. Unless said programmer is an academe or for some other reason the final product and programmer time doesn’t matter.

I guess the best way to find libraries for specific tasks is to just google them. Unlike the class library for java and other languages, it is intended that c++'s STL not be bloated with lots of stuff. That helps keep c++ a generic programming language. I think some of the STL containers use btrees internally. Also, keep in mind that you can use any c library with c++. There may be some exceptions to this, but I don’t know of any.

“Delphi… has very good garbage collection”

Huh???

“Delphi remains the best Win32 dev tool in existence, and a decent .NET dev platform. One which even allows Win32 Delphi apps to be recompiled for .NET, preserving the developer’s code base. Something MS did not make available for all the VB and C++ apps that needed to be converted to .NET.”

True enough. I still hate the language with a passion. I worked with C# for only 3 weeks before falling in love with it and realizing all the drawbacks of pascal.

“I guess what I am saying is that the STL for C++ needs to be updated.”

Yes, this is no discovery. The standard library is going to be updated for the next standard with useful things like sockets and threads.

“Here, through HTML and other easy means, a wealth of wonders has been drawn out from the average person because the technology that was for so long only available in the hallowed halls of academia became liberated. In case you couldn’t see it from your Ivory Towers, this is a good thing!”

I think no one can argue the fact that an increasing number of professional developers are undereducated in programming. Hey, if you’re only a hobbyist programmer that develops unimportant stuff, what do I care if you’re an incompetent programmer? Professional programmers are the ones who should be more knowledgeable. That’s what we’re arguing about. That’s what Bjarne was addressing.

“We’re developers, not English Teachers… You obviously can’t write a lick of real code if you spent the time to worry about the grammar.”

Disagree; written English is an analog of code. One who expresses himself well in code should be able to do so in their social language as well. Nitpickiness in grammar and nitpickiness in code go hand in hand.

Bjarne is absolutely spot-on with his analysis. C++ is an incredibly powerful toolkit, but the mistake that many have made in the past (including my own organisation) is to attempt to build business apps directly from the lowest level components provided by the language. This is cumbersome, which is why it has been pushed from this niche by VB6, Java and the .NET languages. The correct way to build systems is by providing the basic abstractions (starting with strings, collections, memory management) and build on top of these in layers of increasing abstraction; Java and like languages provide this basic layer “out of the box”, which feature has been instrumental in their success.
The sad irony is that we are only now seeing - too late - these sort of facilities standardising in C++, with the advent of STL and boost. Read comp.lang.c++ and you’ll see that a lot of the gurus there never go anywhere near a raw pointer, a delete statement or (god forbid) a C-style array, they have all this stuff wrapped - layers of abstraction again.
The sad thing is that by defecting to Java, C# etc we have also surrendered the wonderful expressive power and flexibility of C++; I certainly miss it.
One last point: C++/CLI would appear to offer the best of both worlds, but I see very little evidence of its use - another case of missing the boat I fear.

Use Qt in conjunction with C++ and you evade it’s downsides without losing the benefits of this great language. The resulting code will retain the efficency and performance of c++ but will at the same time be easier to read and comprehend since it is much more ‘high-level’ due to the elegance of the Qt-Library.

listen here you young wippersnapper noobies!!! I’ve been a programmer eversince you were in diapers and suckling on your poor mamas nipple.Back in my day we used lotus, pascal and just plain old binary and that’s the way it was and we liked it.I got one word for all of u youngsters and that’s that “Your all totally wrong!”. Learn the basics!! and I don’t care if it kills You and by the way, FUCK PRODUCTIVITY!!..We used to walk to the computer lab 5 miles uphill in the snow, barefooted everyday just to write programs that You ingrates dismiss with all of your fancy schmanzy codes and opinions. If I had my way I’d settle this the old fashion way and challenge every one of You to an old fashion code write-off. I’ve written off the best of em , from jobs to gates…I even took out balmer back in 78 back when he was a zitty faced punk in braces and headgear. if any of You young punks want to try me then…Bring it BIATCHES…

“We’re developers, not English Teachers… Wut a dumm risponse.”

Oh dear. Yet another young wanker who thinks that proper English doesn’t matter. Grow up, sonny boy. You probably don’t even know when to use “its” and “it’s” correctly, and I bet you spell definitely “definately”. And the worst thing is, you think it doesn’t matter.

No wonder most software is in such a dire state. If you can’t get the details right, what hope is there for the big picture?

Software engineering: a contradiction in terms.

C++ is only difficult to people who don’t take the time to grasp age=old computing fundamentals. As such, a lot of modern programmers can’t even do binary arithmetic and whether you like it or not computing will alwats be 1’s and 0’.

Anyway, the point I try to make is that the beauty of C++ is that you can code within the user’s constraints. All these fancy new languages (note that I code professionally in C# so I am not stuck in the past) leave the developer making brash assumptions that people are happy to install 20+MB runtimes and other such dependencies just to install their app.

For my own shareware apps, there is no other choice than C++. Of course where necessary I mix it with the native frameworks depending on the platform I target. eg. A windows version of my app uses WTL/C++ yet the Mac port is Cocoa/Obj-C for UI and C++ for the model classes. Works beautifully because I took the time out long ago to work out what I was doing!

Just decided to have a quick look for benchmarks of c++ vs .net

http://blogs.msdn.com/jonathanh/archive/2005/05/20/420634.aspx

pretty interesting - c# won until c++ had been optimised so far that the 60ms startup lost it the race

C++ is too flexible. Yes, in my opinion it’s a disadvantage. The most terrible thing is a possibility to inherit the child class from many parent classes. Sometimes, when the application design has to be changed during the implementation, eg. new facts have been identified or because of the inproper design (and - to be honest - we meet such situations very often, although everyone will agree, it’s “not good”) or the whole design is more “paper like concept” (looking nice on the papaer but not seriously implementable) than “reality model” the implemented application class model seems to be total mess (and many times far away from design concepts). I mean, you can do too many bad things with C++ as in fact it is not to restrictive language. And then, let think about a guy implementing an application for a couple of years, doing total mess, using all the features of C++ without any concept, just to solve the problem and “progress with the schedule”… The guy thinking - “if it is working, it is ok and we don’t have to change anything”. Then, imagine the guy will change the job and you will have to take care about all this mess and crap. I thing it’s impossible to solve many problems with the inproper design and implementation of C++ applications in a sensible period of time. Sometimes it looks, that the best idea is to design and implement the whole thing again, but of course such move is not possible in reality. I think the programming languages have to be more restrictive than flexible. At the end… it’s better to think twice because of some restrictions than avoiding them with the manic-like solutions with the usage of “advanced” features of C++. And - to be more honest - C++ is good, but not for all tasks we can imagine (just because “it’s faster than Java” and also multiplatform). We don’t need the swiss-army-knifes, like plumbers we have to use the set of tools, like : pillers, hammers, cutters, threaders, welding blowpipes and so on… We need to choice a proper language for specific problem. I think the problem with C++ is that many people consider this language as good for almost everything. There are no flexible tools - you cannot hammer in the nails with the usage of pillers, as you cannot write the web application with the usage of C++ (but you can with ASP.NET, some specific J2EE standards or PHP - depending on the complexity of such web application of course).

That’s all from me.

"at a time where the degree of effective formal education of the average software developer has declined"
Yes, I work as a tech lead in a major sw company that uses C++
I have to review a lot of C++ code and interview ppl on their C++ knowledge. bottom line is C++ has gazillion amount of accidental complexity, that distracts from solving the problem.
All teh C++ guru I know, are just that C++ guru, they know nothing else, they’re not the guys who can come up with a practical solution fast. They always always always come up with a massively overengineered solution, whose performance sucks and that is totally impossible to maintain.
I’ve been through so many “refactoring” exercise once the dude who wrote the stuff has left and we find that it is always faster to reimplement than trying to fugure it out.

"C makes it easy to shoot yourself in the foot; C++ makes it harder, but when you do it blows your whole leg off."
That is so so so so wrong, C++ makes it much easier to shoot yourself in the foot and when you do, there’s nothing left of you, leg body arse… all gone.

Gimme C, perl, Javascript, LISP everyday, but C++ for me has sucked the joy out of programming