Zwabel’s Weblog

March 13, 2009

Really rapid C++ development with KDevelop4

Filed under: KDE,KDevelop — zwabel @ 8:52 pm

Code Assistants
When developing for a statically typed language like C++, there usually is quite a bit of redundancy during the development, especially when creating a completely new piece of code. A powerful IDE with deep code understandic theoretically could save a significant amount of the writing work. My goal with KDevelop4 is to allow the user only to concentrate on the “content” of the code, without wasting too much time with creating or adapting declarations in several different places.

To reach this goal, code-completion is not enough. Sometimes it is not possible to properly guess what the user wants to do during typing, but once a statement is completed, it becomes clear. Also the completion-list is not suitable as a user-interface for everything.

During the last weeks I have implement an Assistant architecture within KDevelop. In general it is kind of similar to the bulbs or paperclips known from several office applications, with the main difference of actually bein useful. 🙂 An assistant can watch the happenings in the editor, duchain, etc., and pop up a non-intrusive popup with some keyboard-accessible options as soon as the assistant thinks it can do something useful for the user.

The first assistant I implemented already more than a week ago was one that could automatically adapt changed function-signatures of declarations and definitions. Personally I hate having to do exactly the same thing twice, thus this thing compes very handy. As soon as you significantly change a definition- or declaration-signature, you will see this:
At the bottom you see the assistant popup. Every popup has an associated action with a number, and you can execute the action using the ALT+Number combination. So you will get this effect:
This is already a quite useful assistant, since it saves you from a part of C++ that I personally sometimes find a bit frustrating. But not any more. 🙂

Automatic Declaration Creation
There is other much more significant types of redundancy when programming for statically typed languages. One such example is iterator names. Why do I always have to write out their name completely? Even with code-completion, it sucks, since the iterator variable type is logically completely determined alone by the value you assign to it. Now with KDevelop, you can save a lot of this. If the type of the variable is determined by the assignment, just don’t write the type by yourself, but let the IDE do it for you:
Just push ALT+1 and get this:

Now when you’re designing an algorithm, you can just write as if you were writing python, and let KDevelop create the variable declarations for you:
The assistant gives you this:
But it gets even more interesting. If you try calling a function that does not exist yet, you will get this option:
And the assistant will give you this, notice that even the return-type has been correctly matched to the context:

This also works within the local class:
Here the result, notice that the return-type is automatically a reference when you assign something to it in the call:
Together with all the other conveniences of KDevelop4, like automatic adding of includes, automatic creation of function-definitions, a class-wizard that correctly places all the includes and writes added files into the CMakeLists.txt, the Qt Documentation Integration, Code-Browsing, etc., KDevelop is a really productive IDE.

Development Update
This is one of the few large features that I yet wanted to implement before a release, now there’s not many major features left on my todo list. Although I’m quite sure I will get some more ideas, the next major task is improving the usability, killing all the little bugs, and improving the performance and scalability of the duchain store so it doesn’t get slow once some size has reached.

