[GSoC] Getting started

Today is the start of coding for Google Summer of Code 2013. This year I was accepted by DUNE, a Distributed and Unified Numerics Environment. It is a toolbox for solving partial differential equations, and as a student of Computational Physics I have some experience with that.

My project, however, won’t be directly related to differential equations. Instead, I will provide a tool for measuring, storing and analyzing the performance of DUNE applications. This project consists of several parts, and the final workflow will look like this.

  • Measure the time spent compiling and running a program
  • Store the result into a database, so they can be compared with previous data
  • Perform statistical analysis on the data, find outliers, general trends, and quantify optimizations.
  • Visualize the data as a HTML page with pretty graphs
  • Upload local data to a central server, where performance of the same program on different computers with different compilers can be compared
  • More statistics and visualizations performed on the central server

DUNE currently has helpers for some of the parts (log format, uploading), but the project will still require a lot of work with different languages and frameworks. I plan to use Python for the most part, but charts will require JavaScript. I will also start with some example DUNE programs, which will be written in C++.

My work will progress roughly in the order written above. I’m starting with a small script that measures the  running time of a program and writes it to a logfile. I’m leaving for a conference in England after this week, so I hope to complete at least this first item by then.

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.


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?

Loud talkers be-gone!

In the venerable words of ESR, every good work of software starts by scratching a developer’s personal itch. One of such itches of mine was the fact that my mother is very (VERY) loud when talking on the phone. Invariably, I had to turn the volume down every time she called me, or at least hold it away from my head.

No more, I said last week, and promptly wrote an app for that. It’s called Personal Volume and allows you to have customized per-contact call volume settings. I only have a handful of such contacts listed, but it really feels like a great headache-preventer.

The app is now available on the Google Play store for free. See it for yourself here.

[GSoC] Templates in KDevelop – Final Report

This year’s Summer of Code is coming to an end, and so is my project. I’m spending the last days until the “pencils down” date reorganizing the code, looking for crashes and memory leaks, and writing online documentation. There are no groundbreaking features since the last report, but the functionality is becoming really solid, and I have a feeling that everything is coming together.

During the last weeks, I made sure that any kind of file template is supported by KDevelop, but only Class and Test template get special attention with additional assistant pages. I’ve ene put together a small flowchart of the assistant to illustrate what pages each type of template gets. Because templates can expose their own custom options, one can write some complex templates with no changes to KDevPlatform code. To test code generation for other types of files, I added a template for CMake Find modules. This means that writing almost any kind of boilerplate can be avoided with a good template.

I also tried to make creating new templates as easy as possible. Apart from a toolview which gives you a preview of the current files as it would be renderer as a template, it is now also possible to extract any loaded template archive, edit it manually, and then import it back with KDevelop. I believe that most people will try to use an existing template with some minor edits, so this is an important usecase. Additionally, there is a project template that generates a project with a single class template.

I would also like to thank my mentor, Milian Wolff. He really stepped in during the last month, not only giving me advice but even fixing my mistakes. The template selection now looks much better, and is consistent between project and file templates.

Finally, I had to document all this. I wrote specifications for both kinds of templates, added tutorials for creating new templates, as well as instructions for using existing ones. Writing may not be the hardest part of a summer project, but it’s certainly the least enjoyable for me, so I hope that what I did produce is both understandable and sufficient.

[GSoC] Class and Test Templates in KDevelop


I have generalized the “Create Class” dialog, so that it starts with a template selection page that is similar to what you see when starting a new project. It offers you a selection of templates of different types (currently only Class and Test) and programming languages. Selecting a templates leads to further assistant pages, which are chosen dynamically depending on the selected template’s type.

The first page of the “Create from Template” dialog

I have added wrapper classes for template rendering with Grantlee (KDevelop::TemplateRenderer) and template archives (KDevelop::SourceFileTemplate), so the assistant only deals with those to keep the code clean and readable. Both class and tests use the same format of template archives (described here), only with a some different variables.

As you can see from the screenshot, there’s already quite a few available templates to choose from. Considering a template only has to be written once, every project could have one or more preferred templates for new code. Existing ones can always be re-used, or maybe just tweaked slightly, so a little work can improve coding style and consistency.



[GSoC] Templates in KDevelop – Week 5

My last report (here) was full of pictures, but since then I’ve spent more time polishing the functionality, behind-the-scene improvements, and fixing bugs. However, the mid-term evaluation is approaching, so I think let everybody know what’s the state of things. I’m happy with my progress, my schedule was a bit vague, but I think I’m ahead of it. So far I’m still enjoying it, and I bought a more comfortable chair, so I have little problems with working long hours.

