Wednesday, December 21, 2011

A compile-time debugger?

Today, I've been thinking about templates: the second hardest bits of code to read in any given C++ program. (The very hardest, of course, would be the error messages that the templates generate.)

And, as is my tendency at such times, I've been thinking about how to do a better job in my programming language, Swym. All the cool languages are into type inference these days, and I'm keen for Swym to do it too - but I'm worried that global type inference (as opposed to local type inference like the "auto" keyword, which seems just fine) will lead inevitably to bad error messages.

In that sense, Haskell's type error messages and C++'s template error reports find themselves in a similar situation: there's a chain of types, and one end doesn't match the other. Somewhere along the chain, something went wrong, and we need to tell the user what happened.

C++ just spews out information about the whole chain, which gives you an unreadable a wall of error messages. Haskell's approach is to pick a place and tell you about it. All things considered, it picks fairly good places - but inevitably, there are times when it picks the wrong part of the program, and there's no way to get more information about what else it might have highlighted.

So I was thinking... well, really, we'd like the best of both worlds. Let the compiler tell me its best guess about where it went wrong, but somehow give me the option to explore further. A lot like a call stack in a debugger. "Wait, it thinks parameter x is an int? Where did it get that idea from?" (back out) "Oh, apparently f is returning an int now?" (drill into f)... etc.

This is a fascinating idea. Think about it - when your program crashes at runtime, you can attach your debugger and see exactly what was going on. Wouldn't it be nice to be able to explore the program state at compile time, in exactly the same way?

This supports some other ideas I've been toying with, too. In Lisp, you can write arbitrary code that runs at compile time. Why aren't there any tolerable languages that let me do that? (Sorry Lisp fans, I tried, but I really can't handle the parens). And if you're writing arbitrary code... well, if it crashes, what happens to the compile?

Clearly it's time to start writing a Swym debugger. One that can run at compile time AND run time. :-)

Monday, September 12, 2011

The Three Little Pigs (Reprise)

Last year I drew a little comic in pencil. It's secretly about programming.
I hadn't seen it for months, but this morning I found it among the stuff on my desk at work, and was charmed enough to colorize it and make it look slightly more professional.

Enjoy...

Monday, August 29, 2011

Wordsmith - a new puzzle RPG

I'm really stoked. I just made a first version of an awesome new game concept. I enclose a link to the current work-in-progress version below... but first I want to tell you about it.

Let me introduce the concept. Back in July, I was watching Word World with my daughter. It's a TV show that teaches children to read. Every object and character in the show is visibly constructed out of the letters in its name, and the plot typically involves breaking a word-object into its component letters, and using those letters to build something else.

And it slowly dawned on me... what an awesome game concept! Specifically, an RPG in which, when you kill a monster, you don't receive random loot or experience points... instead, the animal just breaks apart into the letters of its name, which you can collect.

Then, you'd use these letters to build things you need. Instead of "levelling up", or buying weapons from shops, you get more powerful in the game by simply typing yourself a more powerful weapon.

And when you're injured, heal yourself by creating food, or medicine. Just spell "stew" or "balm" or whatever you've got the letters for.

So I thought it over for a few days, following that same kind of logic. Honestly, I have never felt more strongly that a game was designing itself for me. Everything just seemed obvious: oh, obviously when you type "wings", you can put them on and fly around. Sure.

The name of the game was actually one of the last things to fall into place. I dithered about it for a long time... World of Wordcraft? (hard to pronounce). Spellsword (= spells-word... Too cute.) Super Letters RPG? (clumsy).

But I think I found the right name in the end. The game is simply called... Wordsmith.

Of course, the elephant in the room here is the DS game Scribblenauts. In a sense, Wordsmith could be considered very similar to Scribblenauts - you write what you need, and use it to solve puzzles.

However, although superficially similar, the restriction about having to collect letters before you use them makes a huge difference. Figuring out what needs to be done in Wordsmith is usually pretty straightforward. In other words, the challenge is not "what do I have to create?", but rather "how do I get the letters to create that?".

There's another big difference, too: the perspective. The characters in Scribblenauts inhabit a vertical 2D platform game world, all subject to the whims of the physics engine. Wordsmith, on the other hand, looks like a fairly traditional, retro, top-down tile-based RPG.

Hopefully, this means that one of the biggest problems cited in Scribblenauts reviews - the awkward controls - should be silently fixed.

Well, I'll let you decide. Link to the current version:
http://www.mediafire.com/?u79c62j9d8k9one
(That's a zip file containing a self-installing XNA executable. This only runs on PC at the moment, I'm afraid.)

Please give it a try, and leave me a comment - either here, or on Reddit. I'm really interested to know how hard the puzzles are, and which of the multiple solutions you've found.

The controls are pretty simple - Click in places to move, click on objects to interact with them. For example, click on a creature to attack it. Type a word (if you have enough letters), and press Enter to see the object you've created. Then click somewhere to place it, or right click to cancel.

If you're not sure what you're supposed to be doing - your first objective is to get off the little island.

One final note - I'm following a Minecraft style, very open development model here: releasing early and often. What you see here is really early - about three weeks of work. In particular, (unsurprisingly), three weeks has not really been enough time to create every word in the english language! This version understands roughly 300 words, and I'm adding more every day; so if a word you wanted to write was unsupported, please let me know! It will almost certainly be one of the next things I add.