Inform 7: Natural-Language Programming Lives
When most programmers think of natural-language programming, they usually think of Applescript – an ambitious yet doomed-to-failure language with English-like syntax that Apple developed in order to automate OS scripting tasks. Frankly, Applescript in its current incarnation is pretty dismal – any reasonably complex script is positively overflowing with
tells, reminiscent of Ruby’s slower, dumber cousin. (Incidentally, 99% of the pain of Applescript can be removed with Ruby or Python bridges.)
These painful memories, combined with other influential condemnations, will probably lead many programmers to shun Inform 7 and its mission to be “built by writing natural English-language sentences.” However, if you will wait a moment, I will show you the masterful elegance with which Inform 7 mixes modern programming paradigms and the English language.
For those of you unfamiliar with Inform, it’s a system for writing text adventures – well-known examples include Adventure, Zork, and the famously difficult adaptation of The Hitchhiker’s Guide to the Galaxy. Inform was created in 1993; in its first six versions, games were written in a procedural programming language with a syntax looking like a cross between Perl and Applescript. Now, however, games are written entirely in English and then translated with the I7 compiler.
The following is not meant to be a full-fledged I7 tutorial; the official site does that far better than I ever could. This is simply a demonstration of how I7 manages to express complex programming concepts entirely in English.
Let’s look at how we instantiate objects:
The hall is a room.
There, that’s it. Same thing as
hall = Room.new() or what have you. Its name “The hall” will be displayed correctly when the player enters, leaves or observes it.
What about making new types of objects?
A bathroom is a kind of room.
Ooh! Subclassing! Inheritance! And it does it concisely and readably, and without using any terms such as “public”, “class”, or “extends”!
Rooms can be clean, dirty, or filthy.
Bathrooms are usually dirty.
Dynamic programming! We can edit the properties of built-in objects, a lá Smalltalk and Ruby!
The oil drum is a thing. The oil drum is enterable.
“Enterable” in this case is like a Ruby mixin – it allows the player to get in and out of the oil drum and provides it with all the attributes that entails.
Color is a kind of value. The colors are blue, red and green.
Instead of touching the button: change the color of the button to red.
Note the definition of new enumerable types, subclassing methods (in this case, ‘touching’) on existing objects, and changing attribute values.
These are complicated concepts and the fact that the Inform 7 designers have made them expressible in concise English is, frankly, astounding.
Go check it out; write the Dramatic Lovecraftian Adventure you’ve had brewing up in your mind for the past few years. It’ll be fun.
Entry filed under: code. Tags: .