Today I’d like to share a revelation with you:
Developing C++ can actually be fun.
In the next sections I will tell you a bit about how I develop KMix today, and why the newest toolchain gave me a productivity boost. As a peek ahead, this post is mainly about developing KDE applications with Eclipse.
If you just came across this post via searching for Eclipse, C++ and cmake, then you might want to directly head to the practical example at the end of this post.
The core message is that the environment you work with can have a very high impact on productivity. As an example, see the picture to the right from my office: Isn’t this a more comfortable environment than – a cubicle? OK, I was talking about productivity, wasn’t I? So lets forget the image quickly. 😉
The C++ nuisance and rant
Honestly, most of the time C++ development is a nuisance for me. For a better understanding, you should know that I am a 95% Java developer nowadays. And if you do a lot of Java, C++ is full of strangeness:
- Incompatible Headers (try to compile http://thrift.apache.org/, if you are really masochistic)
- Too many standards (SUSv3, misc POSIX variants, various C++ standards, half-implemented)
- Nearly worthless constructs like volatile (https://www.kernel.org/doc/Documentation/volatile-considered-harmful.txt)
- Complicated threading, no real Unicode in the standard, and so on and so forth
CMake and Eclipse as a rescue boat
If you get good tool support, C++ can still be a very good language. CMake helps a lot. For the source code editor it is more complicated: In the past I used every viable tool for KMix development, including misc versions of emacs, vi, aXe, kate, KDevelop and Eclipse CDT. All have their own strengths, but I could use none of them well for KMix development. Then recently I did a new shot at Eclipse CDT (Kepler based), and I am actually delighted.
- The CMake integration now works flawless for me
- The C++ indexer is super-fast and reliable (a massive weakness in former versions)
- Navigation for header to source and back finally works and is very fast. Signals and Slots are parsed correctly and can be navigated.
- Call hierarchies work great most of the time. In some C++ specific constructs they do not work, but using “references” is a good alternative.
- Even the strangest #define and #include constructs work as expected.
- Warnings, Errors, TODO’s and so forth are shown by default very appropriately in the editor and the other Eclipse Views. Very comfortable if one is accustomed to Eclipse.
KMix is a pretty small project, so mileage may vary for your project. Still I recommend to try “Eclipse Kepler CDT” if you have not done so recently. It brought back the fun in development for me.
Practical guideline for developing KDE applications with Eclipse
The basic step to build an Eclipse project is:
cd kmix-git-trunk.obj; cmake -G”Eclipse CDT4 – Unix Makefiles” ../kmix-git-trunk
As a reference, kmix-git-trunk.obj is where I build kmix, kmix-git-trunk is the GIT checkout. After that you can import the project into Eclipse. Run the above command again whenever required and refresh the whole source tree in Eclipse (F5) after that. Personally I am using Eclipse only to edit the source code, to navigate and browse quickly through sources, headers and includes. Everything else I am doing from a console window, like building, running,
debugging and version control (GIT).
(Update 2013-12-16: Debugging works fantastic from within Eclipse, so I will use that from now on)
Thanks if you read until the end. If you have any input, experience or feedback, please leave a comment.