Sébastien Wilmet

: The life of a GUI application

Some generalities about the life of a GUI application. What problems are usually encountered as developers, with solutions.

At time t0 - decisions when creating a new app

When creating a new application, some decisions need to be taken. The ones that interest us in this article:

These are often inter-related. And we tend to choose the latest versions of both at the time of the decision.

Examples:

(Note that it's also possible to write one backend plus several frontends, to have for instance a GTK frontend, a Qt frontend, terminal frontends (CLI, TUI), and so on, without forgetting the web and the cloud of course).

First bursts of development

Once the GUI toolkit (and version) chosen, plus the HIG, the development starts!

One thing to note already is that the application developer is - in practice - limited by what the GUI toolkit provides (and what is easily consumable). Even though it's possible for the app developer to implement custom widgets based on lower-level API, it's much harder to do so and many app developers don't go that route.

So what the GUI toolkit provides shapes what the application looks like, how features are presented to the user and how they are implemented.

We would prefer to have as few frontend code as possible, to focus on the backend and features, but in practice we realize that the frontend is not that easy to implement, after all. A GUI application is not a batch program! Especially if we want to create a real product with a long lifetime, and a revenue stream (incidentally).

Several years later, the GUI toolkit and HIG evolve

This is a fact of life, design is in constant evolution. As such, the HIG evolve, and the toolkit API typically reflects the changes over time (be it with API that become deprecated, or with new major versions that introduce new APIs and new ways of doing things).

But we have created an application! Most users like it the way it is, and perhaps we are earning a living thanks to it.

So, what to do?

By implementing the new design, we know that it will attract potential new users. Also to not become completely irrelevant a decade from now. But it has its own risks.

In my humble opinion, the perfect HIG/design doesn't exist. All have strengths and weaknesses. As a consequence, radically changing the design of an application will make some users unhappy, and contributes negatively to the churn rate (temporarily, we hope so).

From a technical point of view, adapting the codebase to the new HIG and API can involve a lot of work (it depends on how big the application is; an older application usually has more features). When we heavily modify the code, there can be regressions, etc. It's sometimes possible to quickly adapt the code, but then the code is awkward to read and would need a lot of cleanup afterwards (it's a technical debt). If that cleanup is never done, the codebase becomes messier and messier, with bugs lurking a bit everywhere. (The general stability also contributes a lot to the popularity of the application, so technical debt must be taken with care, if at all).

Some solutions to keep the best of both worlds

Having a clear separation between the backend and the frontend is a good solution. "Only" the frontend code needs to be adapted or rewritten. The backend can be written in a library fashion (it can be an internal/static library with an unstable API, or a shared library with more API stability guarantees). That way, the backend will have a longer lifetime.

Give to the user the choice between several design alternatives. Like it is done by LibreOffice, for example: when starting the application for the first time, ask the user what he/she prefers (with also the option in the preferences dialog to change our mind later).

Or follow a software product line approach: have a different application for each main design/HIG. With as much code in common as possible between the different apps.

When adapting to the latest HIG is too much work

As outlined above, adapting the frontend to a new design paradigm can be a lot of work. It's technically possible, but if the developers lack the time, it won't be done, especially if everything already works fine.

That said, it would still be valuable to port the application to the newer versions of the GUI toolkit. Because at some point the older toolkit versions become obsolete and no longer receive security fixes.

This is where there can be a problem: if the newer GUI toolkit versions have removed the mechanisms for the older HIGs.

Example: GTK 4 and older GNOME HIG mis-support

To make the discussion concrete, let's give an example with GTK and GNOME.

GTK 4 still has some support for the traditional UI with a menubar and toolbar. But the API has completely changed compared to GTK 2 or the first GTK 3 versions. And certain things are just no longer possible to do (as far as I know; correct me if I'm wrong), such as putting icons in menu items, or showing a longer description in the statusbar when a menu item is hovered with the mouse.

So basically, GTK 4 has removed some of the mechanisms needed to implement the older design. As explained, it's just software, so an application is able to implement this itself with the lower-level APIs, but it's a lot of work.

Thus, some application developers are stuck with older versions of the GUI toolkit. Without good solutions at their disposal.

Sandboxing as a solution

We mentioned the security problem of running apps that use a very old version of a GUI toolkit. The solution is to run such apps sandboxed, in a container or virtual machine.

Developing a GUI toolkit - mechanism versus policy

I fully acknowledge that developing a GUI toolkit is not an easy task. Here are some general thoughts / philosophy about how things could be better from the toolkit point of view. (Easier said than done, as usual).

I first heard about "mechanism versus policy" when reading the beginning of Linux Device Drivers (see chapter 1, The Role of the Device Driver). A device driver should expose all what the hardware is capable to do (the mechanism). Then higher-level software can choose how those capabilities can be used (the policy).

For a GUI toolkit, we could envision a clear split between the mechanism (with a low-level API) and the policy (with higher-level API, following a specific HIG).

The mechanism API would be more stable over time. Without feature removals. But since it's low-level, it's not the most convenient to use. But it would always be there, in case an application needs it.

The policy API would be more subject to changes, since the HIG evolves. But it doesn't prevent older policies' APIs to be kept around.

(For GTK's case, there is already GDK as the low-level API, but GDK 4 is completely different from GDK 3, to follow more the Wayland peculiarities. And the mechanical way of creating classic menus in GTK 3 has fallen through the cracks in GTK 4).

Conclusion

Developing a GUI application that has existed for a long time (several decades) is very different from developing a brand-new app. But - some day - the new app will sooner or later face the same kind of problems. So I wanted to put some perspective, and give some advice.

If you've followed some courses on software engineering, or just have read some books (on the subject), what I described in this article should be familiar. Since I talked about libraries (both for the application codebase, and obviously the GUI toolkit as well), the problem of re-usability directly comes to mind.

So as a conclusion and to give you some food for thoughts, here are some quotes taken from Facts and Fallacies of Software Engineering (Robert Glass):

Reuse-in-the-small (libraries of subroutines) [...] is a well-solved problem.
Reuse-in-the-large (components) remains a mostly unsolved problem, even though everyone agrees it is important and desirable.
Reuse-in-the-large works best in families of related systems and thus is domain-dependent.

Happy hacking!

Even though it's not possible to write comments on this blog, don't hesitate to drop me an email. I do read them, and like to have feedbacks.