Re: Forth Frustrations



George Peter Staplin wrote:
I'm extremely frustrated by Forth lately.

I was working on an interface to my new window system in Ficl. I found it extremely frustrating to juggle around data on the stack, such as 2 RGBA color components when building a gradient. 8 items or more.

So, I asked in #Forth and was told not to do that, because I shouldn't have more than 3 or 4 items on the stack at once. My code was horrible apparently. So, I used allocate, and then I had to call free. I grew tired of that interface. Then it occured to me that people building large matrices in Forth would of course have more items on the stack than that, so the Charles Moore dogma doesn't apply, and it's a bad dogfood. I suppose people may not even do that with Forth though. The constraints imposed by the community and Charles Moore have limited Forth.

So, I came upon another solution. I added a concept that I call a "super local," to Ficl's C code. A super local works like this:

: quad 4 parse-word (superLocal) ; immediate compile-only

: some-word quad color1 ( pops 4 items ) quad color2
color1 ( pushes 4 items ) ;


Only then did I discover that doesn't really help me in most cases to reduce complexity. I talked about my (superLocal) in #Forth and was of course criticized. The Forth community I'm getting the impression likes to criticize. I've been accused of programming C in Forth, as if that's somehow terrible, but I digress... I realized that I need a way to get the cells in an individual super local. That's where I stopped. I was thinking that indexed keyed arrays might be an approach, or a completely different language.

Forth is great when data flow can easily be made LIFO (and it often can). Forth stumbles when the data flow is not naturally LIFO, especially if you worry too much about conformance to dogma.

One technique that often helps is to use variables. There, I'm a Forth heretic. But everybody knows that ;-)


Now unmotivated and realizing that the structure really sucks in my Ficl code by some standards, I wrote some C code and felt much better. I think C is much easier, because it comes with rich structure abilities out of the box.

The problem isn't that Forth needs structure abilities out of the box. What it needs is real portability, a usable library mechanism, and a collection of published libraries, including structures.

I'm user of a C-based Forth, LSE64. When C's the right thing, I'll drop into C. Forth makes a fine scripting language (and much more) for C.

As Rob Pike once said in his notes on C:
"Rule 5. Data dominates. If you've chosen the right data structures and organized things well, the algorithms will almost always be self­evident. Data structures, not algorithms, are central to programming. (See Brooks p. 102.)"

I believe page 102 is from the Mythical Man Month, and the subsection of that reads "Representation is the essence of programming."

It's a good way to think about programming, at least until it stops working. Then try another way.


I feel sad, because my Forth books have mostly gone to waste. I ordered them from Forth Inc. years ago, and have read them off-and-on since. Since I left the Tcl community last year, I've tried to turn to Forth, but now I find it's just not there. I hate being criticized for using features of the language, and I see it happen in this newsgroup too. I'll add my own too; I think that using the return stack words for temporaries is dirtier than using a local.

Indeed. Too many Forthers delight in write-only code.


So, I expect you all to tell me how wrong I am, and what an awful person I am for posting this.

Nope. I'm going to tell you how right you are. But don't give up on Forth: like most things it's like the girl with the curl ("When she was good, she was very, very, good, but when she was bad she was horrid."). Use the good, avoid the horrid.

Tell me how I should use a different language (again). Go right ahead. You can write me off as a troll if that makes
you feel better. :(

Humans are prone to idolatry. But programming is a practical activity: just be practical.


Sincerely,

-George


--
John Doty, Noqsi Aerospace, Ltd.
--
Specialization is for robots.
.



Relevant Pages

  • Re: A taxonomy of types
    ... (I do not see why inheritance is required here.) ... without an »object-oriented programming language«, for example, ... in the programming language used. ... indirectly) implements an interface IA whose declaration ...
    (comp.lang.misc)
  • Re: FORTH levels
    ... Most working on a collaborative project do not choose the programming language they are using: it is thrust upon them by the needs of the collaboration. ... When Iverson and Hui came up with J-- in part to remove APL's special character set and make it more "user friendly" not much of a community formed around it. ... But RPN does not require a visible stack, any more than any language requires a visible stack to rebuild its semantic trees from its flat expression. ...
    (comp.lang.forth)
  • Re: Announce: Alpha release of BDB-BASIC
    ... those early BASICs, and are still most comfortable with them. ... language will be the most used to program microcomputers five years ... But as soon as you remove them you make the interface more ... programming language that's as easy to use as RPL (The programming ...
    (comp.lang.basic.misc)
  • Re: Programming Languages / IDEs
    ... I am not a professional by any means the Language I am most familiar ... How did you learn your programming skills? ... IMHO - an IDE does not really add that much. ... prototype interface in less time than the folks using visual studio on MS. ...
    (alt.linux)
  • Re: FORTH levels
    ... I also note that inexperienced Forthers often seem to write clearer code than experienced Forthers. ... The Forth culture emphasizes clever stack manipulation, eccentric notation, and code efficiency over readability. ... Every programming language presents a model for computation. ... They are choosing one or more programming paradigms that the programming language offers. ...
    (comp.lang.forth)