Friday, October 13

some reasons I like C++

I've been thinking lately (actually I had a talk w/ L about C++ and this started everything) and I wanted to post something on the reasons I like C++ (compared to C# and java at least);

So, let me see ...

First, there's the whole "destructor call being made at a determinstic time". Garbage collected languages don't do this; they only guarantee the destructor will be called sometimes before the next Big Bang.

This allows automation of writing some tasks (which can be further extended by using generic functors and execution sentinels), leading to one-liners for adding state rollbacks, finalizing (committing) transactions, releasing resources, exception-safe allocations (yes, I know this is not an issue in the other two languages, but I like the degree of control), and releasing race condition locks.

Second, there is the whole template system. I don't mean here the
ok, you have a list supporting only Foo objects, so you have type safety
bla-bla-bla, that all C++ courses will tell you about in the first lesson.

That's ... not really spectacular.

It's the other, less visible capabilities you get; optimizations by type, completely hidden to the outside world (see the separate implementation of std::vector<bool> for an example).

It's the capability of using type traits, allowing one to switch from std::string to case-insensitive strings by only implementing case-insensitive comparision operators in a std::type_traits<char> structure and instantiating the std::basic_string template.

It's also the ability to add metadata to the system in an efficient matter, symilar to the C# code attributes system (except for two aspects: first, it's not defined by default, second it's implementation - if you need one - can be anything you choose).

Then (third if you will) there is the flexible (customizable) input/output system (although I have seldom seen code that actually takes advantage of it), the extensible memory management features (new and delete transparent overloading and the std::allocator usage), the operators overloading and I'm sure I could think of more.

No comments: