Computer Programming Textbooks Suck: At Least Many of Them Do

I have been teaching computer programming to college students for over twenty years. The one thing I have found consistent over these years is that most computer programming textbooks suck. They don’t help students learn, and in my opinion, are mostly harmful to their readers.

Why Programming Textbooks Suck

The programming languages that suck suck in many of the same ways.

Textbook as Swiss Army Knife

The sucky programming textbook crams as many features into a concept or technique as possible. For example, a very popular textbook on C++ programming has a table that displays all eight possible integer data types, from short int to unsigned long long int. The working programmer surely needs to know and understand all these integer data types but the student programmer just needs to know one – int.

Textbook chapters combine too many features.

When learning how to program, especially when it is the person’s first language, the author should not combine several different concepts into one chapter. For example, one textbook introduces data types, variables, statements, arithmetic operators, comments, and scope in a single chapter. That is far too much material to be taken as one unit and should be broken up into at least two or three more chapters.

Textbook authors don’t use modern learning techniques.

Learning science and computer science education researchers have introduced many new techniques for students to learn computer programming. These techniques include interleaving, developing concept maps, working Parsons Problems, teaching how to read code before writing code, and many, many more techniques I’ll be talking about in this blog. Programming textbook authors are still teaching programming the old, let’s write “Hello, world!” way.

Textbook authors, who are mostly college instructors, don’t spend a lot of time writing programs in the textbook’s programming language.

I can say this with authority because I am a college instructor and I know how hard it is to find time to really write meaningful code. We spend most of our time now teaching, grading, advising, and serving on committees, not writing programs and working to advance our craft.

Textbook authors are often late to pick up changes in how professionals are using the language.

Since most textbook authors are college instructors, and they are busy with their teaching jobs, they don’t have the time to stay current in how professionals are writing code. I have seen this happening in C++ textbooks over the years. Professional C++ programmers have been choosing vectors over arrays for many applications for quite a while now because working with vectors is less error-prone than working with arrays, but until recently most C++ textbooks have covered arrays first and only mentioned vectors in a later chapter on data structures.

Another example of this is the use of blocks for all if statements, not just blocks that include multiple statements. I remember that when Douglas Crockford first published his book on the good parts of JavaScript, he advocated using blocks for all if statements. That was in 2008. Since then, many other programming professionals have adopted this use; Google has it in their style guide. And yet, most current programming textbooks aren’t advocating it. To me, this borders on professional malpractice.

Some textbook authors use questionable programming practices.

A very popular C++ programming textbook demonstrates how to write for loops by declaring the loop control variable outside the for block in many examples before finally, at the end of the section, demonstrating how to initialize the variable inside the block. This is deceiving to the student because most for loop variables should be local to the loop block and not be available outside the loop.

Another example exists in the JavaScript textbook world. Authors are still using var to declare variables in most situations when, since ES6 came out a couple years ago, it is now more advisable to use let to indicate local scope. There are lots of examples of this in textbooks on many different programming languages. In most cases, this happens because the author is not working that much at programming but very hard at textbook writing.

How Programming Teachers Support Sucky Textbooks

Those of us in the programming instruction business are largely at fault for the state of programming textbooks. Here are some reasons why.

Programming instructors are too busy to develop materials themselves.

Programming instructors are very busy people. If they work at a four-year college or university, they are probably either graduate students who are also working on their graduate degrees, or they are junior instructors working hard to get tenure through research and publishing, along with their other college commitments. They don’t have time to develop their own materials and instead rely on programming textbooks that supply all the material for them.

Programming instructors are too reliant on the exercise sets in textbooks.

Teaching people how to program involves having students work lots of exercises and problems. It takes time to develop these exercises and to also develop their solutions. For the busy college instructor, it’s a lot easier to rely on the exercises and problem sets found in textbooks, along with the solutions that many textbook authors and publishers provide.  

Not All Programming Textbooks Suck

There are some good textbooks for learning computer programming. I am primarily thinking of the “How to Think Like a Computer Scientist” series by Allen Downey. This series includes books for Python, Java, C++, and other languages. These books present material at the right pace and Downey recognizes that busy students, whether in school or learning on their own, are not going to read a 1000 page book or be able to effectively learn fifteen new programming language features every week. You can read more about Downey’s textbook philosophy at https://greenteapress.com/wp/textbook-manifesto/ and you can find his books at https://greenteapress.com/wp/.

What’s the Solution?

The best solution I’ve been able to come up with is for instructors to use trade publications as textbooks and either provide their own problems and solutions or find a resource that can provide problem sets and solutions that independent from any textbook. Having students read trade publications gives them exposure to the current practice in that programming language, written by programmers who are writing code daily. There are many examples in a variety of programming languages: C++ Primer, by Lippman, Lajoie, and Moo; Head First Java by Sierra and Bates, or Thinking in Java by Bruce Eckel; Python Crash Course by Eric Matthes or Head First Python by Paul Barry; A Smarter Way to Learn JavaScript by Mark Myers or Eloquent JavaScript by Marjin Haverbeke.

All these books take a non-textbook approach to teaching their respective programming language. Some provide exercises in the book and at least one, A Smarter Way to Learn JavaScript, provides exercise sets at the author’s web site. Several of these books also provide more information about the language at their web site.

It’s easy to say that because there are so many good online resources for learning programming now, from online tutorials to online video channels, programming language students don’t need books for learning how to program. I believe, though, that learning through reading is going to be an important element of every programmer’s career so they need to develop the ability to learn through books early on. Learning well, though, requires the right resource and steering you towards those resources is my goal in writing this article.