Designing a Programming Textbook

This is a repost from my blog at Artima.com. In this forum, I am sure that I would have an interesting and differing point of view from those posted at Artima.
I've started work on a rather ambitious book called Fundamentals of Programming which will be intended as a programming book for people starting at the very beginning. I thought I would invite some feedback about my proposed structure.

I plan on breaking the book up into the following sections, with the primary example language for that section.

  1. Programming Basics - Cat
  2. Pointers and Memory Addressing - C++
  3. Object Oriented Programming - Java
  4. Functional Programming - Scheme
  5. Mixed Paradigm Programming - Scala
  6. Software Design - Cross Language
The language I associated with each section would be by no means exclusive. I would introduce that particular language, familiarize the user with it, and use it for the bulk of the examples.

One reason for using multiple languages is that I want beginners to be exposed to a wide breadth of languages, and ways of thinking. I want people to feel they are getting their money's worth by becoming familiar with several different major languages.

The usage of the Cat language is risky, since no one has heard of it. However, I really like the idea of starting a lesson on programming using the example of postfix calculators. This leads naturally to an interpreted stack based language.

The choice of Scala, is potentially contentious because Scala isn't as mature as Haskell or OCaml. However Scala is chock full of support for advanced programming techniques, it is type safe, and it has a sane syntax.

The final section would introduce the concept of using the appropriate language(s) for the job. As such I would be sure to mention languages like: Perl, PHP, Python, Assembly, TCL, and others.

The order of these sections are not intended as hard and fast rules. I am hoping to design the book such that entire sections can be skipped or moved. For example, Pointers and Memory Addressing can be placed at the end, or left out entirely. Another possibility is that Functional Programming can be placed before Object Oriented Programming.

What languages would you use, and how would you structure your ideal programming text? Do you already have a favourite introductory text that can't be improved on?

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

Well this idea obviously has

Do you already have a favourite introductory text that can't be improved on?

Well this idea obviously has parallels with CTM, which uses Oz throughout (alongside brief sections on other languages) because it has language support for all these forms of programming.

For a multi-language approach, my preferences:

Programming Basics - Scheme
Functional Programming - ML then Haskell, with a focus on types as well.
Pointers And Memory - C
OOP - Smalltalk, alongside implementations of object systems in Scheme probably, comparison of classes and prototypes, comparison with Erlang style message passing programming.
Mixed Paradigm Programming - Scheme again? I'd probably try to go a CTM-like route and promote mixed paradigm programming throughout as you introduce new concepts.

i'd say

If it really is for people starting at the beginning (say adults or college/high school students starting to program), then I would use a programming language and development environment designed with some significant consideration for beginners. For example, VB.NET.

Quick and Dirty Outline

If I was to write a book, I would skip out on so-called "multi-paradigm programming" in favor of just teaching that as I go and including a section dedicated to metaprogramming.

1. Programming basics: Very basic Ruby, then a good bit of Scheme. Ruby's just too simple not to show a beginner. My girlfriend who had never programmed before in her life taught herself a lot of useful Ruby in an hour or so without my guidance (without even telling me!). I would show the basics using Ruby, then move to Scheme for a more in depth study of how programming can work.
2. Functional programming: ML followed by Haskell. This will be quite a jump from Ruby and Scheme, but should reinforce the idea of putting strict constraints on programming with positive consequences, which is, IMHO, the essense of the functional programming style.
3. Pointers and memory: Basic assembly followed by C. Nothing makes the quirks of C more understandable than knowing how registers, stack, heap, jumps, branches, etc. work.
4. OO programming: A bit more Ruby, then a tiny bit of Java. Object orientation is a very difficult thing to truly teach to somebody, so a language like Ruby that stays out of the way of instruction would be best. Up to this point, it probably would end up appearing that a dynamic language is necessary to program in an OO style. The bit of Java is basically to demonstrate that, with enough boilerplate, that is not so. [Edit: Maybe Eiffel would be a better choice over Java? Going over a few design patterns would be a good idea too, though I would avoid doing it formally.]
5. Metaprogramming: In depth study of Scheme, followed by an in depth study of Io. I consider those two languages to be ideal for extreme metaprogramming, but with completely different approaches. Io is very new, so this is a bit of a risk, but I believe it to be a risk worth taking.
[Edit: 6. Development process: A study of several different ways to design and implement larger projects. This would include the traditionally taught methods of bottom-up, top-down, etc. but also would touch on test/behavior-driven development, agile development, etc. Basically, it's everything that doesn't necessarily depend on the language or programming style being used.]

