Slashdot Mirror


Software Engineering of GUI Programming?

cucucu asks: "After ten years of programming for the network, I started programming a GUI Desktop application. My problem is most GUI tutorials out there are nothing more than a taxonomy of buttons, dialogs, and check-boxes. So as I checked GUI toolkits, I found that I can easily learn all the widgets, layouts, callbacks, and the like, and start coding a GUI application. However, very soon I found myself repeating code all over the place. Is there a good guide (online or off) for the Software Engineering aspects of GUI programming, so that I can learn how to reuse code, and build my class hierarchies over the one provided by the toolkit?"

11 of 116 comments (clear)

  1. Re:Dont code GUIs... by dave1791 · · Score: 3, Informative

    Errr... there are still controller classes; those nastly little things that sit behind your gui. The last I looked, you had to do at least SOME coding. But in general, the ui elements themselves are just painted now.

  2. Digg me down. Wait, wrong site by BladeMelbourne · · Score: 2, Informative

    I don't have any links to provide, but these few tips might be useful:

    1) Don't duplicate code. The second time some functionality is used, create a library function. Try to think of the variations required and maybe add extra parameters to the function to cater for them.

    2) Be consistent in your approach (similar wording on dialogues, standardized placement of objects, consistent use of terminology).

    3) Think of your user. Determine your minimum resolution (eg 800x600). Will some users want keyboard navigation/use of your application?

    Sorry if this is stating the obvious, but these 3 are rather important on my product (ASP.NET/C#/JS).

  3. Re:I'd be surprised if there was a guide by Bazouel · · Score: 3, Informative

    The article you mention is total bullshit to me. If one know how to use a modern GUI toolkit correctly, then his whole point on code reuse/repetition disappear. I mean, has he ever heard of UserControls? Of MasterPages/Forms? What about using a single DropDownList instead of multiple RadioButton? And when he shows how he could reduce the code size by using a for loop, it is totally bogus. This code is LESS efficient that the generated one!

    --
    Intelligence shared is intelligence squared.
  4. Threads and GUI by DimGeo · · Score: 2, Informative

    Something I've learned the hard way: Never modify any GUI stuff outside the main event loop thread. Well, in Win32 it is possible to get away with it (but you must know what you're doing - i.e. painting to a back buffer is OK, but not drawing into a window). In Swing/AWT you can use SwingUtilities.invokeLater(Runnable) (don't pass anything that extends Thread to it or you will make uncollectible garbage). There must be something similar in the other GUI frameworks out there.

  5. Re:Mono and Gtk# too by modeless · · Score: 4, Informative

    Generics, for instance, are a much-needed feature - but Microsoft didn't bother to implement it for ArrayList, the data structure that I use most often.

    ArrayList is still its original, non-generic self for compatibility reasons, but the new List<> class is its excellent replacement in the System.Collections.Generic namespace, along with the generic Hashtable replacement, Dictionary<,>. Don't know why they felt the need to change the names, although ArrayList->List was an improvement...

    Other than that, I agree. I'd just put events and delegates farther down under the "completely suck" section. They were really botched and it makes certain things a lot harder than they should be. Also, I'd mention the single greatest thing about C#, IMHO its saving grace: C/C++ interop. The design of the interop with legacy code is nothing short of brilliant. It's five minutes work to wrap and call a random C function, no matter if it takes pointers to weird structs or even a callback! And because of that, C# actually stands a chance of displacing C++ as the language of choice for Windows applications.

    If only Microsoft had fixed it to allow distributing C# applications with their own stripped-down runtime included, instead of requiring administrative install of the full 20+ MB .NET Framework including ASP.NET and who all knows what crap you don't need, it probably would have replaced C++ for many applications already. Something like perl2exe for C# is what I want. Just bundle the runtime and the JIT and your code up in one nice tidy ready-to-run executable. That would do wonders for the adoption of C#.

  6. A good article to start by neves · · Score: 2, Informative

    I wholeheartedly recommend this Martin Fowler's article to start with.

  7. Reliable Software through Composite Design by Latent+Heat · · Score: 2, Informative
    My all time favorite software engineering book is Glenford Meyers, Reliable Software through Composite Design. The book predates OO and is based on a module/function tree/hierarchy model of a software system. The book comes up with these module "strengths" ranging from "coincidental" (taking reoccuring sequences of code and calling it a module -- considered weakest reason) to "functional" (making a module out of code that has a simple declarative sentence description -- considered the strongest reason). The book has a lot of discussion regarding whether a repeated sequence of code merits its own module.

    As the book predates the widespread use of OO, it has a kind of proto-OO or proto-object in the form of "communicational" modules -- collections of functions that operate on some common data organized in a data structure or a name space. The communicational-strength module, of which there is a lot of support in Modula-2 and pre-OO Ada, is kind of like a static or perhaps a singleton object, and the reason for this kind of programming is that back in the day dynamic memory allocation was regarded as being fraught with peril -- either too expensive or too risky in terms of heap fragmentation. Remember also the computer speeds and amount of memory that we had compared to today. Classes and their objects are really the communicational module applied to where you have good heap management algorithms and perhaps even GC as well so you dynamically allocate an allow multiple instances of things and don't worry.

    I wish there was a latter edition of "Reliable Software through Composite Design" that addressed OO in some ways, but Martin Fowler's works on refactoring comes close. What I also like about Fowler is that all of his refactorings are reversable so if you find that you have too many code snippets in functions, inlining the code snippets and eliminating the functions is an "allowed" process instead of something you are scolded into never doing.

    As to cut-and-paste, whenever you see yourself using the text editor to copy any block of code to replicate the same functionality, you are asking for some kind of trouble at some level. The whole problem with cut-and-paste is that your code is littered with multiple copies of the same function, perhaps with some minor variations, and if you have a bug in that sequence or need to revise that common functionality, it is a lot of work to search it all out in your code and fix it.

    On the other hand, many times that repeated sequence of code doesn't lend itself to a proper kind of function and you have so many customizations of that function or flag parameters to that function (Glenford Meyers really lays into flags as function inputs and explains why -- I guess Microsoft didn't read his book when doing the Windows API).

    A lot of the idioms of programming languages -- loops, functions, objects, macros, anonymous functions, etc -- are efforts to avoid cut-and-paste, and if you are programming in a weak programming language (dunno, like .bat or perhaps VB), you end up with cut-and-paste to do the job rather than wrestle with the language. At some level, some degree of repeating yourself in code is unavoidable and introducing higher-level languages (closures? functional programming?) to avoid this may be unavailable or perhaps in itself introduce obfuscation if these features are generally not known to your maintenance programmers. So if you are left with some cut and paste, don't sweat it.

  8. ActiveX, Delphi, Type Library Editor by Latent+Heat · · Score: 2, Informative
    The remark about the evil of ActiveX controls is sort of like remarks that since people in occult cults listen to rock-and-roll music then people who listen to rock-and-roll are susceptile to occult cults or belong to them (or some variation thereof).

    ActiveX is a remarkably powerful system for visual component software -- restricted to Windows, yes, but supported by many programming languages ranging from VB through Delphi to Matlab. It is also remarkably crufty so to either develop for it or to use it you end up using some form of "wizards" and automatic code generation. And yes, the use of ActiveX on Web sites, especially malicious Web sites is evil, but such things like Flash and some of the free anti-virus sites are delivered through ActiveX. You could also disable all Internet ActiveX and still be able to use client apps on your computer using ActiveX -- there is hardly a major Windows app that doesn't use ActiveX at some level anyway, so if you are to dismiss ActiveX, there is little you can run under Windows.

    Delphi is a remarkably powerful tool for developing ActiveX controls as well, and I like it better than the VS/VC++ approach because I find it to be more flexible in tinkering with COM interfaces until you are ready to publish the control. Delphi ActiveX development requires some faith in wizard-generated code (actually, GUI development in Delphi is remarkably free of wizards and auto-generated code because the VCL base classes have so much of the functionality in them, but ActiveX in Delphi requires it). You will also have to become friends with the Type Library Editor -- the Delphi way of writing and maintaining the IDL code that is the plumbing of COM and ActiveX. The Type Library Editor is buggy and has its quirks, but I find it much more powerful for inspecting and modifying COM interfaces than any of the MS tools.

  9. Decouple It by RAMMS+EIN · · Score: 4, Informative

    I didn't see this mentioned in other posts, but I think it's very important:

    Decouple your GUI from the code that does the work.

    I really don't have a lot of experience with GUI programming, but I do know that there are many different toolkits on different platforms, each comes with its own guidelines, and these guidelines are subject to change over time. At some point down the line, you or someone else is going to want to change the GUI, while keeping the functionality. Moreover, you or someone else may want to drive the application from a script, or from the command line (some platforms may even require one or the other for applications that are considered good citizens). In other words, your application _is_ going to have more than one interface - make sure that is easy to accomplish.

    --
    Please correct me if I got my facts wrong.
  10. Nesting and Abstraction by RAMMS+EIN · · Score: 3, Informative

    I've built a lot of web pages, and this has made me realize that it's incredibly quick and easy to whip up GUIs with HTML. The experience was much better than with the GUI builders I had used, and certainly beat coding GUIs by hand.

    Of course, HTML is not intended as a language for describing native GUIs, so it has some limitations there. Fortunately, there is a variety of XML formats for describing real GUIs.

    What makes XML so great for describing GUIs is that it's so good at describing nested objects. If you think about it, that's exactly what GUIs are: you've got your windows, with a bunch of widgets in it, one of which is a scrollable area with more widgets in it, etc. This is naturally described by an XML tree that contains all these widgets, with some attributes used for connecting them to the application; e.g. ids to allow the application to reference widgets, and embedded code to let the GUI respond to events (e.g. HTML's onclick).

    Where many XML GUI languages fall short is in that they don't provide methods for building new abstractions. If you have a lot of subtrees that are all very similar (say, a frame, a title, a content window, and a hide and a show button), you'll completely have to code each of them in full. Any programming language worth its salt will provide a way to abstract over this (functions!), but I think the realization that XML GUI descriptions (and HTML documents!) are programs hasn't fully set in yet.

    Next time I'm coding a GUI, I'll be generating the XML from a proper programming language. I've had good results with Lisp before...

    --
    Please correct me if I got my facts wrong.
  11. Re:I'd be surprised if there was a guide by computational+super · · Score: 2, Informative
    Most of his "problems" boil down to, "You're still going to have to write your own code anyway, regardless of what you do in the GUI builder," which I answer with a great big, "Duh!"

    So - the original developer, and every subsequent maintenance programmer need to now understand not only the core language, but all of the subtle nuances of the tool that controls the UI in addition to the myriad ways the two interact (or fail to interact). All in the interest of simplifying GUI construction? I think you just made his point for him.

    --
    Proud neuron in the Slashdot hivemind since 2002.