The Problem With C++

wow, way to go spreading FUD.

“it’s dangerous”? a programming language isn’t dangerous. an uneducated programmer is dangerous. if you can’t program well in something, either better your skills or stick to something you know.

by the way, is something just really screwed up with your CAPTCHA system, or do i just keep getting “orange”?

To me, C++ is a better choice for most embedded software, excluding UIs. Java and C# are preferable as you get closer to the user and performance becomes less of an issue. At the lower layers, though, there will always be a need for a C++ type language. These components are small in number, but very important still.

I work in the embedded (Linux) world, and the real problem I see is that there is still too much use of plain C: C++ would be a step up, but it hasn’t taken off. It will be interesting to see if Mono fares any better.

I think the one fatal flaw of C++ that prevents it from moving forward (in the guise of managed C++ or what have you) is its syntax. No one wants to write a parser for C++, and the toolsets for analyzing and generating C++ code are commensurately lacking.

I am on a legacy application that is C++, and I continue to do new development on it. My team is trying to evolve the app to .NET (you can’t beat garbage collection and no memory corruption!) With managed C++ and Microsoft Visual Studio, I feel like the weird aunt that is invited to Thanksgiving out of guilt, and the hosts keep giving me subtle hints that it would be okay if I went home early. I will move to C# as soon as I can not because it has better constructs than C++, but because it has better tools.

Jeff, I think you’ve settled into a comfort groove where you feel C# has ample speed for your needs. From such a position it is understandable to sneer at C++ for trying harder than it’s worth nowadays. But this “abundance” you’re seeing is a mirage – just imagine if every single application you use daily were written in a managed language. Visual Studio, firefox, winamp, Windows Explorer, Microsoft Office. The mental picture would be devastating. It’s ok for one program to lag slightly when doing UI; it’s a cataclysm when the whole system bends.

C and C++ will always be around, just like cement will be for construction.

The difference is these days we don’t need to worry about the cement and we can just get on with building the house.

  • DISCLAIMER - Cement may not always be around

It is only dangerous for incompetent programmers, real C++ programmers know there standard library and use reference counting pointers where needed. Having said that, you don’t seem to give any points yourself as to why C++ is dangerous, you probably don’t even know why Bjarne Stroustrup mentions all these points.

I would like to know what you are trying to achieve with spreading this kind of FUD and miss information? Did you ever use C++? Are you a D-programming language zealot that is insecure about his programming language or something? Or are you just uneducated?

Spoken like a true VB programmer. C++ is a very useful, powerful, and relevant language. No need to bash it because you don’t use it.

If you take the shooting analogy further, you would blow the whole guy away if you do it in C#. If a language is deemed “easier” it automatically requires less brains to do the job.

There’s nothing wrong with cement (concrete). We’ve been using it for thousands of years, and it should be good enough for a thousand more. Now just overlook the way it fails in tension, leading to problems with earthquakes and hurricanes, the way it takes lots of hand-built forms and hand-wired rebar, and the terrible insulation properties.

On the other hand, you could deliver a bunch of lightweight panels of carbon fiber/epoxy honeycomb with any old pickup truck, and glue them together at the job site. Maybe it’s time for a carbon-fiber programming language, too.

Bjarne’s response sounds very sensical. I do not see anything defensive about it. We should be using a wide variety of languages and some, like C++, should exist that aren’t dumbed down for casual programmers. And yes, there are still far too many idiot programmers employed these days…even after the tech crash.

The C language was wrongly misused for business applications. C was handy because of the notion of having one source that could be compiled on multiple target machines, yet have near Assembler speed.

Delphi (Object Pascal) became such a hit, and many, many commercial apps are written in it, because it allowed you to do business development quickly with a highly powerful language that could do most of what C or C++ could do, and usually match it’s speed. It has very good garbage collection, and it’s clear how the Borland engineers who left to go to MS have influenced the MS products we have today.

Borland’s internal reorganization aside, 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.

C++ is here to stay, at least for a while; 10 or 15 years at least. There’s just too much code already written in C++, especially libraries. Even if we are able to use all those libraries in all other languages, someone has to maintain the libraries.

Forget “D”, I really like the “E” programming language:
a href="http://en.wikipedia.org/wiki/E_programming_language"http://en.wikipedia.org/wiki/E_programming_language/a

"E is an object-oriented programming language for secure distributed computing, created by Mark S. Miller and others at Electric Communities in 1997. A concurrency model based on event loops and promises ensures that deadlock can never occur.

"The entire language is designed with secure computing in mind; this is accomplished chiefly by strict adherence to the object-oriented computing model, which in its pure form has properties that support secure computing. The E language and its standard library employ a capability-based design philosophy throughout in order to help programmers build secure software and to enable software components to co-operate even if they don’t fully trust each other. In E, object references serve as capabilities, hence capabilities add no computational or conceptual overhead costs. …

"In E, all values are objects and computation is performed by sending messages to objects. Each object belongs to a vat (analogous to a process). Each vat has a single thread of execution, a stack frame, and an event queue. Distributed programming is just a matter of sending messages to remote objects (objects in other vats). …

“E has two ways of sending messages: the immediate call and the eventual send. An immediate call is just like a typical function or method call in a non-concurrent language: the sender waits until the receiver finishes and returns a value. An eventual send sends the message while producing a placeholder for the result called a promise. The sender proceeds immediately with the promise. Later, when the receiver finishes and yields a result, the promise resolves to the result. Since only eventual sends are allowed when communicating with remote objects, deadlocks cannot happen. In distributed systems, the promise mechanism also minimizes delays caused by network latency.”

Reading the responces is interesting. I may be a hobbyist programmer but I’ve never understood why I need to consern myself with the dirt and grime of the lower workings just to write an application. As has been mentioned, it’s great for low level stuff, it’s great for cement, but it really isn’t friendly for high level stuff. I read dozens of people saying that if you can’t program well in C++ then get better, or you should give up. But tbh, I don’t want to need to program well in C++. I can, but for a Win32 application why should I need to worry about the ton of stuff C++ forces me to worry about just to get basic stability? Why can’t I concern myself more with ironing out the bugs in my application and making the code I’ve written to do what I want actualy does what I want rather than worrying about the lower levels? But I’m sure people will still cling to using C++ to program websites.

I’m never going to use E as long as examples show people protecting a ‘return’ statement with an ‘else.’ That’s why I don’t use C anymore–the same idiotic motif shows up in KR. And those guys were supposed to be good programmers. Gaaah!

“C makes it easy to shoot yourself in the foot; C++ makes it harder, but when you do it blows your whole leg off.”

C# makes it harder still, but when you do, you don’t know where your hit.

I don’t think it is right to just say that “C++ is fast” without qualifying such a statement. C++ allows you to optimize code at a micro level more than any other language that also has high-level features.

That said, most optimization problems occur at an algorithmic level. In those cases, I find that refactoring C++ code is typically far too difficult. It may merely be the lingering presence of header files, but C++ just lacks crucial malleability. Changing anything at all becomes a major chore.

C++ is the cornerstone of software engineering. Yet, as mentioned before it is a full spectrum language, which can be used either for low level or high level applications.
It is completely natural that other languages have been grown and evolved towards specific software types. And they probably do the job easier than C++ (trying to engineer a dynamic website in C++ would be a real fuss now)
Yet, one great thing about C++ is that its blazing FAST! And as it is really difficult to use and code with ,it may not be used for enterpise related applications- as they don’t have really great speed requirements (most of the time at least). But is used very much , and probably will keep up like this, in the research and academic facilities where speed does matter. I can’t imagine programming a simulation enviroment in java, as a run circle would take up as much as 20 times more than if it was created in C++.

As for the “C makes it easy to shoot yourself in the foot; C++ makes it harder, but when you do it blows your whole leg off.” I certainly disagree. C++ is an Object Oriented Language . Object Oriented Programing enables the programmers to do really careful code planning, memory management. Whatsmore every component/module can be tested/debugged separately and in a much easier way as OOP provides with the best support for unit testing.
This way totally efficient and fast applications can be programed, in cases where other languages would reach their limits (I cannot imagine how I could code an emulation enviroment which takes up 2GB of dynamic data into the RAM and perform constant and painful processing over them for more than a million emulation queries).

I don’t believe that C++ has somewhat lost its value, I just believe that the new wave of software engineers are not up to programing the “hard way”. Of course they are not oblidged to and it is best for everyone that they chose the best programing language to them (in means of stability, efficiency and scalability). C++ will definately stay around for 10 to 15 years, but it will not be massively used.

interesting. back in the 80s I used Lotus 1-2-3, starting with 1A. until 2.2(or 3) it was wholly assembler; thence C. I went from 2.01 (the last assembler release) to the C version. I could watch the screen morph, where before it just snapped. the machines were 8088, of course.

the moral of the story: there are 3 or 4 or 5 “levels” of programming, with 1-2-3 being one level up from systems programming. if that’s what one means by “application programming”, then C/C++/Assem is appropriate. OTOH, if a G/L (yet another) is what one means, then VB/C#/Delphi/etc. is appropriate. if one writes the G/L in C, one ends up writing a DSL, then the G/L. skip wheel inventing, and find a 4GL you like.

in between we find the java/C# world, which I’ve always thought were a bit schizo: trying to be both application and systems level.

C++ is great for what it’s great for, systems programming. What people often fail to realize is that no language is perfect for every task. When productivity, readability, and maintainability are your main concerns you’re much better off with Python (had to get a plug in). But you’d never use Python for a device driver, and you shouldn’t use C++ for a database program (although it’s way better for that than C).