Rants on software, computing, and any other topic I feel like.

Tuesday, January 10, 2006

C++ is not dead.

There has been some recent speculation about the death of C++, since the C/C++ Users Journal has ceased publication. So is C++ dying?


C++ as the one and only language for application development died a long time ago. Java has taken over what once was COBOL's place as the language of business logic. If you're writing straightforward code that is going to be used by the five other people in your company, then Java is for you. It holds your hand and doesn't let you make many mistakes. It has lots of libraries for those who have no desire or brains enough to write their own. Not that I think Java programmers are stupid, some of them aren't. I think that Java, like many other scripting languages, allows you to be stupid, and still write code that works ... mostly.

But yes, Java should take over the role of "Business Language for Dummies". C++ was never good at that. But since there wasn't anything else around at the time, that didn't stop people from trying. Which is why we have so much C++ code that sucks. A lot of stupid people tried to use a language that requires some brains. C++ isn't for dummies. It's for people willing to take the time to learn the language. And as I've said before, that requires understanding of C++, not just C. So C++ gets a bad rap.

Some people say that C++ is dying because C does everything that systems developers need to do. Well, so does assembly, but they only use that when they have to. C++ adds a lot of features that most systems developers don't even know about, let alone know how to use. Real programmers only need while loops, but that doesn't mean that for loops aren't useful. How about template metaprogramming? How about virtual functions instead of function pointers? How about references instead of pointers? Can you create a new numeric type in C and have it act natively? And get the compiler to optimize and inline all of that code? Can you write recursive algorithms that can get inlined completely?

All the excuses claimed by C wielding systems developers come down to two basic problems:

1. There isn't a C++ compiler for my platform.

2. C++ is hard to learn. All them fancy templates and classes are just too complicated.

Ok, some systems developers may have an excuse on number one, but since g++, one of the most standards-conforming compilers out there is available on like 20 platforms, chances are your processor is supported. So it's less of an excuse than you think. It's probably going to optimize your code a whole hell of a lot better than the craptacular C compiler that came from the vendor that barely compiles to correct assembly half the time. I love to hear the words, "But C is faster than C++.", coming from someone who is knowingly using a substandard C compiler. If your compiler sucks, then does it really
matter what language you use?

Number two is just ridiculous. Anyone who has learned about C, pointers and recursion, should be able to learn the features of C++ with some effort. Will it take a little work? Yes. But learning C took some work too, didn't it? C++ is the next step. Really learning C++ is going to take as much effort as learning C did, even with your C knowledge.

So C++ is dying because Java is better for writing code to organize your CD collection on the one end and C is better from writing systems code on the other end. In the middle we have real application development, which C++, turns out, is pretty good at. How do I know this? Because as a manager from Microsoft once told me, 90% of code at Microsoft is written in C++.

No, actually, I don’t think that C++ is dying. Spare me.


This page is powered by Blogger. Isn't yours?