Archive for the ‘Programming’ Category

[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.

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?

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] 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.

Zabava ob izidu KDE 4.8

Po enoletnem premoru se tradicionalno druženje ob izidu proste programske opreme skupnosti KDE spet vrača. Ob izidu različice 4.8 si bomo najprej ogledali, kaj se je v zadnjih dveh letih dogajalo v drugi največji odprtokodni skupnosti in predstavili nekaj največjih novosti namizja Plasma in ostalih programov. Sem spada tudi posebno novo okolje Plasma Active, ki bo letos na voljo na tabličnih računalnikih. Predstavili bomo tudi nekaj izmed načinov, kako se lahko svojimi prispevki in izkušnjami pridružite skupnosti KDE. Osredotočili se bomo predvsem na prevajanje in programiranje.
Po predstavitvah sledi druženje s pijačo in kakim prigrizkom. Po načelu »kdor prvi pride, prvi melje« bomo razdelili tudi nekaj daril.

Predavatelji:

  • Jure Repinc je študent računalništva, ki v svojem času poskuša čimveč prispevati k raznim odprto-kodnim projektom, v največji meri pri KDE.
  • Andrej Vernekar je zaposlen kot vodja pisanja tehnične dokumentacije, v prostem času pa prevaja KDE-jevo programsko opremo in je koordinator slovenjenja KDE ter predsednik društva LUGOS.
  • Miha Čančula sem študent fizike, ki pri projektu KDE razvijam šahovski program Knights in Cantor, ki je vmesnik za matematične programe

Lokacija:

Kiberpipa (zemljevid)

Povezave:

http://community.kde.org/Promo/Events/Release_Parties/4.8#Ljubljana

English version

Knights 2.4.1 Released

Today Knights has reached the stage where some exciting new features are completed and usable. The new release includes saving and loading PGN files, setting the difficulty, and supporting the UCI engine communication protocol. I also added a move history widget, which can display the moves so far in three different notations.

Playing against Stockfish, a strong chess engine using UCI

A handful of new themes appeared on kde-look which can be downloaded from the Knights configuration dialog.

St. George theme by Dave Kaye, with visible history and clock widgets.

Move history can be save quickly from the history widget, or from the dialog which appears after a game is over.

Knights can be downloaded from their usual site at kde-apps:

Getting into Web Development

I’ve always been a desktop guy, preferring to use desktop applications over web ones wherever possible. And since I started programming, I only wrote desktop applications with Qt and KDE. Maybe it was the whole paradigm, or just a lucky choice of language and toolkit, but I liked it immediately and soon learned to feel at home with programming. I got used to C++, it’s strictness and plenty of compile-time error checking.

It was only recently that I decided to broaden my horizons. I got a smartphone, I’m using both a desktop computer and a laptop, so I’m starting to find it easier to store non-sensitive data in the cloud. I’ve had GMail for a long time, WordPress as well, and even used Facebook until I deleted my profile because it was a waste of time. This movement of course reflected on my programming as well. After writing Opeke and Knights (C++/KDE), contributing to Orange (Python/Qt), I have decided it’s time to learn something new again.

Platform Choices

The first problem I encountered was the choice of platform. On the desktop, everything is free (at least as in beer), no matter if you choose Windows, Qt, Gtk, or something else. You  write a program, other people compile and run it. After you’ve written the code, that’s it. On the web, everything is different: you (as the author/developer) have to run the application on your own infrastructure, and more importantly you also have to cover the cost. Fortunately, there are a couple of options that do it easily and cheaply. There’s probably more, but these three are the most used ones:

Amazon Elastic Cloud

Image representing Amazon Web Services as depi...

Image via CrunchBase

It lets you run any OS, but you have to manage the entire software stack yourself. This options grants you the most freedom, and it’s easy to migrate you application from here to a dedicated host and back. This is in my opinion the best option, if it weren’t for the price: the smallest package (micro instance) costs around 15$ a month, even if you don’t use it very much.

