I would like to hear some opinions on hand coding your GUIs as one typically do when using Java or Qt with C++, vs using a gui-designer tool? Examples of GUI designer tools would be MFC GUI-designer, Qt designer, Interface Builder (Apple).
I used to be a fan of hand coding but from recent experience I have switched. The problem I have seen with hand coding is that it is fairly quick and flexible to write the GUIs but once you need to make a change to a GUI written a long time ago it can be very difficult. Finding the right element in big panel can be difficult.
The second problem is that it makes it far too easy to add a lot of logic in the GUI creation and layout code. I have often had to take over maintenance of GUI code which is really hard to reuse because its behavior is mixed with its appearance and mixing layout and behavior often makes the class very large and difficult to understand.
Using a GUI designer tool force a much clearer separation between appearance and logic in my view.
I feel strongly that you should use an interface builder instead of hand-coding a GUI. As in the question mentioned it's a much cleaner separation and once something has to be edited it's much easier.
The Qt Designer got this feature to create a class out of a
.ui
file1), but I think that not using this feature is the best way, as this creates just more coded that shouldn't exist at all. The speed issue of creating the window from a.ui
-file is negligible because the window has to be loaded only once.This is PyQt, but something similar is possible in C++:
Essentially this has the same effect as including all your UI-code into the
__init__()
method, but the UI is almost completely separated from the code.1)
.ui
files are XML files that describe a user interfaceMy view on this: 1. Hand-coded GUI code is much more reusable 2. Layout issues are simpler with designers
Funny enough it has gone the other way round for me. Talking from Winforms perspective, the code generated by the designer is quite noisy, with maybe a quarter or half of all the property settings really necessary. Making pretty big controls is also more of a temptation when working with a designer. Changing some hierarchy of controls in the Winforms designer is quite a nightmare in my eyes.
In my last project I have created additional APIs to set up splitters in forms, dockmanagers, menus, toolbars etc. in a declarative fashion. These are such that they will further enforce separation of concerns.
I also try to rely much more on auto-layout features which admittedly are a lot nicer in WPF but can also go some way in Windows Forms.
It depends on the situation, really. I think both have their place, and I usually use a hybrid approach.
There are always some things that the GUI builder can't do (for example setting the color to a UIColor constant in Interface Builder). On the other hand, most of UI work is pretty mundane (for example adding static labels).
I prefer to do the mundane stuff in the GUI builder, and the more interesting stuff in code.
Also, I occasionally find myself editing the XML produced by the GUI builder (Interface Builder and glade in my case) by hand.
I do it by hand, it's a lot easier to shuffle things around and re-use panels inside the application (some panels can appear in several places).
Using a designer works when you're in a team the artists are supposed to do the GUI.
?? I've never seen that.