#52WeeksOfCode Week 25 – Factor

Week: 25

Language: Factor

IDE(s): Factor IDE

History (official):

(From the Factor Wiki)

“Factor (http://factorcode.org) is an expressive, fast and full-featured Concatenative language invented by Slava Pestov. The Factor implementation is released under a BSD license and runs on most common platforms.

Factor has been in development since September 2003, with a strong focus on practical programming all the way through; it began as a scripting language for a game. Factor has a small but friendly and vibrant community, and it is easy to learn.”

History (real):

Sayre’s Third Law of Politics states:

“Academic politics is the most vicious and bitter form of politics, because the stakes are so low.”

I was reminded of this while doing research on Factor. Apart from the project home page and a couple of YouTube videos, there is surprisingly little to find. On the way, I came across other languages that have small, but rabid fan bases.

Non-programmers don’t realize how many programming languages there are. The Internet being what it is, it didn’t take me long to find someone who wrote up a list.

There are hundreds, not even counting the dialects. In fact, they had to move the dialects of BASIC to another page. Don’t take my word for it. Go look.

Based on Internet discussions and mailing lists, it seems that the smaller the programmer community for a particular language, the more defensive the group.

Personally I don’t care what language you use. Like their spoken counterparts, programming languages are just a set of rules for getting thoughts out of your brain and into the world. If one works better for you than others, blessed be. Let a thousand flowers bloom, man.

Just…calm down, okay?

Discussion:

The first thing we need to do is unpack the official description of Factor because it is the opposite of ‘market-speak’. Marketers find the words that drill straight down into your id and bypass your higher brain functions to get their message across.

Programmers, on the other hand, don’t give a crap what you think. They know what all the words mean. What’s your problem?

First the easy word – expressive.

When someone refers to a programming language as ‘expressive’ they mean that the code is simple, direct and readable. For example, compare these two lines of code:

printf “Hello World!\n”  (Bash)
System.out.println(“Hello World!”); (Java)

They both do the same thing (print the phrase “Hello World!”) but the first has a simpler syntax and is more readable. In other words, it’s more expressive.

Nothing comes for free. The trade-off with expressive languages is that for more complex functionality you need to write more code. It’s easier to read but it’s more work.

What about ‘concatenative’?

That takes more explanation.

In most programming languages, commands have a similar syntax that goes

command plus argument plus parameters

Just as we expect an English language sentence to take the general form

subject plus verb plus object

A concatenative programming language takes a different approach. The code words are put in a stack (visualize the spring-loaded plate dispenser in a cafeteria) in reverse order. When the code runs, the top word is pulled off of the stack followed by the next and the next until the stack is empty and the program is done. (No code left on the stack.)

That means that if you want something to execute first you have to put it on the stack last. Printing “Hello World” in Factor looks like this:

Hello World in Factor

Hello, Factor!

The argument (“Hello World”) goes on the stack first, followed by the print command. This is sometimes referred to as Reverse Polish Notation or RPN. HP calculators use RPN (‘3 4 +’). Fans of RPN say it’s faster and more efficient. For one thing you don’t have to press the equals key on an RPN calculator.

Personally I have enough trouble thinking in the forward direction. But I’m very pragmatic and if a tool works for you but not for me…well, there are other tools for me.

For that reason I’m not going to do anything more complex than above with Factor because I’m afraid my brain will fall out of my head.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s