▲ | selvor 4 days ago | ||||||||||||||||
It may look more high-level than something like C, but it is actually no more high level than a macro assembler with registers eliminated. As there's no syntax tree, essentially every word that is parsed from the input stream is replaced with a subroutine call. So the resulting FORTH code is nothing but a series of subroutine calls. In my experience quite often writing in assembler is easier than FORTH unless you have a strategy and self discipline, which when acquired makes one a whole lot more productive than using assembler, and arguably more so than a high level language. There're no pointer arithmetics, no rudimentary type checking, not even an array type (you have cells and addresses). There is nothing that throws an error except things like stack over/under-flow checks, and if you are lucky your code will crash. If not debugging can be tricky. Stack imbalances won't be reported/checked for you, there is no bounds checking for anything (not even structs). But there are conventions/strategies to prevent these kinds of bugs from happening that one needs to either discover for themselves, or find out in books (the book Thinking Forth helps, but is not enough I would say). Working with the stack can be more difficult than with registers, although the latter can be easily simulated with variables, which is often frowned upon. But words like CREATE ... DOES> enables meta-programming that helps with generating code with code, and makes it quite powerful, but can make your code complicated to reason about (see the concepts of compilation vs. execution vs. interpretation semantics described in ANS Forth). In the end the appeal of FORTH for me is in its "simplicity" (but nowhere any ease of use as it requires mastery of laying out code in memory as you would do in an assembler without any help from the language itself), its overall philosophy (see Chuck Moore's A Problem Oriented Language) on focusing on the nature of the problem rather than thinking in terms of the tools/language given to you (build a "language" for the problem), and providing solutions with as minimal "cruft" as possible. | |||||||||||||||||
▲ | cess11 4 days ago | parent | next [-] | ||||||||||||||||
Factor addresses some of these concerns and instead of giving you a bare metal REPL you get a Smalltalk-like image: https://factorcode.org/ It's rather neat. | |||||||||||||||||
| |||||||||||||||||
▲ | sph 4 days ago | parent | prev | next [-] | ||||||||||||||||
> Working with the stack can be more difficult than with registers, although the latter can be easily simulated with variables, which is often frowned upon Yet every time I hear experienced Forth developers recommending to use more variables, and that newbies tend to eschew them, making the code much harder to read and understand than it is necessary. You become a true Forth programmer once you go past the code golf and stack juggle phase. | |||||||||||||||||
▲ | drivers99 4 days ago | parent | prev [-] | ||||||||||||||||
Anything that you say is missing can be added. I'm no expert but when I had some confusion about the stack I would create a word that did something in a balanced way, test it quickly, and use that word instead to build on. Forth makes it easy to climb the levels abstraction quickly. The method that it uses to interpret/compile a word varies by implementation. Subroutine call is just one of them. | |||||||||||||||||
|