calandale wrote:
Lau wrote:
Hi calandale. I've implemented Forth in various ways. First was on the Sinclair Spectrum - bootstrapped by a large Basic program that ran itself three times whilst generating the machine code in screen memory. Those were the days. Forth can easily result in code that is faster and more compact than assembler.)
Uh...how? Nothing can be faster than properly written native code. The only question is the penalty that you pay for your abstractions.
I knew I'd start argument with that one.
Firstly, have you ever looked at "properly written native code". Very often, you'll find that the code has actually got abysmal inefficiencies in it. What happens is that, up to a point, an assembler programmer's mind concentrates on the problem, but eventually, where the code gets a bit torturous, they'll code something that works, rather than something that is "perfect". With Forth, it is very easy to address the algorithms required, and drop occasionally into assembler for bits that need some speed. Call it cheating, if you like, but it's a fact.
Secondly, there's the cases where you are working with severe memory constraints (e.g. microprocessors). Attempting to produce pure assembler just doesn't cut it (unless you count re-inventing the wheel, by developing a customised interpretive language of your own! It might well look a bit like Forth. I've done precisely this, several times, where I wanted a subset of Forth functionality).
Thirdly, as Forth code can be so compact, you may get an edge by fitting
everything into cache.
Fourthly, and this is more significant than most of the above, counting the "time to completion" of a non-repetitive task, Forth wins hands down. I.e. if it takes you five days to code and debug some assembler that then takes half and hour to solve "the problem", versus half an hour of Forth coding that takes a day to run, you've just wasted four days of your time.
_________________
"Striking up conversations with strangers is an autistic person's version of extreme sports."
Kamran Nazeer