Tuesday, February 17, 2009

My Forth Infatuation

You've got to wonder - why the interest in Forth. Well, I'm currently trying to learn the language beyond the basics (and reading the propaganda). And why am I doing this?

Two reasons. The first is the usual - for educational reasons. No doubt, Forth has important lessons about how to solve problems that will come in handy even if I'm programming in PHP. Also, who knows, someone could hire me to do application development in a Forth friendly environment.

The second reason: I think Forth might be an ideal language to program on mobile devices with. That is, if you want to actually write programs on your cell phone (not for, but on), Forth may in fact be the language of choice. Imagine that, you're standing around and want to write some code, so you take out your cell phone and start programming.

Ignoring for a second why you would want to do this (scripting? automation? because you're a geek?), here's what I find attractive about Forth in this context:

  • The syntax is totally flexible and being word based means you don't struggle matching up parenthesis or keeping track of other syntax elements.
  • The Forth philosophy of building software bottom up, makes sense. You could develop a rich vocabulary of words on a desktop computer, and then use them in a convenient way on the actual device.
  • Forth thrives where there are limited resources. A complete Forth environment is measured in hundreds of K, not Megs or Gigs, and is still quite fast.
  • A Forth environment will often include an editor and a file like structure built into it. Essentially, it's its own OS.
  • A Forth environment is interactive, so you can try stuff out easily, yet it also compiles it's code efficiently.
  • Forth words (effectively function definitions) are often a line or two long, making them manageable on a small screen.
  • Forth is highly extensible, so integrating it in with whatever functionality the cell phone offers (like, say, access to an underlying JVM) should be no big deal.
  • Forth has many implementations to choose from, including Java based versions which may require a minimal amount of porting before they run on a cell phone.

In other words, you might consider a cell phone to be a hostile environment to program in - it has few resources, small screen size, a poor keyboard, etc. This kind of environment makes Java or Scheme painful, yet Forth should thrive.

That's the motivation - it should be an interesting experiment to see if my hunch is in fact correct.

2 comments:

  1. re: "you don't struggle matching up parenthesis"

    You struggle?! I doubt it.

    re: "This kind of environment makes Java or Scheme painful"

    HtDW on Android: http://list.cs.brown.edu/pipermail/plt-scheme/2009-January/029722.html

    Kawa Scheme on Andoird: http://per.bothner.com/blog/2009/AndroidHelloScheme/

    ReplyDelete
  2. Grant -

    You're right, I don't struggle. Parenthesis are invisible - just like spaces are.

    But, that assumes you've got an editor that indents stuff properly for you and closes off parens. Get rid of the editor, and you're in trouble.

    That's not a bad thing at all. A modern computer has no problem running this kind of editor.

    But, a cell phone isn't a modern computer - so, configuring it with a smart editor is tricky.

    Oh, and I think Scheme is probably the ideal language to write mobile apps in, when you've got a real computer at your disposal. I can't wait to see if I can't get SISC apps running on my G1.

    But, I still think for on device programming, Forth may be a big one.

    Thanks for the links!

    -Ben

    ReplyDelete