Re: Forth Frustrations
- From: John Doty <jpd@xxxxxxxxxxxxxxxxxxxxxxx>
- Date: Mon, 02 Apr 2007 09:16:50 -0600
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 selfevident. 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.
.
- References:
- Forth Frustrations
- From: George Peter Staplin
- Forth Frustrations
- Prev by Date: Re: Forth Frustrations
- Next by Date: Re: Forth Frustrations
- Previous by thread: Re: Forth Frustrations
- Next by thread: Re: Forth Frustrations
- Index(es):
Relevant Pages
|