Hacker Newsnew | past | comments | ask | show | jobs | submitlogin
1x Forth (1999) (ultratechnology.com)
67 points by pointfree on July 18, 2016 | hide | past | favorite | 30 comments


Forth is awesome. Simple as that. But it's important for people (especially those just being exposed to it) to completely understand why, and what it's done for everyone.

The indirect threading model was absolutely brilliant. Almost every bytecode VM in existence today owes Forth (and Moore) a giant "thank you." If you never write a lick of Forth code ever, you'll be a better programmer just by researching how its put together.

Forth also pushed for simplicity before it was fashionable. Most "modern" languages pride themselves on their landing-page code samples:

sum = fold (+) 0

But, again, this is old hat for Forth programmers. Languages today use a lot of great, new ideas to accomplish this: FP, pattern matching, closures, etc. But Forth was pushing - back in 1970 - for all functions to "do one thing" succinctly. If it can't be done in one line, you needed to factor the code some more. And, it's not just that the result is one line, it's that _anyone_ can look at it and know what it does instantly. Remember, this was back when BASIC and FORTRAN ruled with GOTO.

Finally, I feel that Forth programmers learn - early on - something I don't see many (very good) programmers learning today: instead of constantly abstracting and obfuscating to try and "simplify" a solution, take a step back and try and simplify the _problem_ so the solution is obvious. For example, this is what I feel the Rust team has done with memory management. Instead of just throwing more brain cells and cycles at trying to improve old-hat solutions, turn the problem upside-down and - in essence - remove it entirely.


>Almost every bytecode VM in existence today owes Forth (and Moore) a giant "thank you."

Funny, I see bytecode VM as one of the things that's fundamentally wrong with computing. It's one more layer of unnecessary crap that doesn't even remotely resemble the underlying hardware.


> that doesn't even remotely resemble the underlying hardware.

And that is what makes the code portable and re-usable. See also Rob Pike's Eulogy on Dennis Ritchie[0], where he explains the true strengths of C and Unix:

> In the late 1970s, Dennis joined with Steve Johnson to port Unix to the Interdata. From this remove it's hard to see how radical the idea of a portable operating system was; back then OSes were mostly written in assembly language and were tightly coupled, both technically and by marketing, to specific computer brands. Unix, in the unusual (although not unique) position of being written in a "high-level language", could be made to run on a machine other than the PDP-11. Dennis and Steve seized the opportunity, and by the early 1980s, Unix had been ported by the not-yet-so-called open source community to essentially every mini-computer out there. That meant that if I wrote my program in C, it could run on almost every mini-computer out there. All of a sudden, the coupling between hardware and operating system was broken. Unix was the great equalizer, the driving force of the Nerd Spring that liberated programming from the grip of hardware manufacturers.

> The hardware didn't matter any more, since it all ran Unix. And since it didn't matter, hardware fought with other hardware for dominance; the software was a given.

[0] https://plus.google.com/u/0/+RobPikeTheHuman/posts/33mmANQZD...


The true strength of C is being a good fit to the underlying hardware.

And hardware still very much matters, even if it's running Unix, because of binary compatibility.

I still don't get the VM thing. I mean, I get it from a portability standpoint, but in practice it's been a pretty horrible thing because a stack machine of all things is often picked as the virtual target. Why not a generic register based machine, like most hardware actually is these days? My feeling is the people doing the implementing are infected with the Forth virus, and a stack based VM is one of the few ways they can force their crazy ideas on the rest of us.


You do understand that hardware development has been shaped by C being the defacto standard low-level language? That is, if new hardware isn't easy to code for with C it has little chance of it catching on, unless it's so incredibly low-level and minimal that ASM is the most complicated language you need.

And while I'm no compiler writer, I suspect stack machines are a great choice for modelling an intermediate language because converting it to optimal register use is fairly simple, yet at the same time is completely agnostic about how many registers an underlying machine has.


>You do understand that hardware development has been shaped by C being the defacto standard low-level language?

No, I don't understand that, and honestly have no clue what you're talking about. C is about as simple as things come, and it doesn't necessarily make strange demands on the hardware. It may seem that I'm contradicting my previous statement, but C working well with hardware doesn't necessarily mean it is a force for shaping modern hardware.

Three operand register-based load / store machines make too much sense from a variety of angles for many (any?) other configurations to touch them, that's why they're everywhere.

Stack machines are inherently less efficient, and you only see a bunch of designs (mostly as amateur soft cores) to this day because they are almost trivial to for enthusiasts to implement, not because they kick ass.


> No, I don't understand that, and honestly have no clue what you're talking about.

Clearly.

https://en.wikipedia.org/wiki/Lisp_machine#End_of_the_Lisp_m...


But we don't do this anymore, we don't build processors to cater to the particular needs of a particular high level language because we know now this approach to speeding things up is fundamentally misguided. Hardware is designed based on the types of calculations it is intended to do (DSP, GP, FP, GPU) and that's it. To do otherwise would be inefficient.


I tried Forth for the first time three years ago, and it's been a kind of guilty pleasure ever since. Even though I can write a program about 3x as quickly in a mainstream language, I sometimes reach for Forth because I think it's so much fun. People don't often mention this aspect of it. There's something satisfying -- in the same way that proving a theorem or solving a riddle is satisfying -- about finding a minimal way to coordinate the data flow on the stack. And, no matter how well you do, it seems you can always stare at it the next day and find a tiny improvement.

When I read Moore's material, I feel like he fell into that positive feedback loop in some kind of pathological way... He keeps rebuilding and rebuilding basically the same CAD hardware/sw system, recreating it simpler and more elegant in his eyes every time. For years and years.

Building a forth system from scratch really is an eye-opener... Many have written about how strange and beautiful it is to take your base language and then add the ability to make comments and perform if-then control flow from inside the language. You build it up from nothing but it's a functioning language/interpreter the whole time. Very cool.


I could listen to Chuck Moore all day long.

Here's my favorite - demonstrating his CPU CAD software back in the early 90s, written in Forth and running on a PC. Quite impressive for back then.

Part 1: https://www.youtube.com/watch?v=B_cf8n58Ews

Part 2 (the meat of the presentation): https://www.youtube.com/watch?v=Dbd7Xu0ibJM


https://www.youtube.com/watch?v=NK0NwqF8F0k

"Chuck Moore, the inventor of Forth and ColorForth programming languages, gives a presentation on writing "1x software," or how to avoid common sources of bloat in software. Topics covered include: what it means to be Forth (as distinct from other languages), how ColorForth is simpler still than Forth, how common system services such as files, windows, and even local variables, complexify (complect) the software, the impact of bloat, maintenance on that bloat, etc. And, as is usual for Chuck, deeply philosophical thoughts as well."


Chuck Moore also founded GreenArrays Inc.[1], building on his work at IntellaSys (the previous chip company he founded) and the resultant lawsuits.

[1] http://www.greenarraychips.com/


Basically, you can build a cathedral per project. It will be elegant, all parts will be purely sufficient and focused on getting the pieces of that particular project working.

But when the project changes in certain ways, that bespoke foundation no longer suffices. Time to take the wrecking ball to it and start building a new cathedral.

It is technically true that you can reduce the sheer amount of code involved with a running program, but I for one would not wish to. I would rather inherit the problem-solving, optimization insights, and compatibility tackling of others inherent in OS modules and libraries (along with their "bloat" and complexity), than carry all the weight of non-project-specific development from bare metal. This is a statement of scope and time as well of that of surface of opportunity for bugs and weaknesses.


I think the point is more that you don't build a cathedral at all.

Another article, more interesting in my view than this one, about the apparent mindset: http://yosefk.com/blog/my-history-with-forth-stack-machines....


I would still point out that that article focuses on bringing everything into the small. Redefine problems so you're not tackling large monstrosities, but simplified versions. Make it so that it neatly fits in little bits of code that directly computes simple things.

That's all well and good, but some people are building web browsers, or distributed AI databases, or even large chip development suites that do things that certainly wouldn't fit in 500 lines of Forth. Forth is a great expression evaluator, and has actual compile-time metaprogramming features, which is nice. But it doesn't solve actual large problems for you. It asks you if you can solve a non-large problem, and if you can, you're happy with Forth.

It's sort of like retro programming. You can work in a small (architecturally conceptual) scope that handles a few things elegantly, and implement some cool project within those constraints and building blocks. But it's still building a little cathedral per project.


For "large" projects you do as every other language does: you link/FFI to the C library that does the heavy lifting for you. It's kind of unfair to say "forth can't do browsers" when all browsers are implemented in C/C++ at the core.


You link to C when you need speed, and that's not even usually necessary anymore in languages like JavaScript or Lisp. Linking to C doesn't let your code somehow abstract higher, to deal with larger projects and larger architectural scopes.


It may allow you to take advantage of existing libraries, however.


Forth's simplicity is very beautiful. But that simplicity is also why it's a dead end. Simplicity is not a worthwhile goal in and of itself. People use computers to get things done. Ultimately the goal is to empower people. All those complicated bits are part of what empowers people. We need things like filesystems, network stacks, operating systems and standards to tie it all together. Foregoing all of that in the modern age effectively leaves you with a computer that might as well be a cog. Which may be fine for some classes of embedded systems but that is increasingly not enough.


