After this long new trial with C++, I feel like I’m sliding into back into C, although I’m still searching for the right balance.
It’s not that I don’t appreciate OOP, it’s rather that C++ seems to be truly messed. There is a wealth of tricks & tips, templatized this and that.
I must admit that the language is truly powerful. It allows one to do things in so many ways… but at a practical level, it has some very dull issues. I understand that C++ had to make compromises to keep the performance up. However, it doesn’t really give much hope to those that wish to do clean OOP.
Again, the single biggest issue is the fact that one must declare all members of a class in the header, including the private ones.
I think I’m right to assume that it’s a good coding practice to split larger function/methods into smaller ones. The so called “helper functions”. With C++, every time one writes an helper, he/she has to go back into the include file and add the declaration for that function.. ..for large projects, we are talking about a lot of them. So much for C++ being sold as the language for large projects !
This is a real pain for someone that has worked with Java. Java has some implicit performance issues that I don’t like, nor I like the fact that it doesn’t support callbacks. However, it’s a language truly committed to OO, and it’s nicer towards the programmer: no need to copy and paste every single function one writes !
Keeping at the practical level, the fact that one has to expose the internals of a class along with its public declaration, it means that the code that simply wants to use the class (the user-code), may have to include a lot of useless additional header files.
For example, let’s assume that I do a 3D library. Internally it uses Direct3D, some private functions will use pointers to D3D texture objects. The user-code will be forced to have Direct3D headers included. This lacks of elegance, but, most importantly, can sensibly slow down compilation times.
Many C++ promoters will promptly answer that there are ways around this. Like, for example, building a hidden base class that the user-code sees as a pointer (thanks to forward class declaration). This however adds more work to do, possibly more include files… takes time on the programmer, and, personally, makes me feel like my code is not tidy.
My apartment often ends up being messy, but my code, I really want that nice and simple. I need a streamlined way to write code that looks good.
Posted by Davide Pasca in Uncategorized
