Thursday, January 3, 2008

Learning Factor

Learning Factor is tough. One reason for this is that Factor is very different from other programming languages. Programmers today are used to imperative programming languages where data is stored and passed around in named variables (or function calls, which name their variables). Factor is the opposite of this. A lot of code tends to be written in a functional style, and even more jarringly, variables are rare, only referenced in a small fraction of words. Nobody intends to change any of this; it's a feature, not a bug!

What we do need to change is the other reason for Factor's difficulty to learn: lack of documentation and organization thereof. It's hard for me to say this when a lot of effort has been put into documentation, especially creating a comprehensive reference for the Factor core and libraries. When I got started on Factor, there was basically no documentation at all; I just asked questions on the IRC channel. Now there's tons of it, but it's in many places.

Two starting places (not necessarily in this order) are the FAQ and the Factor cookbook. The Factor cookbook is included in the Factor distribution, accessed by running Factor, selecting the "Browser" tab and clicking on Factor cookbook, or online. It was written by Slava Pestov, and illustrates really clearly the basics of Factor.

But once you get done with that, where should you go? Here are a bunch of options, depending on what exactly you want to:
  • Factor's included reference documentation, written mostly by Slava, is sound and basically complete but not very tutorial-like.
  • Slava's blog is the best place to learn about new language features as they're developed.
  • Aaron Schaefer wrote a series of blog posts that introduce Factor, starting here.
  • I wrote a bunch of introductory blog posts.
  • Elie Chaftari wrote an introduction to programming Factor, and he wrote about the FFI.
  • You can look at many other blogs about Factor through the Planet Factor aggregator. Scattered around here are many more introductions to Factor.
  • The Joy papers by Manfred von Thun provide a theoretical basis for concatenative languages.
  • You could try reading some source code in the libraries. Simple demos have the tag demo, which you can query in the vocab browser. The core sequence library is a good place to look for clean, idiomatic code.

The best way to learn Factor, after you have a grasp of the basic syntax, is to play around with it and try to build something useful. Here are some project ideas:
  • Write a date parsing library, accepting ISO 8601 format or a natural English (and maybe internationalized) format. A calendar backend already exists.
  • Create an embedded, lexically scoped, infix/prefix DSL for complex math calculations
  • Make an analog clock with the Factor UI library, or a GUI for Factor server administration
  • Solve some Project Euler problems in Factor
  • Whenever you encounter some part of Factor that you don't like, or some missing language feature, implement it. It's very likely that you'll be able to do whatever you want in the library

These problems may sound a bit difficult, but most of them have simple part-way solutions so you can begin to get your feet wet. And with any of these, if you have useful working code, we'd be happy to take it into the Factor library, if you feel like releasing it under a BSD-style license.

If you get stuck, don't despair! The friendly people on the Factor mailing list and's #concatenative channel are here to answer all of your questions. You could also just email me. Eventually, we'll have a Factor book, but it hasn't been started yet, in part because Factor's not at version 1.0 and in part because none of us have enough free time to write it.

Update: Factor documentation isn't as bad as I originally put it, so I changed this post a little.


Adam said...

I've found going through the cookbook in order and reviewing each reference at the bottom (even if I'm unsure of the concepts presented) to be the best way to learn. The documentation is there; in fact, I consider it to be top notch and much better than a PDF.

I can click the examples and get instant gratification whereas static documentation could feel overwhelming if the concept was unfamiliar. I hope the builtin docs continue to grow, after all, Factor is about breaking the mold.

Slava Pestov said...

Dan, you're being too negative. I don't think Factor is that hard to learn, the syntax is simple and the library is almost fully documented. Factor's online documentation (there's more than the cookbook) could easily total to 300 pages if formatted in PDF form.

Unknown said...

You're right. I made the tone more positive.

Michael Johnston said...

this post is cited in a "ten languages to learn" post on metafilter, so you might be about to get an upswing in traffic.

Many of the links in your article are currently 404 -- for example, the links to FAQ and cookbook.