Slashdot Mirror


Forth Application Techniques

oxgoad writes "Sun Microsystems, Federal Express, the National Radio Astronomy Observatory -- what do they have in common? All have used, or are currently using, the programming language Forth in critical subsystems of their products or processes. 'What is this language Forth?' you ask. Forth has been called 'One of the best-kept secrets in the computing world.' Read on for a review of the book Forth Application Techniques authored by Elizabeth D. Rather." Forth Application Techniques author Elizabeth D. Rather pages 148 publisher Forth, Inc. rating 5 reviewer oxgoad ISBN 0966215613 summary A concise introduction to the Forth programming language.

Who & What

Elizabeth D. Rather, president of Forth, Inc., would appear to be the second Forth programmer in the universe. This distinction came about in 1971 when she was brought in at the Kitt Peak NRAO to maintain code written in a quirky language developed by Chuck Moore. Running on a DDP-116 and a H316, this code was responsible for controlling the telescope, data acquisition, and graphical display. After a few years, Moore and Rather, along with Edward K. Conklin, formed Forth, Inc. to attempt commercialization of the language.

Forth Application Techniques attempts to provide a comprehensive introduction to the language for the neophyte Forth programmer. I would say that it pretty much succeeds as such, quietly plodding away through each primitive and feature. It is written in workbook style with various sample problems for the reader to complete. You might not be a Forth coder after reading the book cover to cover; however, you will have a working knowledge of the language and should be able to walk through legacy code with a minimum of difficulty.

If I might step aside from my role as unbiased book observer for a moment, I would like to make a few comments about the state of programming languages in general. It seems that quite often we take for granted essential, but practically invisible, tradesmen such as plumbers and garbage collectors. (Fire your janitor and your web designer -- guess which one you will miss first. Guess which one will still be employable 15 years from now.) Yet, without their services, our daily quality of life would certainly fail to meet our expectations.

Likewise, Forth seems to be an invisible language. No flash, no e-commerce, and no glamour. Such is the nature of embedded systems -- even though every Federal Express delivery driver carries a Forth-based device on his belt. This appears to have resulted in a dearth of quality books dealing with Forth. Search your favorite online book retailer and note the dozens of Forth books that are no longer in print.

While Scheme is from the ivory tower and Forth might be said to be from the machine shop, they do have something in common that is a possible deterrent to the popularity of Forth. Like Scheme, you either get Forth -- or you don't. Stack-based languages leave some programmers dazed and confused. And, as with most languages, it is possible to write some truly obfuscated code. Any language that will allow you to define the number 4 as a word that places the number 3 on the stack can be a frightening weapon in the hands of the contrary.

Kudos

Forth Application Techniques can be commended on its consistency. Careful attention has been given to typefaces to distinguish interpreter output from user input. All primitives and defined words are covered in a clear and unambiguous manner. The book is spiral bound in a plastic binding, and this lay-flat binding is great when using it at your computer or while eating lunch.

Quibbles

The same lay-flat spiral binding that is such a boon when working at the computer can be somewhat of a nuisance when when attempting to hand-hold the book -- the book tends to flop about and feels very insubstantial.

While Forth Application Techniques is very complete and accurate, it is also extremely passionless. You might compare it to a biology textbook discussion of sexual reproduction with no mention of romance. There is no discussion or examples of using Forth in ways that will bring enlightenment. To be fair, in the preface it states that the purpose of the book is to support Forth classes taught at Forth, Inc. This is something that is not entirely clear when examining online retailers' display of the book.

Also of note is that there are occasional features specific to Forth Inc.'s SwiftForth product documented in the book. I would not consider this a real issue as all instances are clearly denoted with an icon. With the exception of chapter 9, which is entirely Forth Inc. specific, the readability is not affected in any way.

Crimes

Forth Application Techniques has no index. With its workbook styling, most will not consider this to be a tragedy. All the same, it would be convenient to look up primitives and defined words.

Conclusions

Should you buy this book? That depends on your desired end result. It is adequate for a quick introduction to Forth. If you are intending to write production code I believe Forth Programmer's Handbook (from the same publisher, review forthcoming) would be a better choice. If possible, I would supplement either with a used copy of Leo Brodie's Starting Forth -- an out-of-print classic.

Where I foresee this book to be a great benefit is in ordering a half-dozen copies for your programming team prior to taking on a legacy project or when considering Forth as a new development platform. The members of your team that "get it" can then enlighten the others with this invisible language.

Table of Contents

  • Preface: About This Book
  1. Introduction
  2. Simple Forth Primitives
  3. Structured Programming In Forth
  4. Data Storage
  5. Strings And Characters
  6. Number Conversion
  7. Vectored Execution
  8. Advanced Concepts
  9. Multitasking
  10. Style Recommendations
Disclosure

I received a review copy of this book from the publisher. Thus, my loyalties and opinions may be completely skewed. Caveat Lector.

Forth Application Techniques is available from Forth, Inc. and from some online merchants like Amazon. Slashdot welcomes readers' book reviews -- to see your own review here, read the book review guidelines, then visit the submission page.

9 of 255 comments (clear)

  1. So two of us own that book :-) by redbaron7 · · Score: 5, Informative
    I bought this book a couple of years ago, when I had an idea for a project which I thought could benefit from a Forth-style system. In those days I did a lot more at-home dabbling which I just don't have time for now, and that idea has gone by the wayside.

    If you have any questions for Elizabeth Rather, she can be found on Usenet. When I asked for an "introductory book for modern Forth" I believe she recommended her own book! :-)

    Threaded Interpretive Languages (TILs) such as Forth have very elegant inner workings. I even wrote one as a kid. And I actually used it for a few months. Although my Forth-inspired TIL was limited to 16 bit integer math (on an 8086 I think it was), I still managed to get it to draw 3d wireframe graphics in real time on a PLUTO graphics card :-)

    RB

  2. No Thanks by acehole · · Score: 5, Funny

    Until I see a decent Language to switch to I'll stick to my punchcards.

    --
    Be you Admins? nay, we are but lusers!
  3. Forth is alive every time you print by LineGrunt · · Score: 5, Informative

    Postscript is based on Forth. You can "program" Postscript...

    Don't know why a non-printer driver person would want to, but you can...

    -LG

  4. "best kept secret" by extremely · · Score: 5, Funny

    "Best kept secret" is actually a review for Forth, not the problem. If I'm going to have to deal with a stack, it should have butter and syrup on it.

    --

    $you = new YOU;
    honk() if $you->love(perl)

  5. Still Worth Learning by Anonymous Coward · · Score: 5, Interesting

    Forth is still great when resources are very limited... Palm OS programming, for instance. I've used it there and in several embedded systems projects without an underlying OS, and managed to run circles around a team coding for 8051-based systems in PL/M (I think that's the name of what they were using, but I'm not 100% certain).

    I also tried a version of Forth-83 for Windows by Ray Duncan's company, LMI. I tried to code up a DDE server, and while it worked, it was painful. I've come to believe that Forth is more trouble than its worth when interfacing to APIs designed for C. Such APIs are often poorly factored (relative to how you'd solve a problem in Forth), and take too many parameters of different sizes as arguments. Even with the Palm you jump through some of these hoops, but in that environment it's often worth the effort.

    The underlying principles of Forth are worth knowing no matter what language you program in... there's a lot of simplicity at its core, and it'll help you understand how to program for other stack based languages such as .NET's CIL. And nothing I've seen teaches factoring better than Forth (too bad Brodie's "Thinking Forth" is out of print).

  6. Elizabeth Rather by Draoi · · Score: 5, Informative
    I had the honour to meet Elizabeth at Apple during an OpenFirmware/FCode training course. She's an amazing teacher & is one of the first people ever to use the language, having worked with Chuck Moore in the late 60s ....

    She now works with Forth, Inc. Check out forth.com. They have an excellent history of the language here. BTW, there are free Forth interpreters for just about every platform out there. It's a cool language.

    Chuck Moore's own site is here

    --
    Alison

    "It is a miracle that curiosity survives formal education." - Albert Einstein

  7. Modern Forths are compiled, not interpreted by Junks+Jerzey · · Score: 5, Interesting

    I keep seeing mentions of Forth being an interpreted language, but that's just an implementation choice. Most modern Forths, such as iForth, VFX Forth, and Forth Inc's own SwiftForth, generate machine code and do optimization to varying degrees. iForth and VFX Forth analyze stack operations and replace them with register operations where possible. Benchmarks have shown that iForth generates better floating point code than Microsoft's Visual C++ compiler (which already generates better floating point code than gcc).

    So why don't you hear about Forth much? A couple of reasons:

    1. Forth doesn't have much in the way of standard libraries, so you'll almost certainly get more bang for your time writing quickie applications in Perl or Python than Forth. Try writing a Forth program to read in a file of strings of arbitrary length and sort them, for example. This is a one liner in Perl.

    2. Forth has always been geared toward simplicity, but modern desktop environments (Linux, Windows, MacOS) are hugely complex. Forth arguably isn't the best match for such complexity. Embedded systems are different.

    3. Forth is best viewed as an interactive alternative to C or assembly language. Certainly from the interactivity alone Forth is a better choice for incrementally building a application than assembly language. This is why Forth gets a lot of use in embedded systems. But with desktop computer speeds being insanely high, it's hard to justify working on that kind of level under, say, Linux or Windows.

    (I fully expect this to be followed by "Not true!" rantings from a Forth zealot or two. But you really do have a hard time pointing to compelling applications written in Forth for modern desktop OSes. Python is a good language, so you see some amazing applications written in it (e.g. Zope), but despite all the religion surrounding Forth, you never see much to show for it on the desktop.)

  8. [Old Fogey Warning] I programmed in Forth once... by Jack+William+Bell · · Score: 5, Funny

    ... And I certainly remember the joke about how in Forth you "Foot in yourself shoot."

    I did my Forthing many years ago (far, far too many). The usual thing, embedded systems work, but I actually did the programming on an IBM PC (original) using a Forth boot floppy (it had its own environment/OS). Then someone else did integration with the embedded system.

    It was a truly weird language, and it made it far too easy to create 'write-once' unmaintainable code. But it was my first introduction to many concepts, including a language that was truly 'cross-platform'. And it led to a short job at Aldus because I already understood stack-based languages, so Postscript wasn't a shock to me.

    In many ways Charles Moore is a seriously twisted genious. I have always rooted for him, despite the fact I prefer to use a cleaner, more readable language. (Can we say 'Python'? I knew we could.)

    So, in the end, I cannot say I think Forth should be in everyone's toolkit. For that reason I expect this review will be of limited use to most of us. (Attn. Moderators, notice how I managed to get this post on-topic in the last sentence. Now you have to mod me down as 'flamebait' or 'boring' or something.)

    Jack William Bell

    --
    - -
    Are you an SF Fan? Are you a Tru-Fan?
  9. Re:Computer languages are all the same by AB3A · · Score: 5, Insightful
    Let me guess: fasteners are all the same, so let's use a hammer to pound in a screw.

    Most languages have a focus toward a particular aspect of programming. Some are very good for Object orientation. Some are good for low level hardware I/O. Some are designed to parse input in optimal fashion. Others are designed for terse code.

    They all have a purpose. That's why we have software tool chests with lots of languages and tools which can be used in so many ways.

    Forth is good for low level I/O work. It's often used in Robotics and control systems. It is a minimalist language and it generates very fast, memory efficient code. These are good traits when dealing with embedded processors. But once you try scaling it up to do more complex tasks, you discover its limitations. That's when higher level languages start to shine.

    --
    Nearly fifty percent of all graduates come from the bottom half of the class!