I split out some functionality to make code more modular, which also allowed me to write unit tests for much of the newly added classes. The main parts of the code (TemplateRenderer, TemplateClassGenerator and TemplatesModel) are covered with test cases.

Class Templates

My main focus was still on templates for creating new classes. I slowly decided on the variables passed to templates. They are also documented, and I think I can start writing more templates about now. The C++ plugin adds some variables of its own, such as namespaces,

Since KDevelop’s Declarations must always point to a location in a source file, they cannot be created directly, I had to add my own classes for describing code before it is generated. This way, data members of a class can be declared. These code description classes are very simple, with only a couple of members, and are written so that Grantlee templates have access to all their properties.

The state of template class generation is such that it covers all functionality of the existing “Create Class” dialog. I have already written a basic C++ template that produces the same output. Of course, it is possible to create different classes, such as ones with private pointers, QObject’s macros, or in different languages.

Writing the Class Templates

As I said, I already wrote a template for a basic C++ class, as well as one with a d-pointer. Since I figured a lot of the code would be shared between templates for the same language, I added some basic templates that can be included. These are for method declarations, argument lists, namespaces, include guards, and some other small conveniences. There is also a library of custom template filters in kdevplatform. The end result is that the templates themselves can be relatively small. I even reduces the amount of whitespace in the rendered output, so that templates can be more readable while the generated classes are compact enough.

However, I don’t think it’s practical to store templates and filters for all possible languages in kdevplatform. So I intend to add a way for templates to specify dependencies on language plugin. Of course, they could still be written from scratch, or simply ship with the needed includes. It is merely a convenience.

The plan is to have language plugins provide some of their own templates and filters, but so far they are only for C++.

Templates, Templates Everywhere

Of course, KDevelop has other utilities for code generation, and I figured templates would be useful there as well. I started with inserting API documentation. The previous implementation manually constructed a Doxygen C++ style comment. I replaced that with a renderer template, which now supports C++, Php and Python.

Pressing Alt-Shitf-D on a declaration of a C++ functions results in this

API documentation with Doxygen for C++

While doing the same thing on a Python function produces this

API documentation with reST for Python

Not only is it formatted in reST, the most common format for Python documentation, but it also is positioned below the declaration, as a true Python docstring. Obviously, we still need to convert __kdevpythondocumentation_builtin type names to python types, but stripping a prefix can be done within a template thanks to Grantlee’s built-in filters.

[GSoC] Templates in KDevelop – Week 2

So, I’ve been working on KDevelop for two weeks now, and it’s time to show some results. My summer project revolves around templates, not in the sense of C++ angle-bracket templates, but templates for source code files. The goal is to auto-generate the boilerplate code.

Sharing Application Templates

KDevelop already had a basic template support. When you create a new project, it gives you a choice of all templates installed by KAppTemplate and a couple of its own. However, those only come from official sources, and while it’s possible to install new ones, there is no GUI way to do it.

So I started by implementing both downloading with GHNS and loading local files.

The “New Project” assistant, with buttons for loading templates

Loading from file works for .zip or. tar.bz2 compressed archives, in which case it simply copies to the directory where all templates are stored. You can also load .kdevtemplate files, the program automatically archives its containing directory and stores it.

Downloading more templates works pretty much as expected, currently there are only three templates available for download, but I plan to make some more.

Application template download dialog

It is also possible to share template right from KDevelop. I have added a new configuration modules, where all different types of templates are listed. From there, you can import, download or upload template files. So far, there are only project templates, but they will soon be joined by class template and possibly others.

Template manager configuration module

The project creation logic works exactly as it did before, the same variables are accepted, so all old templates work. The only exception is that now folder names can have placeholders as well.

Class Templates

Seeing as the current class generator in KDevelop is not very configurable, I wrote a new system that uses templates. However, contrary to creating a project skeleton, classes usually have variable numbers of members, and function signatures look different in every language. To allow loops and other complex constructs in templates, I used the Grantlee template engine, written in Qt by Stephen Kelly. I will add some custom functions (filters) for it, but even without it basic use cases are covered.

To allow this, I modified the “Create Class” assistant a little. The most user-visible change is allowing an arbitrary number of output files, not just two. The following is for a template with a private class declared in a separate header, useful for shared d-pointers.

Choosing output file locations for a template with three files

The template engine already handles most of the properties class functions can have. It is possible to group class members according to their access, have slots and signals declared together, handle constructors and destructors separately, etc. What’s missing is a simple way to declare members before creating the class. Currently, only functions which can be overloaded are offered, but no data members.