I totally hate C++. And every day my hate grows up. But that is not just about my programming language religion. We should look deeper.
I know C++ pretty well. I’ve read all the stuff like
Effective C++,
More Effective C++ and
Modern C++ Design and understand all of it. And it was really hard. Now I can do amazing things with templates and write robust error-free code. Do I want it? No. It is still really hard for me (and for everyone, I guess) to write, read and maintain such a code. That snippet looks really ugly in C++:
for (std::vector<double>::iterator it = values.begin();
it != values.end();
++it)
DoStuff(*it);
And here is it’s C# equivalent:
foreach (double value in values)
DoStuff(value);
And I’m pretty sure (I have some experience, you know) that 99% of equivalent code pieces are much more simple in C# than in C++. When you read and maintain a lot of code, it is very important.
Next, I hate includes. There is no good reason for good programming language to have such a non-obvious and non-robust way to incorporate different subsystems or just pieces of code. Really! IDE can do it for me! In .NET there are no problems with include paths. And I can just reference some library to get access to it’s components. No precompiled headers, no include (or lib) directory setup. That’s all about rapid and easy development.
And the last thing that’s important for me: in most cases (except of writting really performance-sensitive code) you should not care about memory deallocation at all. Execution environment can do it for you. Rather quickly. And it does. How much errors have you ever had with memory allocation and deallocation in C++? I have a lot. More than any other kinds of errors. It’s like a pain.
But, of course, C++ is fast. Really fast. In computer vision and 3D rendering there are a lot of very performance-sensitive stuff. And the only choise you have is to code it in C++. But don’t forget: there are wrappers for everything. There is
XNA,
Emgu.CV and
CUDA.NET. There is much more than that. You can still write performance-sensitive code in a managed environment with all it’s benefits.
I forget to mention wonderful tools for .NET developer such a
Resharper,
FxCop,
StyleCop and many others. There are no technical possibilities to create such a useful and powerful tool for a non-managed language like C++.
Let’s sum up:
.NET (C#)
- Easy language to code, read and maintain.
- No problems with library version control, includes and stuff.
- Fast and robust garbage collection.
- Very powerful standart library.
- Cool IDE and tools.
- Quite fast.
C++
- Really fast.
- There is Boost.
So that’s my proposal: when you want to code something, think about implementing it in C# first and consider C++ as the last option. I’m pretty sure you’ll like it as much as I do.