I think I would disagree. I don't know that I had the same read on the article as you, but it didn't seem Moore was advocating simplicity for simplicity's sake, but as a means to and end (where the end is robust, maintainable software).

>> If it were a lot simpler I would have a lot more confidence that the technology would endure into the indefinite future.

I think he is (correctly) speaking to the byzantine systems which have been propped up (successfully!) to engineer the kinds of applications we are accustomed to (terminal emulators spanning hundreds of thousands of lines of code, web browsers spanning tens of millions etc.). It seems (from what I've read from and about Moore) his idea of empowering people is simplifying the surface area of a problem, rather than simplifying an interface to the problem (for lack of a better phrase).

People can't really use the solutions he presents or advocates to solve the kinds of problems they face with computers as they are being used but the argument might be made that they're solving the wrong problem. I think that we'll eventually come around to some diluted, almost unrecognizable conclusion along these lines - see the number of people advocating a "burn it all down and start over" approach after just half a century of computing. See also the amount of work spent on maintaining compatibility with relatively ancient systems in spite of these arguments.


I take this approach personally. I make it a rule to run as little software as possible. Sadly, every business seems to want an "app" for everything: I know this from being in the applications business. Even if I wanted to, I couldn't get away from the web browser, and it has to be Chromium.

I dream of a future where my bank (for example) publishes API documentation which can be used to successfully implement a working first-class client. That client can then be an actually-good piece of software.

The web is an awful platform for applications, and the only reason for its success in this space was ubiquitous and consistent deployment.


I have a hard time imagining how some tasks could be managed while using the disciplines that make Forth useful.

What are some examples of highly complex tasks that have had Forth programs written for?

Something like Starcraft in Forth. Or perhaps the most complicated Paint Program written in Forth.


Philae, the probe that landed on a comet, used Forth.

https://en.wikipedia.org/wiki/RTX2010

ChipWits was a programming game written in MacFORTH.

https://en.wikipedia.org/wiki/ChipWits


Chuck Moore, who invented FORTH, uses his own CAD system written in his own Forth-like language to design Forth chips. It is a very complex task and Forth discipline is strongly enforced in the whole process. CM also wrote colorForth, which includes what you could call a simple panting program (it is used to draw font glyphs).

In embedded environments like control systems or CNC, it is also quite common to find some kind of Forth. These are not exactly painting programs, but they are used to paint with laser or water jet on real world materials, which is cooler.

And, although it is not Forth, postscript follows similar principles. You could consider ps as a quite advanced paint program.


There is the "Workstation in a Mouse"

http://www.ultratechnology.com/scope.htm

Bit of a toy demo though since it only ran a single fake program.

A chess game: http://www.ultratechnology.com/chess.html

The largest serious suite I know of is a VLSI CAD/simulator for silicon chip design:

http://www.ultratechnology.com/okad.htm

http://www.ultratechnology.com/okad2.htm

Pictures of it in action: http://www.ultratechnology.com/tape1-2.htm


I almost said "uh, Starcraft was written in Forth" but I was thinking of Starflight. (https://en.m.wikipedia.org/wiki/Starflight)



Look here for a colorforth like system: https://github.com/phreda4/reda4

Many programs, 2d, 3d, editors, voxels, compilers, etc ..

Everything is written in that colorforth inspired language.


Is there some level of art in CS and processor design? Yes, because there is no one clearly "right" answer to larger problems. CM speaks eloquently, and presses a lot of my buttons (i.e. I agree with him) regarding what is "wrong" with how the industry approaches computing. But he then goes on to so strongly advocate for his own stuff that he makes it sound like a panacea for all computing ills. He comes across as an underdog with the solution to everything that the world is unjustly ignoring, which is a little weird IMO. He would make a great counter-culture guru.

I wanted to love Forth, but it's a cumbersome tiny language tied to a couple of stacks that you have to micro manage. DUP, DROP, SWAP, etc. are inefficient, much like copying a value from one register to another, which is why most modern processors are 3 operand (to include the copy/move in the operation). And running a stack-based language like Forth on a register-based processor is a poor fit and inefficient, but that isn't necessarily a reason to build custom hardware that fits the language (we don't really do that anymore). This Emperor has no clothes.

Cue the true believers.


Forth is maybe one step up from an assembly language for a stack machine. Is Forth difficult to master? Yes, partly because the target hardware is alien, but mostly because you're doing things in glorified assembly posing as a higher level language than it really is. And the syntax is screwy.

No wonder it's a massive struggle to do anything more than trivial projects in Forth, writing assembly is always a huge pain in the ass.

We need to get past Forth's exoticism and see it for what it really is: assembly + a huge dose of obfuscating downtrodden underdog philosophy.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: