Tuesday, July 31, 2012

C++: Why or why not?

These days, I'm most integrating with native libraries, although web browsers are interesting, too. (See perhaps NaCl and Emscripten on the latter.) Some of those libraries export C APIs. That's nice for reuse across languages. Some (Bullet, Skia, ...) do best with the raw C++. This makes interfacing more difficult. One of the best ways to use C++ libraries is to code in C++.

And truth told, especially with C++11, I don't mind coding in C++ myself these days. I like type inference and closures. Bothering with shared_ptr, weak_ptr, and unique_ptr isn't the end of the world, and it gets most resource management done. Eclipse CDT has passable (although quirky and not always reliable) support. On a fast CPU, I can almost survive compile times.

On the down side, C++ is still a complicated beast. I'm not sure I'd like to see results of newbie code in C++ as they try out fancy features (which sometimes really are needed for clean code, too). I also don't understand everything myself. I get the point of C++11 move semantics, for example, but I don't really understand how to use it. I'm sure I could, if I spent time on it, but I sort of hover around "I need to get to that someday" mode. And it's such a bother to have to understand such details. Many other such examples exist in the beast.

Also, there's the issue that I'm really tired of needing to declare functions before defining them and the whole header vs. source files. It seems a small thing, and I could argue their virtues, but it's one of the things I'm most tired of.

In the end, for just getting a job done when I need to integrate, I think C++ is the easiest way to go, and it really is possible to write clean and portable code. However, the warts and slow compiles really grind on me. I'd also like a good implementation I could use everywhere, open standards not withstanding. Maybe that'll be Clang someday, if Windows coding support goes up. Maybe.

I wish the language in my head would fly out automatically with amazing C++ integration support included.

No comments:

Post a Comment