The Problem With C++

I would agree with Tragomaskalos, where “modern C++” doesn’t have C arrays or fully-explicit memory management (it is still somewhat explicit, as you can discern between a single-owner or shared ownership strong reference, or a weak reference, for example). You don’t go anywhere near a “delete” statement, and buffer overflows are a rare occurrence with vectors and such.

The much hated C+±style casts are at least greppable (and I find their ugliness to be a feature, you know something’s awful when you see one!) as well as more accurate (static_cast does notmagically and silently turning into a reinterpret_cast, which would most likely introduce a bug, for example).

You still have the lower-level C-style constructs available, for those times you really need them (which is just about never, if you’re not doing system programming). One could say that not having them at all is probably best, but I find idiots somehow manage to write crap code no matter what language you give them, so it might as well be a more capable language.

This way, you can also notice the people with blown off legs and fire them. :wink:

C++ is just C with object structures, I’m guessing all C++ compilers actually still at some point output C code.

Personally I love C and C++. Yes its complex, probably more complex than is really good.

Also pretty much no one uses it, but its not really the languages fault. Blame it on Microsoft, no one wanted to write MFC applications, and Microsoft openly ignored the standard, and implemented a lot of crap that people didnt/couldnt/wouldnt/shouldnt use.

Who’s got time to figure out how to write code in a language that doesnt have a standard implementation that can be used to build real applications. MFC was just too hard, weird, too Microsoft – it killed the language.

C# is just Java with the names changed to protect the lawyers, I dont consider it a derivative. But I like it, even though I dont use it.

Mostly, I find PERL, AWK, Python, and other scripting languages get it done for me these days. Its just easier, and most stuff i want to do I want to automate and a GUI is in the way.

I still love you C++, but your time has passed.

“But when was the last time you used C++ to write a […] website?”

I’ve written several websites using C++. For example an SMB search engine. It is very good at integrating things - an HTML template library, SQL library, CGI library.

“Because it can do all these things, it’s complicated and dangerous.”

Dangerous links to buffer_overflow. That’s really only a valid criticism for C and for stupid programmers. C++ has std::string and std::vector.

I guess another way to look at things these days is that with so many RAD desktop/web software being developed, a modern language targeted for that end point is needed.

Low level work requires C/C++, but these days more work is done at a high level (i.e. Writing an AJAX web application, rather than writing a web browser in C++)

Really this topic shows more about human psychology!

With people:

  • Defending their choice of language
  • Taking digs at other language
  • Attacking each other

When deep down we all know the basic truth, with is:

  • There are different programming languages
  • There are different types of software to be written with those languages

There is no right or wrong, only different choices with different outcomes.

You are a fucking idiot, c++ is supposed to be for expert programmers only because noobs like you dont need to use it. Youre the stupidest person i’ve ever seen, or read.

There sure is a lot of defensiveness around C++, but that’s already been pointed out.

I agree that C++ has very few uses nowadays where C# (or another common language) would be a better choice. But Stroustrup’s point about uneducated programmers is valid. As far as I’m concerned, language is irrelevant compared to skill with programming, and we have too little skill going into increasingly complex problems.

This whole topic is laughable. About every month or so the VB and Java camp spit out propaganda against C/C++. This time because Ruby has Java on the run.

Let’s take this article’s argument even further. Why use Java? It’s harder than some other languages. The simple fact, which Stroustrup made clear, is it encourages specialization.

Look at Java, for example. As long as a Java application is idle 99% of the time it’s ok to use Java. Otherwise use C/C++. That’s the reputation that specialization awards.

Stroustrup is clearly frustrated with the state of Computer Science in academia. Most universities switched to Java in the classroom about 7 to 8 years ago. Not because Java is a better language but because the professors got lazy and didn’t want to spend anytime teaching the C++ language. This narrow minded philosophy has lead us straight to where we are now. A small army of Java disciples suffering from something akin to C++ envy. Now we have to suffer with things like slow phone systems ‘proudly’ written in Java.

Graham

Give me a language that is better for real time 3d graphics programming, and I will gladly use it. Not everyone has moved on to the web.

