Wednesday, July 7, 2010

Review: Create Your Own Freaking Awesome Programming Language

A while ago I blogged this ebook, as some highly relevant advertizing - it's got affiliate links - but I didn't have the time to actually sit down and read it. That's been at the back of my mind for ages, so last night I finally got around to it. I also watched the bonus screencast.



The book gives you open source Ruby code to play with as the foundation for a language, with the caveat that it's toy code, presented as teaching examples. It goes deep enough to explain the concepts in detail, and the book includes "Do It Yourself" challenges/exercises in extending the code, with answers at the back. Jeremy Ashkenas created CoffeeScript on this foundation, but soon replaced it with a more robust system once he'd gotten the language going; in a sense, he used the teaching examples code like a Rails newbie might use scaffolding. The video shows you how to use the other code package included, a more serious/realistic example in Java.

I had been worried, because I ran an ad about this on Reddit a few months ago, and a really rabid hater got into a furious flame war about how awful this book was and how much better SICP was, and blah blah blah. My intuition at the time was that the guy just had some anger issues; the book totally bears this out. His main point of contention was that the dummy code uses regular expressions in its lexer, and the book makes it abundantly clear that this is only for teaching purposes, giving plenty of pointers to deeper examples on how real lexers work. The author, Marc-André Cournoyer, built the languages Min and tinyrb before writing the book (as well as the Thin web server, which is less relevant but still pretty cool), and he provides a nice, comprehensive overview with plenty of informed links to deeper detail about related projects. This makes the book a great starting point if you're new to language design. No disrespect to SICP or the other classics, but this is a really nice, fun starting point.

I learned quite a bit, and I'm a pretty experienced programmer. Pretty much the only thing I knew about language design before this came from reading the source for Potion and Rubinius, making a tiny patch in Rubinius with a lot of help from Wilson Bilkovich, and building a ridiculous but fun Rails plugin with TreeTop, the Ruby parsing expression grammar. Although I don't have time to get into this today, I'm hoping to do a followup post where I explain a little bit about that; since that flamewar guy on Reddit made so defensive about the fact that How To Create Your Own Freaking Awesome Programming Language uses regular expressions in its lexer, I want to show how you'd step beyond that to something more sophisticated, and TreeTop makes an extremely logical next step. Maybe I'll even create my own ebook as a complement to this one. Being a so-called "rock star programmer" can make you a little insecure.

For now, though, I'm just going to say, I totally recommend this ebook, I enjoyed it, and it probably even made me a little better as a programmer. Definitely recommend you buy it. I don't want to jinx this project idea, but I've been hoping, ever since I first played with TreeTop, to use TreeTop to revamp my Rubotz project, which allows you to program Lego Mindstorms in Ruby. I guess that counts as language design experience also, but only as one hell of a stretch. It's mostly just a DSL plus ERb. If you install the gem (gem install rubotz) and look at the code or the documentation, you'll see how incredibly primitive it is.

I did get it to the point where it could program this robot to do what it's doing in the video:



But that's about it. What I've been hoping to do with TreeTop is actually implement it like a Logo for Mindstorms in Ruby, maybe renaming it Rogo in the process; Cournoyer's book makes it a lot easier to see that idea becoming reality. So yeah, once again, I'm going to say it rocks and you should buy it.