Issue #24: Java,  Library

How To Choose A Programming Language For Your Book

If you wanted to write a book about any subject related to computers, but not specifically about a particular programming language, which language would you choose? For example: if you wanted to teach programming concepts (algorithms, patterns) to an absolute beginner, which language would convey your thoughts better? Say, if you had to explain algorithms that could be implemented in any Turing-complete language, which one would you pick, and why?

This problem is not new. As this edition of the Library section coincides with the 25th anniversary of Java, I decided to look back in time to see which languages were chosen in famous (and not so famous) computer books. Of course, we are leaving aside all books called “The X Programming Language,” since the answer for the question is, invariable, the X programming language, whatever X might be.

Early Examples

Let us begin with “The Art of Computer Programming” (1968), a book about which Graham wrote an article in a previous edition. To illustrate the various themes of the book, Donald Knuth invented his own programming language. Actually not one but two; MIX, used in the first editions, and a RISC version called MMIX for the latest ones. Designing a programming language for your own book is akin to J. R. R. Tolkien creating his own languages to tell a story; it is certainly fair to say that Knuth’s work can be easily compared to Tolkien’s, if not in popularity, definitely in magnitude and reputation.

Somewhat similar, Niklaus Wirth used his own Pascal language to illustrate the classic “Algorithms + Data Structures = Programs” (1976); the book describes a Tiny Pascal compiler, which is said to have inspired Anders Hejlsberg to create Turbo Pascal. We can add Brad Cox to the same club, whose “Object Oriented Programming: An Evolutionary Approach” (1986) title, also the subject of a popular article by Graham, uses Objective-C as a tool to explain OO concepts which were quite novel at the time.

Later authors have understandably preferred to use existing languages; for example “The Elements of Programming Style” (1974) by Brian W. Kernighan and P. J. Plauger. In this case the authors chose Fortran and PL/I:

…since these languages are widely used and are sufficiently similar that a reading knowledge of one means that the other can also be read well enough.

The Reign of C/C++

The rise of Object Oriented Programming (OOP) had it hallmark moment in the 1980s and 1990s. And at the beginning of this craze, the most widely used language to explain it was C++.

I will start with the book that taught me OOP: my beloved copy of “Object-Oriented Analysis and Design with Applications (2nd edition)” (1994) by Grady Booch, which represented also my first exposure to C++ code examples. Grady Booch is one of the “three amigos” who came up with UML and in 2002 IBM bought their company. Interestingly, the 3rd edition of this opus (2007) has examples in C# and Java.

OOP begat the design patterns movement, incarnated by two major books: “Design Patterns for Object-Oriented Software Development” (1994) by Wolfgang Pree, a title that got sadly, unjustly, and immediately shadowed by the success of the eponymous “Design Patterns: Elements of Reusable Object-Oriented Software” (1994) by the “Gang of Four”: Erich Gamma, Richard Helm, Ralph Johnson and John Vlissides. Both books, released one year before the smashing release of Java, show examples in C++.

C++, largely thanks to the legendary speed attributed to its name, found a niche in numerical and financial processing back in the 1990s, starting a slow industrial demise of Fortran. In this sense it is worthwhile to mention “Numerical Recipes: The Art of Scientific Computing (3rd edition)” (2007) whose first edition (published in 1992) featured two distinct versions: one in C and another in Fortran. As for financial modeling, we can mention “Modeling Derivatives in C++” (2004) by Justin London, and the excellent “Financial Instrument Pricing Using C++” (2004) by Daniel J. Duffy, recently updated to C++11 in a second edition (2018).

Regardless of when they are published, some low-level topics are better explained using C. Examples are the both extraordinary and fundamental “Linux Programming Interface” (2011) by Michael Kerrisk, and “Beej’s Guide to Network Programming: Using Internet Sockets” (2019) by Brian “Beej Jorgensen” Hall.

Java Takes Over

