On the subject of IF, programming language geeks should all check out Inform 7 - Graham Nelson's programming tool for creating text-based games that run on the Infocom Z-machine (and other related formats). There are a large number of truly astonishing things about the language, compiler and development environment. For example:
- the text editor supports elastic tabstops
- its documentation is embedded right into the development environment, beautifully complete and well written, and filled with great little examples
- compilation error messages are delightfuly detailed, specific, and useful. But if the same error is repeated, the compiler usually tells you "again, this doesn't make sense" rather than hitting you with a wall of repetition.
- many of the language's tools are for creating new language syntaxes for you to write your program with, rather than for the player to use in the game. You can create your own nouns, verbs, adjectives and prepositions to use in your descriptions of the world.
- Its relationships system is very powerful, and includes first-class support for performing operations on the graphs defined by relationships. For example, rooms are related by adjacency, and you can enquire what room is 'the next step via the adjacency relation' from one room towards another to have characters navigate towards a goal - but equally you can create our own relationships and perform similar operations on those.
- in spite of the syntactic restrictions of trying to 'read like English', it surfaces surprisingly rich functional and generics syntaxes; there's a real, grown-up programming language in there.
It is definitely worth a weekend play, if you're looking for a completely different kind of language for a change.
To give an example of the language. Let's say you want a room where the player is eaten by a grue if they linger too long:
A room has a number called grue counter. The grue counter of a room is usually 0.
A room can be grue infested. A room is usually not grue infested.
Every turn while the player is in a grue infested room:
Increase the grue counter of the location by one.
The dungeon is a room. "You stand in a basic medieval dungeon." The dungeon is grue infested.
The first time the player enters the dungeon:
try looking;
say "It is dark. You are likely to be eaten by a grue."
Grue lunch is a scene. Grue lunch begins when the grue counter of the dungeon is greater than 10.
When grue lunch begins:
say "A large, smelly, foul tempered creature resembling a cross between a troll and an orc lumbers out from one of the open passageways. It sniffs the air, catches your scent, and looses a mighty roar! Before you are able to do anything else, it quickly lunges forward, chomping down on your head with a sickening [bold type]*crunch*" ;
end the story saying "You have been eaten by a grue."
This is the actual syntax, and it is surprisingly readable. Getting used to what the parser wants you to say can be tricky sometimes - just because the language is english like doesn't mean you can write your code in completely free-form english, but it's damn close!
Once you've gotten your head around a few of the foibles, it's a lot less like writing a program and a lot more like just writing a book. In any case, agreed heartily with parent, it's a lot of fun to play around with!
Emily Short's Inform implementation of extensible "computers" makes for a good read. (Note that anything in [square brackets] is a comment and not interpreted, except when between double quotes, where it's like string interpolation.)
Michael Callaghan's fixed-point math extension is less prose-like but worth a peek. It shows how some of the more traditional programming language features can be translated to Inform (eg. explicit loops with ranges as repeat with X running from 1 to 7).
Wow! I was trying to create something like this for knowledge representation, last week. Ended up reading some of the CLIPS manual, then deciding to roll my own, as usual.
Wow. Programming is so faddish! I know this, but it's still surprising. What other problems that we're struggling with have been basically solved, in some currently unpopular corner?
Yes, sadly; and this is because programming languages, like spoken languages, live and die by their community. And it's harder to cross-pollinate programming languages since all changes must be backwards-compatible with existing source text. Language interop is usually terrible. You can't easily bring just a bit of Inform into an application.
This is very slowly improving with the popularity of compile-to-llvm, compile-to-CLR, and compile-to-JS as intermediate targets.
The other factor in faddishness is ahistoricity; the most energetic and community-orientated people are young, but interested in building their own new wheels while overthrowing the old wheel order.
> The other factor in faddishness is ahistoricity; the most energetic and community-orientated people are young, but interested in building their own new wheels while overthrowing the old wheel order.
It's easier to write code for a small system than to read code for a large system.
I'm not sure I appreciate the syntax. Most hackers have a thing for brevity: a subconcious craving for the code as terse as possible without sacrificing readability (this, of course, is problematic in very many ways...). I would probably like using something like Racket's Scribble better: on the surface it's just as human-readable, but you're only one '@' sign away from a real Lisp beneath.
It can be hard to get programmers to take a second look at Inform 7, because the initial perception (mine as well) is always "Oh, it's a DSL with an English veneer on top". But because the domain is English itself, the fact that the programming syntax is (a very small subset of) the English language is essential to the way the system works. It means for example that you can type sentences in the form that the player will see them and the system will understand the semantics behind them, all at once.
It takes some time working with it to realize all the cool things it does for you. It's definitely worth spending a little time with.
I wanna expand on this, in relation to Hadean Lands.
I wrote HL in Inform 7. Could I have written the game in a more traditional IF language, such as Inform 6? (I6 is C-like.) Answer: yes, but it would have been a bunch more work and a lot more frustrating and painful.
The English-ish syntax of I7 takes some getting used to. Yes, you have to free yourself of any attachment to brevity. I7 code is verbose. The hidden benefit is that it's very easy to skim through and re-read. All code is write-once-read-many-times, right? You may be comfortable with "gruecount++", but "increase the grue counter of the location by one" is just as intelligible (and more so for people who didn't grow up on C).
The real strength, for me at least, is I7's rule dispatch model. Big swatches of HL's code look like this (yes, an exact quote):
Ritual-processing rule for rit-speaking anaphylaxis-word when at RSChymicStart and the bound of rstate is the retort and the reservoir comprises grey-acid-subst and the retort contains exactly perfect-diamond: [...]
I've got hundreds of these little code snippets, and I trust the compiler to stitch them together into a working state machine. If this were I6, I'd have to write giant functions and collect these snippets together -- in the right order, etc. If this were an OO language, I'd go crazy deciding what object each snippet is a method of. I7 just takes the above and runs. (Okay, I have to worry about the rule ordering a little, but I7 mostly gets it right.)
(You can see that I've forced some brevity in, by careful definition of the words "at" and "comprises" and "contains exactly". I like hyphenated-symbols too. Those are personal style choices.)
Why can we not write applications this way? Are there any languages that allow you to use more natural language to describe your application? I've heard of Behavior-driven development, is this what it is?
There are a large number of truly astonishing things about the language, compiler and development environment. For example:
- the text editor supports elastic tabstops
- the text editor supports elastic tabstops
- its documentation is embedded right into the development environment, beautifully complete and well written, and filled with great little examples
- compilation error messages are delightfuly detailed, specific, and useful. But if the same error is repeated, the compiler usually tells you "again, this doesn't make sense" rather than hitting you with a wall of repetition.
- many of the language's tools are for creating new language syntaxes for you to write your program with, rather than for the player to use in the game. You can create your own nouns, verbs, adjectives and prepositions to use in your descriptions of the world.
- Its relationships system is very powerful, and includes first-class support for performing operations on the graphs defined by relationships. For example, rooms are related by adjacency, and you can enquire what room is 'the next step via the adjacency relation' from one room towards another to have characters navigate towards a goal - but equally you can create our own relationships and perform similar operations on those.
- in spite of the syntactic restrictions of trying to 'read like English', it surfaces surprisingly rich functional and generics syntaxes; there's a real, grown-up programming language in there.
It is definitely worth a weekend play, if you're looking for a completely different kind of language for a change.