Recently I have been messing around with the Glade interface designer, a rapid application development tool that allows you to create full GTK+ user interfaces very easily. The neat thing about this tool is that it saves the GUI as an XML document, which is then hooked into your code through various language specific ‘sketchers’. These sketchers read in the XML and generate the corresponding ‘native’ code interfaces – often at runtime. There seems to be a big push toward these types of XML-based user interface solutions, Microsoft is pushing XMAL through its Windows Presentation Foundation technology as just one example, and it got me thinking: is this really the best way to go?
XML offers a number of unique and interesting benefits when compared to the classic programmatic style of user interface creation. For one it represents a true separation of the “view” from the logic of the application. This is incredibly important to a long-term modular design. In addition, by storing the user interface in a file external to the application itself, it allows for complete GUI changes just by updating the single XML file – you don’t even need to recompile the code! This is a huge benefit when testing how users interact with various interface designs or changes and makes A-B testing a snap. Similarly if you want to have various custom front-ends to the same application, say a basic user interface as well as an administrator interface, you can simply distribute your application with two different GUI files. Finally, and most importantly, XML is completely language independent. Thinking about changing your application code base from C to Python? No need to re-write your GUI. This in turn leads to better GUI-specific development tools (like Glade) that aren’t constrained by any language’s particular quirks. The flexibility of XML is where this approach really shines.
Depending on how it is used XML can have not only a performance impact but also a security one as well. Both of these are especially prevalent when using external GUI files. For instance, a program that loads the GUI from an external file must first read and parse said file every single time the application starts. This is an operation that would otherwise have been avoided by using a pre-compiled programmatic GUI. Next while the ability to completely swap out the GUI without re-compiling the code is pretty cool it can also lead to some… unintended consequences. Take this bit of Glade XML as an example:
<widget id=”myWindow”>…<signal name=”destroy” handler=”on_myWindow_destroy”/>…<widget id=”myWindow”>