5 ms·
Agree with the parent, it's a language worth knowing like LISP is worth knowing, but (unlike LISP) it is not a good language choice for almost all use cases in
by jll29 4y ago
Agree with the parent, it's a language worth knowing like LISP is worth knowing, but (unlike LISP) it is not a good language choice for almost all use cases in 2023 (almost all use cases are not that memory constrained any more, even embedded systems), for the same reason you shouldn't use Perl (it is very hard to read code).
I was going to say "its main disadvantage is that the only way to find out what a piece of code does is to execute it mentally" (non-declarative) but one may say that of every language to an extent. Instead I will say it feels like using a macro-assembler for a stack VM.
Clifford Stoll, author of "The Cuckoo's Egg", in which he described how he chased a hacker, allegedly used FORTH to control a radio telescope (https://www.amazon.co.uk/gp/product/1416507787 https://www.amazon.co.uk/gp/product/1416507787) back in the days (not sure, I might have got this nugget from the book).
- pkaye 4y agoThe original use for FORTH was to control radio telescopes.
- macintux 4y agoI was delighted (and saddened) when I discovered a Forth manual written by W. Richard Stevens for Kitt Peak observatory. A great writer lost far too young.
- slaymaker1907 4y agoI don't know, I think it can be a pretty solid language depending on what variant you use. There are few pieces of code in Forth that make me think "man, this seems repetitive, but I don't know how to actually generalize this" because abstraction is little more than structured copy+paste.
- avmich 4y ago> abstraction is little more than structured copy+paste Which perhaps is logical, since Forth is a concatenative language. Roughly, one can split a program in half at any point and get two subprograms which can be called one after the other - in the same order - to get the same result. Like, to calculate 2 + 3 * 4 one would write 2 3 4 * + in Forth, this sequence can be split in two 6 different ways, and we can even meaningfully interpret those two parts each time. E.g. part 4 * + is a two-argument function which multiplies first (closest to the top in the stack) by 4 and sums the result with the other argument - in JavaScript it would be function(x, y) { return 4*x+y; }.
- mananaysiempre 4y agoI don’t really feel I can judge whether it’s good or not to use generally, but it’s difficult to obtain a similar degree of DSL-ness even on pretty powerful (e.g. Micropython-grade) constrained platforms. Forth, along with Lisp, is one of the original DSL substrates (Thinking Forth spends like half its pages on preaching EDSLs), and I don’t think it’s really been supplanted in that niche by anything that doesn’t require a beefy GC. (The extremely easy bootstrapping from any point down to an ISA manual and a ROM programmer—or a monitor that accepts peek/poke/goto from a UART—I also don’t think has really been replicated anywhere else.)
- bob29 4y agoDSL just a library that exports a lot of functions that work together any language that allows naming functions does that?
- mananaysiempre 4y agoIf you don’t care about syntactic convenience, yes. In practice, a(n idiomatic) Forth “library” can have an API like, for example, 1000 ,bp) ax mov, for laying down assembly code in memory (might look a bit unusual, but think “postfix assembler” and it’ll become natural soon enough). If you want this to compile down to byte writes and arithmetic without requiring an assembler library at runtime (DynASM-style), you can do that as well. Custom control structures[1], object systems, perfect hashing, parser generators, all that fun stuff that’s possible with flexible syntax and arbitrary compile-time code execution, people have done it. You never have to think whether an X-macro is sufficiently ugly yet to warrant a custom preprocessor. (If you want to say “web templating”, you can say “web templating”, except it’s not that pleasant with manual memory management, and most of what I’m thinking about was written in the 80s.) There’s nothing impossible about this in any language (the absence of a competent C REPL continues to amaze me), but not all languages are good at everything they can technically do, and Forth is good at these. (Forth is also bad at some things. If you want code that transparently works on floats and doubles, or 32- and 64-bit addresses, on the same system depending on a compile-time setting, it’s going to be painful. Passing abstract types by value is impossible to do elegantly as far as I know. Omitting unnecessary code from the executable, trivial with static libraries and a linker, requires adapting half your implementation and is a serious selling point for commercial Forth systems. And so on.) [1] I know we’re all alleged adults and are not supposed to get excited about these, but does LuaJIT’s FOLD tree peephole optimizer, for example, qualify as a legitimate custom control structure? (It’s implemented with a combination of macro magic and a custom preprocessor.)
- SoftTalker 4y agoPerl doesn't seem like it should necessarily be hard to read (I'm not a perl programmer) but agree that most perl that I've seen is pretty opaque. I guess if you really get to know the idioms maybe it's easier.
- tmtvl 4y agoI guess if you really get to know the idioms maybe it's easier. It is, as long as you stay away from things like selfgol* or memowe's keywords only JAPH** (which is technically very readable, it's just very hard to comprehend). * https://libarynth.org/selfgol https://libarynth.org/selfgol ** https://www.perlmonks.org/?node_id=594266 https://www.perlmonks.org/?node_id=594266
- turtledragonfly 4y ago> for the same reason you shouldn't use Perl (it is very hard to read code) I slightly disagree with this take on Perl. Agreed that it is easy to write code which is hard for others to read, and agreed that it is often not a good idea in a large-team setting, for that reason. But there is a lot of code that doesn't fall in that category, and Perl, by its nature (and by CPAN), can be remarkably good at just "getting stuff done" for oneself. All the wild syntax can really help in expressing a concept succinctly. I wouldn't say the same about Forth, though.
- efitz 4y agoSomeone told me once that Perl was write-only.
- jll29 4y agoNot trying to disparage Perl, which has some utility, like most languages, notably fast regex engine and presence on many systems. BUT: I've been writing Perl for much longer than Python, but despite wanting to write readable/maintainable code, Perl has a tendency to get you to a stage where your code looks cryptic (part of it is by design - Larry Wall, a linguist, values implicitness as "context" - I think explicitness, by contrast, should be aspired to, in order to avoid confusion). I've never written cryptic Python code (and I am not a particular Python fan, as I prefer statically typed compiled languages), but it should be said that clarity is one of Python's advantages. I agree with you that it is easier to write readable Perl than readable FORTH, which could be due to the similarity of Perl with other non-stack imperative languages.
- zelphirkalt 4y agoWell, in Forth there isn't much "wild syntax" to begin with, so naturally you couldn't claim the same about Forth.
- jcpst 4y ago> it is not a good language choice for almost all use cases in 2023 I think I agree with this. But it’s fun to think about wild scenarios where it would make sense. Like some dystopian future where people are trying to cobble found hardware together to make something.
- knowledge-clay 4y ago> Like some dystopian future where people are trying to cobble found hardware together to make something. https://git.sr.ht/~vdupras/duskos https://git.sr.ht/~vdupras/duskos http://collapseos.org/ http://collapseos.org/
- jcpst 4y agoThank you!
- ArtixFox 4y agoIf a Forthlike language was to be made today, what features would it require to not be a hard-to-read mess? I can see some type of typesystem being useful, I dont know what else can make it better.
- t-3 4y agoTyping would make things more verbose, but not any more readable than just writing words for each type of data you're dealing with, which accomplishes the same thing. Forth can dictionary mask and forget words, so typed-lang-style overloading is trivial, but unnecessary. Many short word names could be expanded from symbols and abbreviations suited for 4-character names into more verbose versions, but the underlying RPN stackiness would still prove an impediment to broad understanding. Native vectorization like APL or Lisp would increase the base complexity of the language machinery and make implementation more complex, but would allow the language to be simpler by getting rid of the need for most stack reordering.