Extreme Forth

Dr. Dobb's Journal August 2003

By Tim Kientzle

Tim is a DDJ contributing editor and can be reached at kientzle@acm.org.


Thinking Forth: A Language and Philosophy for Solving Problems, Second Edition
Leo Brodie
Fig Leaf Press, 1998
272 pp., $37.50
ISBN 0-13-917576-8

I've had a number of conversations recently about Extreme Programming (XP). Although many people seem to share my distaste for the name, I've encountered remarkably little controversy about the ideas themselves.

Ultimately, XP is just a collection of best practices, many of which have been around for decades. I recently reread Leo Brodie's 1984 Thinking Forth: A Language and Philosophy for Solving Problems, which covers many of the same ideas, but in a different fashion. Still, Thinking Forth (now out of print, but available from Taygeta Scientific, http:// www.taygeta.com/thinking_forth.html, and from bookstores such as Amazon.com and Powells.com) provides a thought-provoking counterpoint to newer writings.

First, Make It Work

Thinking Forth is very much a book of best practices. Brodie started by interviewing the best software developers he could find. He then mixed extracts from these interviews with his own commentary and short, to-the-point tips, such as this gem:

Tip: Today, make it work. Tomorrow, optimize it.

This statement has been my software-development mantra for nearly two decades now, and it echoes clearly through much of the XP literature. Software development is, after all, about solving problems. Working code must always be the first priority.

A more subtle issue is also involved here. Working code provides you with positive feedback and encouragement, which makes it less intimidating to take the next step and thus leads to improved productivity. This is a key idea both in XP and in Brodie. One of Brodie's interviews even refers to the "fun-down approach" of software development—start where you will get the most immediate gratification.

Second, Make It Work Well

But working code is merely the first step. XP's "refactoring" is more than simply a cookbook list of code transformations. It is a fundamental dictum that improving code is not just a matter of adding features.

Brodie explores this idea in detail: An entire chapter is devoted to "Factoring," and another discusses the merits of prototyping and iterative design. Few XP treatises could hope to do better:

Tip: Look for repetition of patterns.

Tip: Don't change too much at once.

Tip: Be sure you can name what you factor.

The interviews are especially helpful here. Chuck Moore, for example, urges you to challenge your solutions: "You need a feeling for the size of the problem...When you're done, look back and say 'Did I come up with a solution that is reasonable?'" If your result seems out of touch with your intuition, maybe you haven't yet found a good solution:

Tip: You don't understand a problem until you can simplify it.

Brodie uses a variety of somewhat contrived textbook examples to illustrate his ideas, but these are the book's weak point. They also require you know Forth.

Forth Matters?

Knowing Forth is not a remarkably marketable skill these days. Forth's compact size and portability are less important now than they once were. Forth's very weak type- and syntax-checking are also drawbacks, as are its somewhat unusual syntax. Forth is still in use, but it is becoming much more of a niche language.

Even if you never use Forth, however, you might benefit from studying some of its features. For example, all of the internal code used by the Forth interpreter and compiler is available to application developers. This simple idea has many benefits—it exposes a complete standard set of tools, it lets you extend the environment and language in deep ways, and it enables some very advanced development paradigms.

Forth's interactive development model is also very appealing: A Forth system encourages you to type in and test a line of code, then add it to the application once you are certain it is right. This kind of short-cycle development, strongly advocated by XP, may be better supported in Forth than in any other language environment.

Thinking Matters

Of course, any programming language is just a tool, and no tool or methodology will make up for carelessness. Brodie's insights, like those of XP, can only provide raw materials for building excellent software development teams. But it is far better to start with ideas that have worked for generations of developers before you.

DDJ