There is a free tier that lets you run the 15$ package for free, but it only lasts for a year. I’ve tried it with my http://noughmad.eu website, and it’s noticeable slow even with a small number of visitors (I had around 100 per day). I understand pricing gets better with volume, so as long as you’re prepared to use your own computer or another dedicated host while learning, writing and testing your app, it could be useful when your app is ready for the public. Yet again, because of it costliness, it’s not really appropriate for non-commercial fun projects.

Google AppEngine

Image representing Google App Engine as depict...

Image via CrunchBase

Unlike the Amazon cloud, Google provides a complete managed software stack. This means less work and worries for you, but it comes at a heavy price: Only Java, Python and Go are supported. The runtime environment (especially the database) is designed with scalability in mind, rather than compatibility with existing systems, so porting an app to and from GAE is not trivial.

Still, it’s possible to develop apps that will be compatible with the App Engine and still work without it. For Python, this can be done with Django and django-appengine. For Java, you can use GWT for presentation and JDO for database objects, both of which can work on GAE and on your own server. However, you always have to keep in mind the restrictions Google’s datastore imposes on your data query to ensure scalability.

Windows Azure

It comes from Microsoft, so I’m not touching it. I don’t even know what it offers, but from what I could tell it’s not free, which means bad news for a hobby programmer.

My Choice

I chose to start with Google App Engine. The main reason was cost: It’s free for small apps permanently. Out of the three supported languages I only know Python, so I used that, combined with the power and comfort of Django. There is a large number of modules for it, including Dajax (asynchronous requests) and a REST framework (to easily create an API).

Appearance

Another important difference between desktop and web programming is application visual appearance. On the desktop, the toolkit will guarantee a consistent look and feel with other programs, so you don’t have to think about how your buttons look. You just create a button, and users will see it will all sorts of decorations and text effects, and it will be just like all the buttons in all other programs.

On the web, the default appearance with most browsers looks like horrible. You have to specify the style of every single element of the page, setting colors, borders and layout. The separation between content and appearance is nice, but it would be even nicer if I didn’t have to worry about the appearance at all.

My First Web Application

For the learning experience, I decided on a task management tool. You can find it at http://ntasks.appspot.com. It’s not much yet, and most certainly it doesn’t look like much, but I’m starting to like Django so maybe it’s going to progress faster in the future.

Upcoming features in Knights

I haven’t been lazy since the last stable release of Knights. Three highly-awaited but not difficult features have made their way to feature branches and will be included in the next release.

Saving and loading the move history

Knights can now save a finished or in-progress game to a file using the PGN notation, so that users our other programs can load and analyze the game. Such files can also be opened, in which case the saved moves are replayed.

I am also planning to add a view of the game history, probably a simple list at first.

UCI protocol support

Many chess engines, most notably Stockfish, make use of the Universal Chess Interface. The basic operation of passing moves between the engine and the interface works, but I’m still working on other features (pretty much only draw offers).

Difficulty setting

Chess engines usually don’t have any explicit hard or easy modes, but you can limit their search depth. Having the computer only consider a small number of moves on advance makes its game weaker. It is also possible to reduce the size of the program’s memory hash, further reducing its strength.  Fortunately, both XBoard and UCI support this setting, so there is no need for differentiation.

Difficulty Settings in Knights

Try it

I decided that keeping a stable master and developing in feature branches is the easiest approach for me. So this work is still in branches ‘pgn’ and ‘uci’. I will merge them into master as soon as all translatable strings are fixed.

I would be especially happy for any testing and input regarding the difficulties (currently still in branch ‘uci’, will be merged real soon), are they too easy, too hard? Are they noticeable at all? I’m not a good player, so it’s hard for me to rate the skill of engines.

Update: I merged both branches into master.

Follow

Get every new post delivered to your Inbox.