But in 1995, just as the World Wide Web was making headlines, Sun released Java and became, in just a few years, one of the most popular programming languages ever created. Book authors took notice, and promptly started using it in their work. Since Java was being actively marketed as a “better” or “simplified” C++, it was quickly considered that it would make programming books immediately more approachable. The rest is history.

Martin Fowler’s “Refactoring: Improving the Design of Existing Code” (2000) and “Program Development in Java: Abstraction, Specification, and Object-Oriented Design” (2000) by John Guttag and Barbara Liskov (Graham wrote about her and this book in this magazine) are two major examples of early books centered around Java.

Kathy Sierra’s Head First series in O’Reilly (read the article dedicated to her in this magazine) relied heavily in Java for two major titles: “Head First Design Patterns” (2004) and “Head First Object-Oriented Analysis and Design” (2006).

In the area of university textbooks, “Computer Networking: A Top-Down Approach Featuring the Internet” (2004) by James F. Kurose and Keith W. Ross features a “top down approach” starting at the OSI Application layer, with many code examples in Java. Similarly, “Schaum’s Outline of Principles of Computer Science” (2008) by Paul Tymann and Carl Reynolds followed the trend, firmly set in the early 2000s, of university Computer Science programs based in Java.

Grady Booch was not the only one of the “three amigos” to use Java in their books: “The Unified Modeling Language User Guide (2nd Edition)” (2005) by Grady Booch, James Rumbaugh and Ivar Jacobson features examples in JavaBeans (and COM), while “Aspect Oriented Software Development with Use Cases” (2004) by Ivar Jacobson and Pan-Wei Ng uses AspectJ (an extension to the Java language.)

Beyond Java

By 2005 everybody was raving about Agile and Open Source and Web 2.0. In the middle of that frenzy, a young man called David Heinemeier Hansson presented a new web framework called Ruby on Rails. The recording of a demo explaining how to create a blog engine in 15 minutes, was then uploaded to a new platform called YouTube you might have heard about since. Besides proving that Mac OS X was a suitable programming platform, or that TextMate was a very nice editor, this video galvanized a whole generation to the notion that there were simpler languages than Java. Those thoughts were condensed in Bruce Tate’s “Beyond Java” book. These were the times where “think different” meant something.

The reaction was immediate, and programming books started exploring other languages. The essential “Python Programming: An Introduction to Computer Science” (2004) by John M. Zelle (recently updated to its third edition) uses Python. “Programming Collective Intelligence” (2007) by Toby Segaran used Python as well. “RESTful Web Services” (2007) by by Leonard Richardson and Sam Ruby uses… Ruby, as the authors say:

We chose Ruby because it’s concise and easy to read, even for programmers who don’t know the language. (And because it’s nice and confusing in conjunction with Sam’s last name.)

This trend continues to today. Two interesting examples are “The Imposter’s Handbook” (2016) by Rob Conery, which uses JavaScript, while “Domain Modeling Made Functional” (2018) by Scott Wlaschin is based in F#.

Outsiders

Of course not everybody falls in the buckets defined above. Some absolute classics have taken orthogonal routes, in some cases with great success.

We must mention them: “Structure and Interpretation of Computer Programs” (1984), also called the “Wizard Book”, by Hal Abelson, Jerry Sussman and Julie Sussman, which uses Lisp. “Specifying Systems” (2003) by Leslie Lamport uses the TLA+ formal specification language. “Object-Oriented Software Construction” (1988) by Bertrand Meyer (which we have covered previously in this section) uses Eiffel. “Introduction to Functional Programming” (1988) by Richard Bird & Philip Wadler uses Miranda. And more recently, “AP® Computer Science Principles with Swift” (2019) by Apple Education showcases its newest programming language, Swift.

MIT’s “Introduction to Algorithms, Third Edition” (2009) by Thomas H. Cormen, Charles E. Leiserson, Ronald L. Rivest and Clifford Stein uses a special pseudocode that, for the third edition, took a shape closer to Java, C, C++ and Python.

Finally, in a category of its own, “An Introduction to Functional Programming Through Lambda Calculus” (2011) by Greg Michaelson deserves a special mention; the book illustrates all concepts through lambda calculus. But we know since Alonzo Church that lambda calculus is akin to a model of computation and can simulate a Turing machine… well, it is probably a programming language in its own right.

