Finally, KDevelop file templates

The title of this post is slightly misleading, because you can’t use them in the stable version of KDevelop yet. However, after months of laziness schoolwork, I finally managed to upload some to http://kde-files.org. This means that anyone running KDevelop master can now download some of the templates they need. So far, I only made templates for things I am using: QObject subclasses with bells and whistles (properties, signals, private pointers), QML items, and a differential equation solver. This covers all my current programming activities, although I do hope to write some code (and templates) in Java for Android and/or some web framework, preferably Meteor.

template-complex-qt

Example class made with a template, only by specifying its name and members. Note the proper insertion of const references for QString (which is known to KDevelop as a class), and lack thereof for QDateTime which has not been included and parsed yet.

Now, I am certain that at least some of you write code in different languages and framework. I would like to have some more templates ready for the 4.5 release, so people won’t go “oh, there’s only three” and never look at it again. I am having some trouble with non-C++ languages, because they all have simpler syntaxes with less boilerplate and fewer files. Java comes close, but I as far as I know most people use Eclipse with it. In C++, using Qt and all the best practices, you have to do the following for every class member:

  • Add a public member to the private class
  • Add a Q_PROPERTY() declaration to the main class
  • Declare a getter, and a setter if the property is not read-only
  • Declare a signal
  • Define the getter and the setter in the implementation file

In QML or ORM’s like Django, you only need a single-line property declaration, while in pure Python you don’t really have to do anything. Obviously templates, as pretty much all code generation, are much more useful in C++. I presume there are other examples of such complicated languages, or at least different uses of the same ones. So I ask you for ideas, what kind of template would help you write code quicker. They don’t really have to be classes, for example unit testing frameworks require quite a bit boilerplate code and could be sped up by using pre-made templates. What are the things you write again and again, but are different enough to not be able to simply copy?

Advertisements

2 responses to this post.

  1. Posted by Kyle on 22. March 2013 at 04:20

    What would be really awesome is to be able to point KDevelop at an existing database and have the ORM code be generated for ODB, QxORM, or Django (DJango auto generation doesn’t work that well). I have no idea how much work that would be though, or if it falls outside the scope of this. But in any case I know it’s something I’ve been trying to find for a while now.

    An easier idea would be to generate safe assignment operator methods and constructors. I haven’t used Qt’s implicit sharing mechanisms, but from looking at it there appears to be plenty of room for having generated code.

    In any case awesome work and thanks!

    Reply

  2. Hi,

    “What would be really awesome is to be able to point KDevelop at an existing database and have the ORM code be generated for ODB, QxORM…”

    To do this kind of things for QxOrm library : it is now possible with QxEntityEditor application.
    QxEntityEditor is able to :
    – connect to any kind of database ;
    – generate C++/Qt source code ;
    – all entities are registered into QxOrm context.
    More details here : http://www.qxorm.com

    Reply

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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 )

Google+ photo

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

Connecting to %s

%d bloggers like this: