Refactoring some Factor code

Most of the software I work with is very practical. At Oasis Digital we mostly create line-of-business enterprise software, and even when I step away from that, I usually pick up a tool or language that has a good likelihood of mainsteam adoption.

Sometimes, though, I like to really stretch my mind. For that, it’s hard to beat Factor. Factor is fascinating in that it combines a goal of efficiency and practicality, with a syntax and computation model which are quite alien even to a software polyglot. Don’t let the stack-ness deceive you; it’s a big leap even if you’ve used FORTH and grown up with a HP RPN programmable calculator.

So I set about this evening to work with some Factor code, a simple GUI calculator posted a few days ago by John Benediktsson. I bit off an apparently small bit of work: remove the “code smell” of that global variable, and in the process, make it so multiple calcs each have their own model (rather than a global shared state).

Original version from John

My finished version

The two most important pieces of updated code:

The changes consist approximately of:

  • Change all the button words to accept a model input
  • Change the <row> word to accept a model and use map instead of output>array
  • Remove the calc variable
  • Change the calc-ui word to shuffle things around and use make rather than output>array

In case it isn’t obvious from my text above or the source code, I am not a Factor programmer, please do not use this as example code. On the other, I learned a bunch of little things about Factor, and perhaps implicitly about concatenative programming in general, in the process of making this work.

Factor Talk at the Lambda Lounge

Last night (April 2, 2009) at the St. Louis Lambda Lounge I gave a 45-minute talk on the Factor programming language. I’ve uploaded the handout and example code here. I apologize in advance to anyone in the Factor community who reads it and laughs at my “newbie” mistakes and misstatements.

Appistry again provided space and pizza – thanks guys! (Appistry is our locally-grown but widely-known cloud infrastructure software maker – they’d been cloudy for years before the term entered wide use.)

The talk appeared to go over well. There were many important things about factor that I’d love to talk about but didn’t have time. Nonetheless, I think 45 minutes is a good talk length, and I think the format (short talks) is a key part to the Lambda Lounge’s success so far.

Speaking of the Lambda Lounge,  next month there is a “language shootout” – if you want to participate, be sure to join the mailing list and look over the participants. (You need to join the list, to be able to get to the wiki with that page.) I might submit an entry myself, using Factor or another language.

Factor

Over the holiday I looked at the Factor programming language, and was very impressed. It has a Lisp-like metacircular quality, and a remarkably wide set of features/libraries in spite of a very small development team and community. Unlike many other small language projects, Factor is fast, rich, and can produce shippable binaries. Its team cares about robustness, and operates a build farm for multiple platforms. If you can spare a few hours, first watch Slava’s Google Tech Talk, then download Factor and work through some tutorials.

Will Factor become popular? With a FORTH-like syntax, I suspect the answer is a firm No, the syntax is too foreign (even compared to Ruby, for example) for mainstream devleopers. But I find it fascinating nonetheless, and I will keep my eyes open for an opporunity to use it on a small, real project.

It would also make a great topic for the Lambda Lounge, a new St. Louis area user group about which I am quite excited.