A number of people seem to be saying the same thing and that is, C++ isn’t the problem, the programmer is the problem. The argument seems to be if you can’t solve your problem in C++ then you aren’t good enough to use it.
I think this line of thinking is generally one that stunts progression. The problems we are trying to solve today are, arguably, many orders of magnitude more difficult than those we were solving 10 or 20 years ago. When C++ was created did anyone think of desktops with multiple cores? Probably not. Given this increased complexity, perhaps C++'s expressiveness is not enough anymore. C++ is not going anywhere due to legacy code, however when making a new project one should think hard and long about what benefits the various languages will give them. To put it in an analogy, construction has come a long way from slave labor, now we have giant machines to do our work. They can move in a single shovelful as much as a hundred men can. They move a bulk and of the problem and then we use smaller and more refined tools for the other parts.
I don’t think making languages ‘easier’ is meant to make less skilled people able to program, no, I think it is meant to let experts solve more complex and interesting problems. Writing an IRC client in C++ is one thing, however building a large, fault tolerant application that needs to have defined state throughout its lifetime is different, and I would not like to do that in C++.

One thing to also remember with all of these languages, is marketing.

When .NET, which I am using to encompass C#, et.al., has Microsoft’s marketing team behind it, how many “new” programmers are going to head to SmallTalk or Java? At lot less.

When Java has Sun behind it, plus their other Sun Studio product which includes C/C++ for free, how many of the left over “new” programmers are going to head there? Not quite as many.

That said:

When a business needs to have an B2B web service and web protal created in 2 months, who are they going to want to work with AND add supportability for any other programmer to step in at anytime? A C# ASP.NET programmer who can turn out that app in possibly 1/2 the time or a C or C++ programmer who can maybe get it out on time?

What if a cell phone manufacturer needed a new GreenNose driver that is going to blow away the competition and make it to market before their biggest competitor? The C# programmer who might be able to fit the app on the cell phone’s limited storage space or the C programmer who can make it fit and leave room for that spreadsheet app the other department is working on PLUS crank it out in half the time?

I’ve said it before, yes the tool may do the job, but is it the right tool for the job?

I totally agree that knowledge of other languages is important, but I also agree that it isn’t necessary. I can read C, C++, Java, or any number of other languages, and with time, could even code in them. Anything can happen with practice AND documentation.

One of the other things that makes MS technologies “better” is the fact of support. They have excellent documentation, support forums, training, and a user base that rivals any other language produced by another company or by the open source world. This a cannot be denied.

It seems to me, there are two types of “languages”: a) of the Turing camp (the FULLY ORACLE-SQL-Persisted-SWI-Prolog and ASSEMBLERs), and b) the fast, straight, bladed procedural (compiled) languages ala C/C++/Haskell/Ruby/Most_LISPs/Mercury…u name it. The basic end-to-end-runtime system, buddy, that’s the very idea behind every language philosophy. And C++? Well… SEX. Yeah, sex, sex, sex, sex, sex. The easiest way to overcome a problem is to make it a bit more… bisexual. Add libraries. Mix it, blend it with stuff like LLVM, rt_ctiny()…even Factor…

No, bytecode seems to be so…i dont know…rude. I mean, something like a C# parser, or a Java one or VB over a bytesomething…yeah whatever

i gotta go, oh happy new year ! :slight_smile:

I work 50/50 C++ and JavaScript - C++ simulation models and an XUL based front end. Prior to that I’ve used Java both for both server and UI work, and a bit of C, Fortran, Pascal, various assembler, XSLT and Matlab. The use of C++ components with a scripting front end is not uncommon - most of Mozilla’s products are defined that way, as are many COM applications.

For modelling and simulation, if you have something processor heavy it’s likely to be mathematical. A good programmer can write Fortran in any language - well thought out algorithms operating mostly on primitive arrays. For that kind of code, with Java 1.4 you got better performance than MSVC++6 C; now VS2005 C is better than 1.6. C++ using stl fares worse than Java for tests such as SciMark. This is for modelling, not real-time simulation.

One of the modelling systems I’ve been called to work on cost 500,000 UKP per year in processor hours (the company was renting a legacy mainframe), so unless you’re a multi-millionaire we’re not in an era of abundance. On the other extreme, OLPC is a 100 dollar platform so again requires tight code.

