Category Forth

Forth - A very different way to program and think about the art and science of programming.


"Writing software as multiple layers is a powerful technique even within applications. Bottom-up programming means writing a program as a series of layers, each of which serves as a language for the one above. This approach tends to yield smaller, more flexible programs. It's also the best route to that holy grail, reusability. A language is by definition reusable. The more of your application you can push down into a language for writing that type of application, the more of your software will be reusable."

Forth is a language that exercises the above to the extreme. In procedural programming languages the computer is instructed to execute a series of operations, and the notion of subroutines is introduced more or less as an afterthought. In Forth, the entire effort of programming constitutes of building small routines that call other routines. On top of each level of routines (or words, as they are called in Forth) you create another level, until you come to the top level, where the large scale behavior of your program is defined.

The words can (and should) be used in other contexts (or applications) too, thereby achieving levels of reusability not readily found in many other languages. The core of Forth is quite small, and usually most of a Forth implementation is programmed in Forth itself. Forth is most efficient in situations where you have to combine new hardware with complicated or abstract behavior, as in situations where there is no established programming platform and culture to go with it. Efficiency here means two things: program development is quite fast compared to e.g. C or assembly language, and it only takes a reasonable Forth programmer to make code as fast as that of excellent C or assembly language programmers. This is mainly because Forth inherently encourages small-step incremental bottom-up programming, and it is an interpreted language where the writing-debugging cycle is quite concise. Since there is no arbitrary distinction between system functions and user functions, you can even redefine the foundations of the language, if you need to.

Superficially Forth resembles programming on an old HP calculator. Forth is a Reverse-Polish, stack-oriented language. First you bring the variables on the stack, and then invoke the operation. Some early HP calculators used Forth explicitly as the programming language. (Somebody please fill in which models?) (HP-80 series had Forth. A 48K plug-in module was available for the HP-71B. And don't forget HP's language Reverse Polish Lisp (RPL) that integrated elements of Lisp and Forth was implemented on the 18C, 28 series, 48 series, and 38G.) The later HP-28 calculator uses a programming language that for all practical purposes is a subset of Forth. The word Forth, however, does not appear in the manuals.


See original on c2.com