Maybe everybody shall just

Maybe everybody shall just write a book about all the languages he likes. Than we have far more authors and less readers. But who cares?

Ew. The only thing you can

Ew. The only thing you can possibly get from a book full of languages that the author only put in because he likes them is a lot of stuff that you will probably disagree with. :)

OO: Java?!

Java is a very bad beginners language, and it's even worse to show the beautiful idea behind object-oriented programming. Use Smalltalk! It was even designed with programming for beginners in mind!

Ruby as an entry might be a good idea, but I'm not quite sure how much the language might change in the next couple of years. OTOH, if you stick with the core features this might not be an issue. Still, Ruby and Smalltalk are quite similar.

Also, which C++ features are essential for explaining pointers, but are not available in C? I also agree with the Assembly-then-C idea.

Completely agreed. I'm of

Completely agreed. I'm of the opinion that OOP in languages like C++ and Java is an entirely different subject than OOP in Smalltalk and Ruby.

You're not alone in that opinion

It seems that you're not alone in that opinion. Here's a quote from Alan Kay's keynote speech at OOPSLA 1997 (available via Google Video here - the comment in question appears roughly 10 min 30 sec into the speech):

...I made up the term object-oriented — and I can tell you I did not have C++ in mind...

Perhaps it was commercialization

Lest we take that quote to imply satisfaction with Smalltalk, Alan Kay has also said:

"Perhaps it was commercialization in the 1980s that killed off the next expected new thing. Our plan and our hope was that the next generation of kids would come along and do something better than Smalltalk around 1984 or so. We all thought that the next level of programming language would be much more strategic and even policy-oriented and would have much more knowledge about what it was trying to do. But a variety of different things conspired together, and that next generation actually didn’t show up."

Programming basics

I think that Forth should be used instead of Cat.
Forth is better known than Cat, it doesn't mixes things (Cat=Joy=Forth+functional stuff), and introduces to the basic concepts (in the "low-level" or "how a computer really works") such as memory adressing in a clean and simple way. In particular, because it is an interactive and interpreted language, it is a much better environment where to experiment than a compiled language like C. Don't forget the fun factor.

To be fair ...

Cat has a type system, which sets it apart significantly from Forth and Joy.

Why multiple languages?

If you're targetting your textbook at the complete beginners, I think throwing a new language (and a completely new way of thinking about programming) at them in every chapter is only going to cause confusion and frustration. Even in a two-term course, i.e., 26 weeks of instruction, this would translate into a new language every four weeks or so. Courses comparing multiple languages and programming paradigms are typically introduced in the second, or even third, year, once the students get at least a feel for the basics. As for the basics, I think a language like Python or Ruby would be ideal. You want a language that allows people to start producing their first programs very quickly and experiment easily, and where they can focus on the important concepts you're trying (be they loops, objects, iterators, or coroutines) to cover without other language features (e.g., unfriendly syntax) getting in the way.

Perhaps.

I must admit that I have no knowledge of research on the subject (I'm sure it's been done - I just don't know anything about it), but in my experience there seems to be at least two general schools of thought on the process of learning/teaching: 1) slow and steady, 2) sink or swim. The idea of putting a lot of languages in the same book and throwing stuff at the student left and right is approach #2. Most books use approach #1. I think it's just different is all - unless there's solid research proving it's a bad idea (links welcome!), I say more power to him! :-)

A lot of research besides

A lot of research besides the fact that it's harder learning multiple things at once?

Hard to argue that.

:-) Since I have no research knowledge to point to or even really guess about, I'll just wrap up my opinion of this matter thusly: What does it hurt for him to try it his way? In my own experience I've had times when I wanted to strip away complexity and try to learn from base principals and other times when it seemed better to just jump in and try to understand not only the problem area itself, but the context surrounding it.

My only experiences with programming text books have been the slow, methodical approaches of one overall language, one language feature per chapter, etc. After plowing through all the way to the end you may have a great new set of words and terms in your head but no immediate sense of how it all fits together and why. Perhaps by teaching programming through multiple languages a student could begin to form a larger picture in their head that transcends just learning the steps into an understanding of why the steps exist in the first place.

Even if I set all of my baseless emotional opinion aside, there's still the reasonably undeniable fact that in this age of Web 2.0 (ack), building even a simple web application can involve a host of different languages from SQL, to PHP, to Javascript, HTML , and CSS. People don't seem to have just too much trouble learning what they need to know when they are driven to accomplish a goal. If the goal is to learn why programming works, what it is, and how to best apply it - perhaps a multi-language text book is a legitimate answer and could help avoid religious devotion to any single language simply because so much time was spent learning it instead of learning general principals.

Don't confuse teaching concepts and language syntax

My only experiences with programming text books have been the slow, methodical approaches of one overall language, one language feature per chapter, etc.

That's not what I said. My point was to pick one language that will stay out of the way and will let you focus on whatever concept (*not* a syntactical language feature) that you want to cover in the given chapter. So with Python, for example, you can go from procedural to OO (incl. multiple inheritance and mixins), with a sprinkling of functional (list comprehensions, map, filter, etc.) in between. Use Stackless Python and you can cover coroutines and concurrent programming, too.

CTM has a similar approach but uses Oz as the language. I think using Python or something similar would give a very different feel to the course, a bit more "relaxed" and forgiving I think. (Call it the European vs. North American approach. :-)

Know thine audience

Before writing any textbook, one has to address the target audience. Are these freshmen in high school, freshmen in college, post-graduate students, or somewhere inside or outside of that spectrum. Next question is what level of knowledge one assumes about programming - are these people that have never touched a computer? Have they ever written a program? Are they proficient in one or more languages?

And then there's the motivation for what the text wishes to accomplish. Does the text want to have an impact on people who are only mildly interested in programming. Are you aiming at the self-motivated kids that have hacked on computers since they were in diapers. Are you aiming at the professional programmer? Are you aiming at the theoreticians?

Or to summarize, a textbook writer has to make assumptions about the students. What assumptions one makes about the students will determine the tone and depth of the text. A good study of one set of choices aimed at a specific audience of college freshmen is the material surrounding the text "How to Design Programs" (HTDP). Here the authors elected to use a minimalistic language (a restricted subset of Scheme) because the course is not about programing languages - but rather programming. On the other hand, CTM is very much about advanced concepts in programming and the PLs that are used. Those authors chose a subset of Oz and limited forays into other languages.

If I were to go back in time and become a college freshman, I'd probably prefer to use Scheme as the language for my textbook. But then, when I was actually a freshman, I thought I knew everything there was to know about almost any subject - so I probably would have preferred C at that stage in my life (I was so much older then, I'm younger than that now).

Anyhow, if I was to offer advice on the subject to cdiggins, I'd probably say do as much with Cat as possible. First, the subject would be an interesting study in PL design. And second, the author has much more at stake with that particular language - so the care and craft would be much more a labor of love.

Great Points

I think you make some excellent points Chris, thank you. In fact thank you to everyone who has provided me with useful feedback.

I have come to a clearer understanding of what it is I intend to do, and how to achieve it. What I was describing originally would have been appropriate for several books of material aimed at different levels.

I think that I shall start with a textbook aimed at College Freshaman who haven't neccessarily ever programmed the computer.

I plan on pursuing this in Cat, which may either marginalize the book, or bring Cat into the mainstream. However, as Chris pointed out, it might as well be a labour of love so that I will do my best possible job at it.

Maybe I will attempt a survey of languages and techniques afterwards.

Thanks again everyone!

I'd suggest C, not C++

for the section on pointers. Or at least, use code which is valid C and C++.

Or Forth!

If you're going to use Cat, then Forth is fantastic for experimenting with how memory works.