Rationale for the Book

[ fromfile: rationale.xml id: rationale ]

At Suffolk University, we buck the popular trend and continue teaching object-oriented programming using C++. For many years we taught a standard one-semester OOP/C++ course that had the CS1-CS2 sequence as prerequisite and a data structures and algorithms course as corequisite. Our CS1-CS2 sequence was based on the C programming language for many years and is now taught in Java. In the OOP course students developed substantial mastery of the core C++ language, the Standard Template Library (STL), and an understanding of key OO concepts such as encapsulation, refactoring, and tool development. However, we found that STL is a library that often overwhelms students and causes them to spend too much time on low-level programming constructs and template issues. In addition, the naming conventions used do not encourage the kind of programming style we prefer. Furthermore, STL does not provide a basis for writing applications with graphical user interfaces (GUI), so another framework would have to be used anyway.

During the summer of 2003, while Qt 3.2 was the current version, we decided to develop a book that would approach OOP/C++ at a higher level. We wanted to provide a substantial introduction to GUI programming using the multiplatform Qt framework, and also to introduce and use some important design patterns. When Qt 4.0 was released, we did some extensive rewriting to accommodate the code-breaking improvements that it introduced.

We designed this book first as a textbook to be used in a university class, but we did so in an extensible way and included lots of information that can make it useful for readers with a wide range of backgrounds: from those who already program in C or another procedural language and want to learn OO and GUI programming, to those who have no C background but are familiar with Basic, Java, Python, or another programming language and want to learn C++. The first part of the book is aimed at familiarizing all audiences with basic C++ elements, OO concepts, UML, and the core Qt classes.

We believe that readers understand ideas best when they apply them, and we found this to be especially true with design patterns. Many of the Qt classes or code examples are concrete implementations of some of the more popular design patterns described in [Gamma95]. For each design pattern that we discuss, we make available the source code for our example and include exercises that challenge readers to reuse, refine, and extend that code.

Reuse of libraries requires an understanding not only of libraries but also of modular software, the linker, and library design. We have included a substantial amount of advice distilled from experience (ours and our students') and from online discussion communities. We found that this helped our students to cope with most of the problems they encountered in courses based on early versions of this book.

We used evolving versions of this book in Suffolk University's OOP/C++ course each semester during the academic years 2003–2004 through 2010–2011, with increasingly promising results and with much valuable feedback from our students. In the earlier version of this course (prior to 2003), students typically would write thousands of lines of code for their programming projects. By contrast, with the emphasis now on code reuse and the exploitation of robust tool libraries, student programming projects have fewer lines of student code but are much more interesting and, we feel, provide a much more valuable learning experiences.

There are many C++ books in print that either teach C++ or teach Qt, but we found that the C++ books use a variety of different programming styles, and they emphasize some topics that we do not often use with Qt. The Qt books we have seen all assume prior C++ knowledge. This book, by contrast, assumes no C or C++ programming experience, and it covers the language features of C++ that you need to know to use Qt classes as early as possible in the examples and assignments. It can be used as a textbook for teaching C++ and design patterns, with an emphasis on code design and reuse.

As far as we know, there are no other university-level C++ textbooks that contain Qt examples and also provide review questions, exercises, solutions, and lecture slides for instructors.