The Science of Programming/Introduction

A student of mine once remarked, after taking a programming languages class from me, that she had grown from a "syntax coder" to a Computer Scientist. She once knew only enough syntax to get a program to compile and to run, after a fashion, but now she can identify a computable problem, sort through a set of strategies for solving the problem, weigh their advantages and disadvantages, and implement the chosen strategy in a robust program.

I can take a little credit for this transformation, but I believe the honor should fall to the textbook I chose, SICP: "The Structure and Interpretation of Computer Programs" by Harold Abelson, Gerald Jay Sussman, and Julie Sussman. The Wizard Book, as it is affectionately known, is a wonderful text that challenges students to learn the nature of computation and data. An earlier edition of that very book lead me on that same journey from syntax coder to Computer Scientist. The book is so versatile it has been used as an introductory computer science text at some universities and as a programming languages text at others. In fact, I tell my students that if they were to be marooned on a desert island and they could take one computer science text[1], SICP should be their hands-down choice.

The existence of such a text as SICP is quite a deterrent to creating this textbook, but we have embarked upon such a task. If there are any drawbacks to SICP, they would be in the choice of Scheme as programming language to illustrates the concepts therein. While the authors justify their choice well, the use of Scheme has probably prevented a wider adoption of SICP as an text for introductory computer science courses.

This is not a fault of Scheme, which is an elegant, fun, and easy to learn language, but rather in the parochial view that students need to learn "practical" languages. These days, practical means the programming language C and the languages derived therefrom, C++ and Java, both of which add object-orientation while maintaining a C-like syntax. This trend towards object-orientation is the second, and perhaps more valid, criticism of Scheme and thereby the choice of SICP as an introductory text; Scheme lacks formal object-orientation.[2] While there have been many attempts to add object-orientation to Scheme and LISP-like languages, the results have looked much like a Victorian home with a ranch-style addition - serviceable, but with jarring aesthetics.

The Sway Programming Language edit

The idea of the Sway programming language arose in this environment. I had been using a simplified C-like pseudocode in teaching an Algorithms class[3] and my experiences teaching programming languages led me to believe I could implement a good portion of the pseudocode language. I chose the name Sway as I would often misspell pseudocode as psuedocode, which I reckon should be pronounced Sway-dough-code.

I designed Sway to have nearly the elegance of Scheme and all the fun, but with a C-like syntax to ease the transition of students from Sway to an industrial-strength language like C, C++, or Java. Moreover, Sway incorporates a fiendishly simple object and inheritance system based on a combination of previously published research in object orientation by others and my own research in this area. The idea that Sway should be fun makes the language a little more dangerous for novices. The point is: I wish to teach about computation and computational strategies rather than how to write a for loop in some toy language. To do so, the language of instruction needs to be expressive, the more expressive, the better. Also, I hope to avoid the pitfall of the Niklaus Wirth's Pascal programming language, a language, like Sway, designed for teaching. Wirth chose a rather rigid language model so that the language would be easier to learn. Under such a model, error messages generated by the language processor usually point out the error that led to the problem quite directly.[4] Unfortunately, the language was inflexible and could not grow. This rigidness was responsible for Pascal falling, for the most part, by the wayside.

Sway is designed to grow in ways unanticipated by me and I have given Sway some properties that I believe give the language a solid base from which to grow. On the downside, this built-in flexibility can, at times, cause some rather obscure error messages. For example, a missing semicolon might generate a "missing expression" error message rather than the hoped for "missing semicolon" message. To make up for this trade-off, special care has been taken to make Sway monolingual.[5] That is, the very same constructs for writing a program can be used to debug (fix errors). In fact, unlike most textbooks, this one provides a link to an entire chapter on the debugging of Sway programs, from the mundane (print expressions) to the sublime (running an interactive interpreter within a program).

Organization of the Book edit

This textbook is designed for students who would like a little practice in programming before moving on to a traditional CS1 class. The Science of Programming takes a non-traditional transit through the material, however. Rather than focusing on language features, the emphasis is on using a programming language to help the student understand material in an entirely different domain. In this case, the domain is Introductory Calculus. The student learns to program by writing short algorithms for solving Calculus problems. At the same time, students learn about Calculus and thus get a little practice in this subject before moving on to their first Calculus course.

In my mind, current CS1 textbooks suffer from a number of flaws. The first is that they tend to be encyclopedic. Thus many of the great concepts of computer science are obscured by a deluge of details. I don't, and I suspect many students do not, want to wade through an 800 page (or worse) textbook. Another flaw is that when examples are used to motivate language features, a detour is taken away from the example to introduce some new language construct, breaking up the narrative. Yet another flaw is that examples are usually contrived and not very convincing motivators for learning CS.

TSOP attempts to solve the first two flaws by taking advantage of the benefits offered by hosting the textbook online. When a particular language construct is needed to accomplish some task in TSOP, the reader is instructed to follow a link to learn about the construct, if desired. These links lead to sections in the Sway Reference Manual, a companion text to TSOP. These little pointers do not disturb the flow of the overall narrative. The final flaw is ameliorated by the use of examples (calculus) that are most certainly of benefit to a Computer Science major.

The chapters of TSOP follow exactly the text of Calculus Made Easy, by Sylvanus P. Thompson and updated by Martin Gardner. For a student who already knows Calculus, TSOP (with the Sway Reference Manual) stands by itself. For a student who wishes to learn calculus as well as programming, Calculus Made Easy is a necessary, and comforting, companion.

Notes edit

  1. No student has ever inquired as to how such a situation might arise.
  2. The effect of encapsulation can be achieved through the use of function closures, but Scheme lacks a method allowing these object-like closures to inherit functionality from other closures.
  3. I taught this class using the text "Introduction to Algorithms" by Cormen, Lieserson, and Rivest. This another of the great Computer Science textbooks and is affectionately known as CLR or the White Book, although subsequent additions were no longer white. Unfortunately, students felt the pseudocode used in the book was more confusing than not.
  4. A common complaint from novice students is that "this error message makes no sense". Most practical languages suffer from error messages that do not seem to correspond with the actual error. In a testament to Pascal's error system, I remember as a student having the Pascal compiler tell me that I forgot a semicolon in such and such a place and would I like for it to insert the semicolon for me!
  5. As an example of a non-monolingual language, it is said that one needs to learn three languages to become proficient at C programming: C, language itself, cpp, the C preprocessor, and gdb, a debugger for C.


Terrifying Concepts