The other parts of KDevelop are doing ok, but unfortunately the debugger still hasn’t made it into a usable state, it’s the one big gap that’s still there in KDevelops functionality.


  1. only one word: awesome!!

    Comment by mario — March 13, 2009 @ 9:16 pm

  2. only one word: awesome!

    Comment by mario — March 13, 2009 @ 9:18 pm

  3. Yes, this is really, really awesome work. This will be tremendously useful, can’t wait to try it out…

    Comment by Thorben — March 13, 2009 @ 9:25 pm

  4. One other idea:

    If you try calling a function that does not exist FROM A CLASS that inherits another class…could you then have the following options?

    1 – Declarate function in [Class]
    2 – Declarate function in [SuperClass]
    3 – Declarate and inherit function in [SuperClass] as virtual

    Essentially, immediately refactor a new function call to either the abstract parent class or interface.

    I know, this has huge propagating problems. But not even Visual Studio has the ability to “Promote method to abstract class/interface.” (it can extract everything to a new parent class, but not promote a particular method to a particular parent class).

    Comment by twilightomni — March 13, 2009 @ 9:28 pm

  5. This looks great. KDevelop4 is quickly shaping up to be amazing – I can’t wait for the release! Keep it up with the innovative features.
    On a side note, @mario: that was two words 😛

    Comment by ffejery — March 13, 2009 @ 9:31 pm

  6. @twilightomni: I will probably add some kind of simple user-interface where you can pick a superclass to declare the method in.

    And Declarate, argh, what an ugly typo of me, should be “Declare”, but i’m not going to take the screenshots again. 🙂

    Comment by zwabel — March 13, 2009 @ 9:35 pm

  7. This is witchcraft! Witchcraft I tell you! 😀

    Cool thing, kudos 🙂

    Comment by Ivan Čukić — March 13, 2009 @ 9:48 pm

  8. wow

    One thing, the assistant’s tips are a little hard to (mentally) parse, it would be useful if they had some highlighting, in most of the cases syntax highlighting like normal code.

    In the first case (update/replace rather than inserting new code) it might be useful if the parts of the definition that are proposed to be changed were also highlighted somehow. Also it might be easier to read if the old version was above the new rather than having them side-by side.

    ❤ KDevelop ❤

    Comment by maninalift — March 13, 2009 @ 10:14 pm

  9. Computers are only really useful for removing repetitive work. Declaring a function in a header file and a source file is repetitive work.

    As long as it doesn’t try to do anything non-intuitive, it will remain awesome and not become like the MS-Office paper clip.

    As it sits right now (and merely based on the screen-shots) it is awesome!

    Comment by Michael "Paperclips suck!" Howell — March 13, 2009 @ 10:16 pm

  10. Hooray for type inference!

    Comment by Soap — March 13, 2009 @ 11:15 pm

  11. Excellent work! KDevelop4 is on it’s way to become one of the best IDE on the block 🙂

    Comment by Luiz — March 13, 2009 @ 11:31 pm

  12. Thank you for your great work; this looks very cool!

    Comment by mike hancock — March 14, 2009 @ 2:08 am

  13. I’ve been using this for the past few days on my laptop/desktop. I’m very pleased, it’s already helped me save some frustrations. (I would get annoyed when I made a change, then went to jump to the def/decl to make the other change…. and I couldn’t because now they were noticed as two different functions)

    I will mention that on my laptop’s lowly 1024×768 screen the blue box is cut off and is completely un-understandable as a result. If I hadn’t read it first on my desktop, I wouldn’t have a clue what it was supposed to do nor how to use it. Maybe it would be a good idea to have it line wrap if it is larger than the application window?

    Comment by Andrew Stromme — March 14, 2009 @ 3:43 am

  14. You know that there will be life after KDevelop 4.0 too… Ie, isn’t it better to spare some features and bring out a stable IDE instead?

    Comment by Sam — March 14, 2009 @ 6:54 am

  15. Speaking of stability, how is KDevelop4 in that area.

    Looking at the new features just makes me want to dump QtCreator right now (and that’s saying something since QTCreator is swell too).

    It’s just I can imagine it being frustrating haveing to restart the IDE too often.

    Any tips much appreciated.


    Comment by David Mills — March 14, 2009 @ 8:26 am

  16. @David Mills: KDevelop4 has made enormous progress, it crashes only about one time during a day of full use, it used to be a lot more than that for me. However, I still run kdevelop in gdb and so I can report the crashes with backtrace, it’s amazing how fast they get fixed 🙂

    Comment by Thorben — March 14, 2009 @ 8:47 am

  17. This is great work David.
    Using KDevelop4 is really bad for my vi usage. It is the first time ever that I really miss features in my work-flow there. All because I’ve used KDevelop for about 20% of my coding time in the last weeks.

    Comment by Jos — March 14, 2009 @ 9:21 am

  18. Wow wow wow. This is really an Intelligent Duchain Extension :-p

    I have a few idea’s for the tooltip:
    – put the suggestions below each other.
    – instead of the button, have the text “Alt+#: ” before it (makes it much more obvious how you can use it).
    – put it some part of the code, e.g. instead of being long and verbose about adding variable type have the following as suggestion:
    “Alt+1: bool result = …”
    “Alt+0: hide”

    Either with the dots literally, or the full line with added part in bold — so it kind of suggests how it would write the code.

    – instead of “Declarate ..” I’d use “Add declaration: *void SomeClass::someFunction(someargs)* ”
    – perhaps the types or added part in a bold font.

    I’d love to know what you think of this 🙂

    Comment by Diederik van der Boor — March 14, 2009 @ 9:32 am

  19. Some months ago I switched to QtCreator since it’s stable, integrated, with fast workflow and works good.
    !! But here you’re telling that I can save some % of my lifetime with an improved-productivity IDE !!
    Ok, I’m installing Kdev4 right now, but if I see some crash/lose some code… I’ll drop it and never go back again 😉

    Comment by Enrico Ros — March 14, 2009 @ 9:34 am

  20. @Diederik van der Boor:
    I Agree, the actual text in the assistants is too much, and hard to read. It needs to be reduced a bit. Showing the whole shortcut instead of just the number is a good idea, but would be counter-productive in the current version, because it would make the texts even wider. 🙂
    The assistant architecture has an option to show each option in a separate line, but I think if this was used by default, the popup would reach too far into the coding window, and would thus start to be annoying of not desired.

    Some highlighting in the tooltips would be nice as well, but isn’t that easy to do, since the semantic highlighting is bound to the editor architecture. But at least some simple highlighting of making some parts bold would probably be enough to make it better readable.

    Comment by zwabel — March 14, 2009 @ 10:27 am

  21. Do you guys have support for in-line notifications, similar to NetBeans?

    It flags a line with a notification in the margin when you can do something special to that line. Clicking on the little icon in the margin (similar to a breakpoint mark) reveals the menu with the full list of modifications for that line. (“Declarate new function”, etc.)

    The in-line-margin method of notification seems much more space-conservative than the current big-banner-pop-up idea, and it can be adjusted to handle more than one notification, and for the user to come back to them later (since they just have to go the line where the notification is). I imagine once you close your Assist Popups, they’re gone forever.

    So perhaps that’s a better notification paradigm. If it’s not there though, certainly don’t waste development time on it this version.

    Comment by twilightomni — March 14, 2009 @ 3:53 pm

  22. @twilightomni:
    You also get all the options by right-clicking the yellow underlined text in the editor for the assistants based on specific code problems.

    And when you leave+re-enter the line, the popup will appear again for them.

    What you’re proposing is not really an interesting option, because it requires switching from keyboard-input to mouse-input, while a good workflow allows you staying with the input device you’re using(And while programming, it’s the keyboard)

    Comment by zwabel — March 14, 2009 @ 7:00 pm

  23. […] Really rapid C++ development with KDevelop4 Code Assistants When developing for a statically typed language like C++, there usually is quite a bit of redundancy […] […]

    Pingback by Top Posts « — March 15, 2009 @ 12:16 am

  24. Wow that’s freakin’ great. 😀

    Use ESC instead of alt-0.

    Started using trunk KDevelop a couple weeks ago and I love it. I think its only crashed a couple of times (I had it open for several days at one point).

    Comment by Ian Monroe — March 15, 2009 @ 12:48 am

  25. Maybe the suggestions could be shortened to “Create method”, “Create private method”, “Create variable”, … etc? In most cases we can already guess what the signature would look like.

    I quite like the way IntelliJ IDEA does things. It shows a light bulb next to the code you are updating. When you click the bulb or press Alt+Enter you will get a context menu with suggestions.

    Comment by Andy Goossens — March 15, 2009 @ 12:59 am

  26. I really tried this time, but Kdevelop crashed *so many times* that I have to go back to QtCreator..
    What I found during the tests:
    – the C++ engine KICKS ASS! is the best out there, period. it helps you so much.
    – the IDE is *painful*, crashes are so widespread that using kdevelop is like walking on a very dense minefield and definitely you *can’t* use it for your daily job (unless it’s testing the kde crash handler)

    Since you have the BEST C++ Ass Kicking, real Life Saving engine out there, it’s now time to focus on the IDE. By seeing your posts, people assume that KDevelop is at least in a ‘usable’ state and then they get bitten so hard that they may not try it again next time.

    Comment by Enrico Ros — March 15, 2009 @ 11:05 pm

  27. @Encrico Ros:
    Well, me and many fellow developers are using nothing else then KDevelop for quite some time. It works very reliably if you only use the core features like the C++ support, navigation, etc.. Actually my KDevelop hasn’t crashed for days.

    There is peripherial stuff like multiple main-window support or the debugger that are untested/unstable. But anyway, if you encounter a crash, you should report it. It might as well be some misconfiguration or miscompilation on your system(Tends to happen).

    Comment by zwabel — March 15, 2009 @ 11:17 pm

  28. I have been following this for a while and love this new work. It is great and just wish I could use it at work not just at home :-(. A few questions:

    1) What happens if you already have a function declaration?

    class A {};
    class B {};

    struct C {
    void do(A arg1);

    void f()
    A a;
    B b;
    C c;; // Can produce void do(A arg1);; // What now happens ?? Do you have a choice to add either an overloaded function or a template? Will it also update the definition if already written?

    2) Does it ever do anything with passing references to functions or does it always assume the object is copied?

    3) What does it decide about const? It seems from the screenshots that it is making some decision.

    Thanks for all the work on this it is superb stuff.

    Comment by Paul — April 15, 2009 @ 1:01 pm

  29. What’s the status of php integration?

    Comment by php — May 31, 2009 @ 9:38 am

  30. Almost prefect. What happens when you press hide? This is kinda important error in line should still get marked hopefully.

    Of course that is on top of Pauls problems.

    About the only thing I could think to top this is auto duplication of code prevention. You are coding away and ide notes the code you just entered has very similar code else where in program and reminds you of it.

    Comment by oiaohm — June 1, 2009 @ 12:28 am

  31. […] اطلاعات بیشتر در مورد این قابلیت جدید، به وبلاگ توسعه دهنده آن مراجعه و برای دریافت نسخهٔ جدید از یکی از سرورهای KDE […]

    Pingback by KDevelop 4 Beta 3 منتشر شد « دنیای بدون دیوار — June 1, 2009 @ 4:59 pm

  32. […] اطلاعات بیشتر در مورد این قابلیت جدید، به وبلاگ توسعه دهنده آن مراجعه و برای دریافت نسخهٔ جدید از یکی از سرورهای KDE […]

    Pingback by خانواده گنو/لینوکس ایرانیان » Blog Archive » KDevelop 4 Beta 3 منتشر شد — June 1, 2009 @ 5:16 pm

  33. […] the third public beta of KDevelop4. This release includes some major new features, such as a new code-writing assistant, a new documentation plugin showing you the API docs for Qt and KDE APIs, a reworked Mercurial […]

    Pingback by KDevelop4 Beta 3 Released | World Boxx — June 1, 2009 @ 7:49 pm

  34. Everything looks nice, but…what’s the deal with that font? Can’t we just get MONOSPACE fonts in there by default?

    Comment by Impressed — June 3, 2009 @ 4:46 pm

  35. @Impressed: Monospace is the default. This one is my personal preference, as I don’t like to waste horizontal space.

    Comment by zwabel — June 10, 2009 @ 12:18 am

RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

Blog at

%d bloggers like this: