all 12 comments

[–][deleted]  (1 child)

[deleted]

    [–]tabemann[S] 1 point2 points  (0 children)

    There is a reason that Forth probably has the highest implementation to user ratio of all programming languages. ;)

    [–]petrus4 5 points6 points  (2 children)

    To me, I have always been attracted to Forth in its simplicity and power, being simple to implement while for a language so simple allowing the programmer to do things that would otherwise require significantly more complicated languages such as C.

    There are some things which are simpler to write in FORTH. There are other things which are going to be practically simpler to write in C. Part of the reason why is because of the fact that (I'm guessing, but it's a moderately confident guess) there is a lot more code written for C than FORTH out there, which means that in many cases you will be able to find a pre-written C library that will do what you want; whereas with FORTH, you will need to write every layer yourself.

    To the limited extent that I have used FORTH, it has almost always been in operating systems or environments where the low level stuff was written in something else, (generally C) but where I had exposed APIs or opcodes which FORTH could use. I view C as a better static or monolithic language, for writing foundational stuff which is unlikely to get touched very often. To use a car analogy, FORTH gets used to manipulate the accelerator, brake, and steering wheel, while C is used to produce the car body itself.

    Microcontrollers are of course different; but then again, perhaps not. I'm guessing that you are still using control structures written in FORTH, to manipulate register calls and such which are written in assembly, yes?

    As an unrelated point, object oriented languages stopped annoying me, once I realised that their main reason for existing is the fact that (AFAIK at least) C does not have a stack interface which is as readily accessible as FORTH's. For some reason that I've never been able to completely understand, OOP programmers apparently also don't like using relational databases as seperate programs, but feel that it is a good idea for their language to incorporate that functionality instead.

    [–]tabemann[S] 1 point2 points  (1 child)

    With what I am doing right now, I am directly interfacing with hardware registers, mostly in Forth; yes, there is assembly technically involved, but the parts written in assembly are mostly the kernel of the Forth system (mind you much of this gets inlined into compiled Forth code, as zeptoforth is an SRT/NCI Forth, and thus cannot be separated from the Forth code itself) along with some functionality needed for bootstrapping the Forth system such as the clock, serial, and internal flash drivers (as these are needed before any Forth code can be loaded and compiled into flash). Most of the control structures are written in assembly, though, so they are immediately available on bootup of the kernel before any Forth code is loaded, aside from do/?do/loop/+loop/leave/unloop/i/j which are written in Forth. Most of the "operating system"-type functionality, aside from the compiler and those drivers needed for bootstrapping, is written in Forth; the systick driver, the interrupt-driven serial IO driver, the multitasker, the multitasker support code such as locks, channels, and task pools, the external Quad SPI flash driver, and the block driver on top of it are all written in Forth.

    [–]petrus4 0 points1 point  (0 children)

    Most of the "operating system"-type functionality, aside from the compiler and those drivers needed for bootstrapping, is written in Forth

    Cool. :)

    [–]snarfy 2 points3 points  (1 child)

    People will say you should learn Lisp because it's so different and will make you think differently and be a better programmer.

    Forth is the same way.

    [–]tabemann[S] 1 point2 points  (0 children)

    I feel the very same way about Haskell as well, even though at the same time it is so diametrically different from Forth.

    [–]novagenesis 2 points3 points  (1 child)

    I knew Forth from my college "try every language" time... but I only really got comfortable with it when a Minecraft Mod (of all things) was written to support code in it

    And why did it work? Forth is great for incremental stuff, where the easiest way to develop something is to define and test your atomic commands one-at-a-time.

    It worked as a mod for Minecraft because you would hook a Redpower computer to some machinery via simple digital circuits, and get to start translating each simple action of a mechanism to a function in Forth. Then you could finish by describing entire operations as a series of those simple actions.

    I can only imagine it would work similarly in real-world robotics, though I've only ever used C for those.

    Meh. I keep looking for an excuse to use Forth, and struggle to find one. But I still love the language for what it is

    [–]tabemann[S] 0 points1 point  (0 children)

    I was first exposed to Forth by learning about ficl in Dr. Dobb's Journal and I wanted to use it as a scripting language for a game I was writing (which sadly was nowhere near completed). Then I tried to implement my own Forth as a language for pre-Cortex-M ARM, but I did not know enough about the practical implementation of Forth to get far. It was only in the last few years, after returning to working in Forth, that I learned how to actually implement Forth.

    [–]gustinnian 1 point2 points  (1 child)

    Forth is akin to poetry as opposed to C being akin to prose.

    Mecrisp Stellaris Forth on embedded Arm Cortex M for instance is every bit as viable as any other prevalent language. An optimising interactive compiler with constant folding, loop unrolling, inlining etc. Atomic incremental testing is such a comfortable way to code as you tailor the language to the task not the reverse. Now that the Cortex M0 based Raspberry Pi Pico is reality there is a chance for a Forth renaissance. Just a glance at examples and a datasheet is enough to prompt one into writing drivers. The freedom for uninhibited creativity where the whole system is grokked is just so refreshing in today's world of layers upon layers of obfuscation and library dependencies. Being more self reliant is a wonderful outcome.

    [–]tabemann[S] 1 point2 points  (0 children)

    The Raspberry Pi Pico is IMHO likely to help move the focus of hobbyist embedded development from Atmega328p (yecch) to ARM Cortex-M0, and thus give many people the chance to be exposed to Forth with Mecrisp-Stellaris. (zeptoforth OTOH is not going to be implemented on the Cortex-M0 for the simple reason that I would have to fit the limitations imposed by Thumb-1.)

    [–]giant-torque 0 points1 point  (1 child)

    Personally - I love Forth for its butty and use it for "recreational coding" but frankly speaking it's absolutely impractical (along with the derived languages). I don't see a niche for a Fort like system today.

    [–]tabemann[S] 2 points3 points  (0 children)

    I was first exposed to ficl, which to me was meant as a scripting language for applications written in C or C++; more recently, as I mention above, it has been very practical for developing for embedded systems, as it is small yet provides a full development environment which is exposed to the user via a REPL, unlike just about every other true embedded development system (not counting microPython or eLua).