Forth Programming Guidelines
As with any other programming language, it's possible to write good Forth, and just as easy to write bad Forth. Here are some Forth tips:
Limit your stack usage to three or four words. Any more than this, and you will find it very hard to keep mental track of where you're up to.
Use several short word definitions rather than one long word definition. Don't ever create a Forth word that is hundreds of lines of code long. The beauty of Forth is its ability to build upon itself, allowing you to test as you go. To this end, keep your Forth words to three or four lines of code where possible. That might sound strange if you're used to other languages, but once you get into the swing of Forth, you'll understand that this is a logical approach to coding.
Keep it simple and focus on what you're trying to achieve. A simple Forth word that solves a specific, simple problem is better than a complicated do-all word that is difficult to write and hard to debug.
Check for data that is out of range or erroneous and generate useful error messages or diagnostics.
There's a lot more to this powerful language than I've shown here. For more information on Forth, visit the Forth Interest Group (FIG) at http://www.forth.org or go to Forth, Inc. at http://www.forth.com. Charles Moore, the creator of Forth, has a web site at http://www.colorforth.com. If you'd like to play with Forth, there are dozens of free Forths available for download over the Internet. For gnu's Forth, go ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access