Jakob Vase

The problems with GUI programming

Hey.

So I’m a developer, I do a lot of GUI, it sucks.

There are lots of problems with GUI programming. The worst ones include: The complexity of the frameworks in use, how fiddly it is to get something to behave the way you want it to, and the problem of separating GUI layout, GUI design, GUI behaviour, model rules, and model data.

Let’s go through some of the frameworks I’ve worked with, how they tackle these problems and what they could do better.

WinForms

WinForms is the ‘old’ Microsoft GUI framework. Many people still swear by it though, so it’s still actively updated and maintained.

Features:

WinForms is not a complex framework – at least not initially. Most of the day-to-day stuff programmers want to do in GUI is readily supported, and that’s a huge help.

WPF (Windows Presentation Foundation)

What a name. WPF is the new school (new as in 2007 new. Not new new), where bigger, better ideas were had. I believe it is in fact more usable than WinForms – but there’s a catch…

Features:

HTML, CSS, JavaScript

The holy trinity of web development. It’s not terrible.

Features:

So what do we do?

I think part of the problem of GUI programming is that no one language easily encompasses all we want to do. Web development has the right idea with so neatly separating layout and design, but JavaScript is not the best language to write big production code in. The data binding of WPF is really interesting, but has other problems – I have to put my validation logic in the GUI, or let my model get into bad states while people go crazy in the GUI, and then fix it when they leave me alone. Somehow, validation belongs in the model. The GUI should only care whether something is valid or not, not what it is that makes it valid.

Another problem with both WPF and HTML (but not so much with WinForms) is the prevalence of ‘magic strings’ – string names for things that has some meaning elsewhere in the application. These are the things that break when code is updated. How should I know that this string was used over there for that purpose?

I think we need a complete package. Where GUI is taken as seriously as the deeper model, and where the communication between GUI and model is easily facilitated. This is not easy.

Layout – HTML has proven to be a great way to layout and structure an interface – but not so much for binding data to a model behind it. And it has the problem of magic strings. If these two problems could be eliminated, I believe HTML could be one cornerstone of every GUI in the future.

Design – CSS has problems – but it also does things right. I believe the CSS people (over at Mozilla) are too focussed on it being purely the way it is. I believe it would benefit greatly from variables, from using XML-selectors instead of the weird pseudo-selector language it uses now, and from a more clear focus on what is applied where. I think a new language based very much on CSS should be made, that could take design to the next level.

Behaviour – There is nothing I know of that tackles behaviour right. I think behaviour should be able to be added much like CSS-design, with maybe a library of standard behaviours that is all that most people want?

Data binding – WPF has the right idea with binding the text or variables of a control with some underlying model behind it, but the separation between View and Model hurts it some, and the problem of the Model not being able to apply validation on it’s text hurts more. I believe it is time for a programming language that allows for validation on variable-basis. If my Match class has a Score field of int, I want to be able to set some limitations on that. It can’t go below 0. It can only increment by 1 at a time (assuming soccer). Or whatever. It’s max value is tied to the number of socks in my drawer. While I still believe there should be a layer of separation between GUI and model (Eric Evans calls it the Application layer), I believe the GUI should still be able to update the model quite directly and vice versa. Maybe something like int currentGoals = bind Match.Score. Yeah.

What about Client-Server architecture? What about CQRS? What about some other stuff I don’t know? I don’t know yet. Haven’t got that far. I don’t think what I’m thinking is impossible though. I think I’ll formalise a list for good GUI frameworks later.

Other stuff I’ve tried

I’ve made minor GUI stuff in Java’s Swing and Apple’s cocoa too, but I haven’t dug deep enough to tell you how fiddly they are. Swing was pretty hard to understand and pretty fiddly, but it was my first, so maybe I would just understand it if I went back. Cocoa is C++, and I’m no shark there. Maybe the perfect GUI-framework already exists somewhere, and I’m just not aware of it. Oh the travesty.