User:Boldingd/Sandbox/GuiProgramming/Libraries and Languages

Picking Your Environment edit

A complication in covering GUI programming is that there are a great many possible environment in which we might be working. We must select at least one concrete programming language and at least one library to provide us with graphical capabilities. There are, fortunately or unfortunately, a great many pairs of languages and libraries that we could choose between.

Unlike many courses, the aim here is to cover common concepts in a generalized and abstract way - the aim is 'not' to learn, say, GUI programming in Java SWING, but to learn the abstract and general concepts of GUI programming that will be consistent across all possible platforms. To that end, the student or reader is invited to select their own language and GUI toolkit; since this early choice may have great consequences for how the student interacts with the course, we will here provide some guidance. We do this both so that the reader will be aware of the options that are available, and so the student can make a wise selection from among them.

What Matters in a Language edit

What facilities are important in a particular programming language? For our purposes, two spring immediately to mind: 1) some capability for functional programming and b) some capability for object-oriented programming.

At least while we are starting out, functional programming is a very natural way to describe a callback; however, many modern GUI toolkits do not use functional programming as the primary metaphore for registering event handlers. Instead, most modern graphical libraries treat graphical entities as 'classes', and use overridden methods as the primary system for specifying and providing callbacks. This is a fairly efficient and natural way to work with graphical elements.

It is, of course, not essential: C does not support object-oriented programming, and yet Gtk - which is written natively in C - is a perfectly usable GUI development library. Perfectly usable, but somewhat awkward; Gtk must provide through macros and explicit functions many of the facilities that APIs developed in object-oriented languages get for free, which can make Gtk programs much more verbose (and much more repetitive) than equivalent programs written in other languages. This means that the student who selects a language such as C will have a much harder time than is required.

What Matters in a Library edit

Most libraries will support at least the basic set of interface components - widgets, as we will later name them - that we shall cover, so this need not be a concern. How exactly callbacks are described will vary greatly from library to library, and will of course also depend on the underlying language in use.

Likely one of the largest differences that will distinguish one GUI toolkit from another, apart from those dictated by the underlying language, will be the platforms on which it runs (or perhaps the platform on which it is most native). For example, if one wished to develop applications that would "behave well" on Windows and has little concern for other platforms, one would be best advised to select Microsoft's GUI development tools; if one wished to develop portable programs that would run on a variety of platforms, one would be well advised to select Qt or Java.

Another issue of particular import to the student is pricing. Fortunately, most GUI toolkits in common use are available for free - including, for example, Microsoft's free Visual Studio Express or Google's free tools Android Development Tools. Therefore, price need not necessarily be a concern.

A final point of particular interest is support for visual GUI design tools. Many modern GUI toolkits allow the user to develop GUIs visually - by dragging interface elements around in a visual representation of how their design will appear, as opposed to manipulating the code that will generate their interface. This is a valuable facility that will save the developer much time and anguish. Most modern GUI toolkits include such a facility; unfortunately, many older toolkits do not. The availability of visual design tools is a point that the student may wish to carefully consider.

A List of GUI Libraries edit

The above having been said, let us consider what libraries exist, and what features may recommend them (or discourage their use).

Java edit

Java is a popular language, and its use is common in many academic settings in particular. Java has not one but several GUI libraries -- both integrated with the language, and provided independently. Java Swing is an older tool-kit, but it is still popular. It lacks a number of modern features: it does not include an integrated GUI building facility, meaning that Swing GUIs must be built "by hand" in explicit code; its event-handling system is extremely primitive, and it is particularly awkward to add custom events to objects; and its platform integration is woefully deficient. Still, because it has been in use for a long time, and because it is integrated into the Java standard library, it is still in active use, and a large amount of supporting material has been assembled -- such as tutorials and documentation.

Recent editions of Java also include the newer JavaFX. This is a much improved and much more modern system, capable of making use of 2D and 3D acceleration. It has much better theming, supports modern animation, and uses a declarative (XML-based) mark-up language to build interfaces, so that explicit code is not required.

The third-party SWT kit is also available for Java. SWT has the interesting property that it uses native components on different platforms -- so that the same program looks like a Windows application when run on a Windows PC, like a Mac application when run on a Mac, or like a Gtk application (for example) when run on Linux. This is an appealing facility, given that native platform integration is often a very weak point in Java applications; however, it also can make deployment of your application an issue.

Qt edit

Qt is a popular open-source tool-kit. Qt applications can run on Windows, Linux and Mac systems. Like SWT, they have the property that they appear native when run on different platforms; however, unlike Java programs, though the source code remains the same, the program must be recompiled for different platforms. Qt is also well-recommended for its extremely sophisticated and flexible event system, it significant supporting libraries and its native and transparent use of OpenGL for fast widget drawing.

Qt uses C++ natively -- that is, it is a C++ library, designed to be used from C++ code. It is designed to be used with QtCreator, a GUI program for building interfaces. However, users will still have to do a certain amount of C++ programming, significantly when writing callbacks; this can be a disadvantage, as C++ is a difficult language to learn and write, certainly compared to Java or C#.

Qt also includes a newer facility, called Qt Quick. Qt Quick, as the name implies, is designed to make application production quick and easy. It uses a unique declarative language (based on JSON) to build interfaces, and it uses JavaScript as its programming language (so callbacks are, for example, written in Javascript). A minor weakness of Qt Quick is that it is still new, and has gone through a significant amount of change since its launch.

WPF edit

The recent Windows Presentation Foundation is an impressive kit. The underlying language, C#, is very similar to Java; it is easy to learn and easy to write for anyone with a background in C-like languages, including Java. C# also includes a built-in event system and support for functional programming, which can make even-wiring and creating custom events very easy. The WPF kit itself is very sophisticated: it uses a powerful interface-design language -- called XAML, based on XML, as the name might imply. XAML allows users to set bindings between the properties of different widgets, so that changes of the properties of one entity can change the representation on others; in some cases, this allows for the construction of entire interactive interfaces without any actual code. The system is designed to be used with the Visual Studio IDE, which includes a graphical interface builder. The major drawback of WPF is is that it is owned by Microsoft; though there is a free edition of the IDE and the development tools, it is available only on Windows PCs.

TK edit

TK is a widely-available graphical library. It was originally the minimal graphical library for the tcl language; however, the library was extremely compact, and so it has been included in a number of other scripting languages. Unfortunately, "compact and widely-available" is nearly the end of what recommends Tk: it is not a particularly modern or sophisticated kit, and GUIs built with it are hardly pretty.

Tk is of particular note because it is the native windowing facility of the extremely popular Python programming language. Though Python is an amazing language, Tk is an unimpressive kit; those wishing to develop GUIs with Python would be well-served to use some other graphical library. Fortunatey, many other GUI libraries -- including Qt, and also Gtk -- have Python bindings.