by 90s_dev · 1y ago · 0 comments
I prefer Factor[1] over Forth, however. Maybe you'll like it!
> 2 3 + 4 * .
There's a lot more there to mentally parse than:
> (2 + 3) * 4
It's the same as when Rob Pike decries syntax highlighting. No, it's very useful to me. I can read much quicker with it.
It's the same principle behind how we use heuristics to much more quickly read words by sipmly looking at the begninnings and ends of each word, and most of the time don't even notice typos.
Some people prefer:
2 3 + 4 *
Some other people prefer: (* 4 (+ 2 3))
And some other people prefer: (2 + 3) * 4
I personally find the last one easier to read or understand, but I have had my fair share of Common Lisp and Factor. :DSyntax highlighting is useful for many people, including me. I can read much quicker with it, too. I know of some people who write Common Lisp without syntax highlighting though. :)
2 .... hundreds of words .... +
where the operands of + are 2 and the result produced by the hundreds of words!Which could also be:
.... hundreds of words .... 2 +
which would be a lot easier to read!If you're writing Forth, it likely behooves you to try to adhere to the latter style of chaining where you take everything computed thus far, and apply a small operation to it with a simple operand. Not sure if it's always possible:
... complex numerator ... ... complex denominator ... /
Now find the division between the numerator and denominator among all those words.Yes, this is why you are supposed to have short words. You should factor out the complex parts into short, self-contained, and descriptively named words, which is going to make your code much easier to read, test, and maintain.
For example:
Instead of:
a b + c d + * e f + g h + * /
You should probably have: : compute-numerator a b + c d + * ;
: compute-denominator e f + g h + * ;
: compute-ratio compute-numerator compute-denominator / ;
Most (if not all) Forth books mention this as well.