Dynamic Languages at TechEd 2009

Los Angeles Convention Center Information Booth

Dynamic languages on .NET are picking up momentum at this year’s TechEd. Your typical TechEd attendee is a mainstream .NET developer, since this conference focuses on technologies that are shipping today (as opposed to futures conferences like the PDC). To speak more to this crowd, I focused on how they can make their existing .NET apps better by mixing in some end-user scripting.

My talk was DTL332 if you’re a TechEd attendee (not sure when/if the videos will open up to the general public). I showed how you can add Ruby and Python scripting to an existing app, and spent some time building some simple REPLs. Toward the end of the talk, I showed a more realistic scenario where I embed a REPL in an existing Open Source .NET application: Witty.

During the demo, I showed off a twist on the traditional REPL – one where the editor and the REPL are one and the same. To run code in this REPL, you select the code that you want to run, and the output appears immediately below the selection. Since the REPL is just an editor, you can just delete any output that you don’t want. History behaves just fine as well. Here’s a screenshot of the REPL in action:

image

There are a couple of other notable things in this REPL. First, it syntax colors the text that ran correctly. Second, it supports more than one .NET language – you can switch between Python and Ruby using %python and %ruby (although whether that’s a good idea is left to the reader). Third, all of its configuration is self-contained inside of a single DLL. This means that all you need to do to add scripting support for your app is add a reference to a single assembly. The assembly will write all user configuration files to well-known locations on disk (within your HOME directory) the first time it is run.

This idea of a REPL within an editor buffer isn’t new by any means. I’ve been spending some time hanging out with Mark Hamburg recently, and this is his favorite way of implementing a REPL (he’s done quite a few, including the embedded IDE that the Adobe Lightroom folks use to build Lightroom). He won me over on the idea, so I thought that I’d hack up an implementation for folks to experiment with.

I pushed the code up to Github as the repl-lib project, so feel free to fork, play with the code, and send me some feedback on the idea. Note that there’s a nice long tail of bugs in this REPL, so feel free to fix bugs and submit changes!

Here’s a screenshot of the Witty main window; notice the console button:

image

Here’s a sample console session:

image

The last line of code causes the Witty UI to display:

image

After poking around inside Witty, I think there is some work that needs to be done to make scripting truly a first-class citizen in the project. While some might look at this as bad news or an indictment of Witty, it really isn’t. Any project that isn’t designed for such an invasive feature will likely make lots of assumptions that make it hard to make that feature successful.

But the good news here is that if you use scripting as a end-user feature to drive your refactoring efforts, you will wind up with an app that is easy to script, but more importantly, is better designed. I argue that your design is better because it’s forces a clean separation of concerns in your code: especially your models and your views. This separation of concerns will make it easier to test your end-to-end scenarios and script your integration tests. This all adds up to better software for everyone.

I’ve made it pretty easy to add scripting support to your app. Grab the repl-lib project and spend a few minutes (that should be how much time it takes) to integrate scripting into your project. If you’re interested in how much work it took to integrate these changes into Witty, check out this diff; most of the stuff is VS-related, and ReplResources.xaml is no longer required in current builds of repl-lib:

Twitter Digg Delicious Stumbleupon Technorati Facebook Email

6 Responses to “Dynamic Languages at TechEd 2009”

  1. John,
    Looks pretty cool. Is an existing WinForms app a reasonable target for this feature? I have a large .net framework that could probably benefit from a console window.

  2. @Justin: Unfortunately, the syntax coloring stuff would be pretty hard to do in WinForms. However adding scripting support to a WinForms app should be just as straightforward. It shouldn’t be hard to fork the repl-lib project to build a WinForms version of it modulo the syntax coloring.

  3. Hi John.
    I was very impressed with your REPL project, and wanting to give it a try, I went to the Github site, thinking I would be able to download and build the project.
    Unfortunately, there doesn’t seem to be any way to do that.
    Is there some trick or magic inacantation you have to chant in order to download the entire project from “Github” ?

  4. @caddzooks: you’ll need to download a git client (just search for ‘git windows’). It’s an MSI-based installer and once you’re done, just click on the “clone” link on the project to copy and paste into a git-enabled command prompt.

  5. This looks very similar to http://lotrepls.appspot.com
    Very impressive

  6. Look like a fun weekend project for me. I am still fairly new to .net but have been wanting to get more involved.