Criteria

So, how does an author choose a programming language? There are a few factors that come into play. First, there is definitely hype and vendor lobbying; or, as others would call it, “market demand” which would explain choices such as Java, Swift, and various .NET languages to appear in teaching curricula.

Let us consider the target audience; are we talking to math majors, computer science PhDs, or practical programmers? Not to mention the themes of interest of such audiences; which explains why most Artificial Intelligence Machine Learning titles overwhelmingly feature examples in Python. Similarly, mathematically-oriented books will lately prefer Python today to Fortran; in both cases, the rise in popularity of NumPy was enough to drive the choice of the programming language.

Teachers prefer some programming paradigms to others. For books explaining concepts around Object Oriented Programming, C++ and Java are overwhelminly used. For functional programming, though, the choice is a bit larger.

What about cross-platform issues? Should all students use the same operating system, or could they learn on whichever one they prefer? In a related fashion, is open source a criteria to consider for the choice of a learning language?

Finally, there is the approachability of the language; how easy is it to read or write it? Is there a Read-eval-print loop (REPL) available for the language? Experience shows that being able to write lines of Ruby, JavaScript, or Python code in a REPL accelerates the adoption of a language, instead of having to setup a complex toolchain to be able to compile and test a simple program.

The Polyglot Approach

In the humble opinion of the author of these words, there is no better choice of programming language than many of them at the same time. Quite a few hallmark books have adopted this strategy, which yields rich, diverse books, using the full strength of each chosen language and, at the same time, automatically expanding the horizons of readers.

As Steve Yegge once said,

But you should take anything a “Java programmer” tells you with a hefty grain of salt, because an “X programmer”, for any value of X, is a weak player. You have to cross-train to be a decent athlete these days. Programmers need to be fluent in multiple languages with fundamentally different “character” before they can make truly informed design decisions.

From the 1980s, come to mind “The Peter Norton Programmer’s Guide to the IBM PC” (1985), whose last chapter explains Assembler, Basic, Pascal and C. Also from that era, “Compilers: Principles, Techniques, and Tools” (1986) also known as the “Dragon Book,” by Alfred V. Aho, Monica S. Lam, Ravi Sethi, and Jeffrey D. Ullman, whose chapters show a mix of FORTRAN, C, EQN, Modula-2, and shows a compiler for a subset of Pascal as a project at the end of the book.

More recently, “Writing Secure Code, Second Edition” (2002) by Michael Howard and David LeBlanc, illustrates common security vulnerabilities in code with examples written in C, C++, Perl, VBScript, JScript, SQL, Visual Basic.NET, and C#. The “Dinosaur Book” “Operating System Concepts, Seventh Edition” (2005) by Abraham Silberschatz, Peter B. Galvin and Greg Gagne, uses C code snippets illustrating the Win32 API, as well as Java for some higher-level concepts such as threads, file locking, and others. The widely celebrated “Working Effectively with Legacy Code” (2004) by Michael Feathers uses Java, C++ and C – the latter two, as expected, to show “legacy” code. Finally, Deitel & Deitel’s series “How to Program” feature books in C++, Java, C#, Visual Basic, and other languages.

I would like to highlight as well, although it is not a book per se, the excellent Stanford Course CS107 “Programming Paradigms” (2008) where professor Jerry Cain explains various subjects using C, Assembly, C++, Scheme and Python.

I will finish with a quote I could not agree more with, borrowed from “Code Complete (2nd edition)” (2004) by Steve McConnell, and which summarizes my thoughts in this matter:

The examples are in multiple languages because mastering more than one language is often a watershed in the career of a profesional programmer.

Cover photo by Iñaki del Olmo on Unsplash.

Donate using Liberapay

Adrian Kosmaczewski is a published writer, a trainer, and a conference speaker, with more than 25 years of experience in the software industry. He holds a Master's degree in Information Technology from the University of Liverpool.