Once you stop writing Fortran (and most sane people want to), the performance hits you get with Java or C++ seem to come from exploiting OO’s information hiding, so the compiler is not able to optimise across objects. Sometimes trading hot-spot optimisation for whole program optimisation pays, sometimes it doesn’t - for example inlining the most common case at runtime. The Fortress language, which runs on the JVM and is targetted at MS, is addressing this by flattening the program; I’ve also had success using model-driven development pipelines for generating flat code from high level maths models.

One weakness in C++ is that its templating system is not a very good model for meta-programming; Java and C# don’t even try, so there’s more external code generation options. Object oriented languages also have introspection and reflection, which C++ lacks, so I’ve ended up having to add them to every large C++ system I’ve worked on.

WRT RAII and garbage collector scheduling destruction, C# provides the ‘using’ statement that gives similar scope-delimited resource life-cycle semantics. It’s not a hard problem.

I don’t see C++ moving from realtime simulation yet (and that includes many video games, though there is use of scripting languages for AI and overall gameplay etc.) - it does most of what you want well enough, and lets you optimise for a traditional machine - until it’s pushed off by a language that can handle multi-core processors better.

Sorry Jeff; While I usually agree with everything you say, you’ve totally missed the boat here.

If you use source control, you have to see this YouTube video! ROFL!

I like C# a lot too, but it by no means replaces C++. There are a number of things that you can’t do in C# that requires you to do a p/invoke to C++ code. This is especially true when programming for when programming in C# using the .NET Compact Framework on a Windows CE device.

Jeff, are you just writing these pieces just to sit back and laugh at so many whacked-out responses and get your page rankings up?

It works!

@Steve

You are incorrect. That is not garbage collection but a simple parent-child relationship in the Delphi VCL. It is present in nearly every GUI library I have used, including Motif ©, VCL (Delphi)and Qt (C++).

The parent-child pattern is a paradigm common in many GUI toolkits and has nothing to do with garbage collection.

The largest problem with C++ is that it is too easy to make mistakes. People say “You must be a competent programmer, then that won’t happen”, suggesting that they are such a competent programmer. NO ONE can just write bug free code, particularly in C/C++. The OOP system gives a facade of high levelness (leading to misconceptions such as a GC and safety), but really its just a macro system. The odd bit about this macro system is that it didn’t really do stuff that had been repetitious in C code before.

The other problem with it is that the ‘proper’ expression of solutions tend to be much longer than the dumb ones, and tend to have bad interfaces to boot. Worse yet is the tendancy towards preoptimization - because you can, you do. In the end you get longwinded, improper, preoptimized code.

Except for the preoptimization point, the previous paragraph may also be applied to such languages as C# and Java, which force upon you the OOP model as well as longwinded expression of simple concepts.

PS - that thing on fortress above, It does look like a very interesting language, but it doesn’t necessarily target just JVM. That’s just the initial impl. They are going to target machine code, and ramp up performance.

How can I resist adding my own comment to this burgeoning list when everybody else and their mother has already chipped in with their two cents? I have been writing embedded code for years. I do as much as I can in C, occasionally I have to deal with assembly language. C++ never appealed to me, I never found any advantage. Of course, most of the stuff I write is pretty simple minded.

The C++ programmer comments are quite interesting. None seem to remember why programming languages exist.

They exist to do useful things for PEOPLE.

PEOPLE. Remember those things?

Sometimes I need a power screwdriver with 12 specialty tips plus a dremel tool with a set of plans to do a job. Other times, a hammer and some intuition will do. You could put the dremel, drill and plan holder and pencil holder into one tool much like C++ tries to put everything into one tool. Anyone out there own anything like that?

As for complexity, they discuss it like it’s a good thing, rather than simply an occasionally unavoidable thing. I chalk this up to machismo rather than intelligence. In humans, intelligence expresses itself as using the easiest, most appropriate tool for the job.

So I’ll stick with generic freely downloadable C# or VB (which at this point are more or less the same) which run on that much hated, and ubiquitous Windows OS for most work and save c++ for those ever fewer occasions when it provides cost-effective utility.

Cheers!
Ian