Portrait of Edd Dumbill, taken by Giles Turnbull

Subscribe to updates

Feed icon Atom or RSS

or get email updates

What I make

a conference management web application

XTech Conference
a European web technology conference

Dynamic .NET scripting with Boo

My disappointment with the recent IronPython release, along with encouragement from correspondent Michael Davies, has caused me to take a second look at Boo.

Boo is a Python-like scripting language for the ECMA CLR implementations such as .NET and Mono. The previous time I looked at Boo, it was rather less mature than it is now, and I admit to being reluctant to learn yet another minority programming language.

However, my recent investigations have removed that reluctance. I spent a few hours with Boo yesterday, and got very excited about what I saw. As the Boo web site is so excellent, I won't recite every single detail here, but I will note some thoughts I had about it. I also made some demos, which can be found at the end of this post.

The juicy details

I approached Boo pretty much from a mindset of being a Python and C# programmer. Boo may be reasonably characterised as Python with a little of the oddness removed, and some CLR-specific smarts added in.

Boo hits an interesting level between dynamic and static typing. Type inference means it's not necessary to declare the type of everything, yet a certain amount of strong typing brings error checking and predictable interaction with the rest of the CLR world. Additionally, the duck typing mechanism means you can bust out of the typed world, and rely on dynamic invocation without a lot of tiresome casting.

Boo also makes an effort to provide convenient syntax for common and CLR idiomatic operations (including attributes and P/Invoke), and a very exciting macro feature means you can add more with ease. This macro feature is used to provide syntax for object locking and assertions, among other things.

Most of the goodies you expect from Python are there, including generators. And some of the odd bits are left out. __init__ is now called constructor, and there's no need for the self first argument to object methods.

As functions are objects, asynchronous programming is a snap, and the closures make it easy to write small event handlers.

The demos

There were enough juicy details to make me want to find out more. So, I took the first five labs from the GTK# chapter in Mono: A Developer's Notebook and converted them to run in Boo. Here's the first example, a Gtk# "Hello World":

 import System
 import Gtk from "gtk-sharp"

 def Window_Delete (o, args as DeleteEventArgs):
         Gtk.Application.Quit ()

 def Button_Clicked (o, args as EventArgs):
         print "Hello, World!"

 Gtk.Application.Init ()
 w = Gtk.Window ("Gtk# Basics")
 b = Gtk.Button ("Hit me")

 w.DeleteEvent += Window_Delete
 b.Clicked += Button_Clicked

 w.Add (b)
 w.SetDefaultSize (200, 100)
 w.ShowAll ()
 Gtk.Application.Run ()

I've made these available for download: monodn-boo.tar.gz. They're based on some earlier work I did with IronPython, which illustrates that the jump from Python to Boo is small indeed.

In addition, I've made a screencast of a simple example of subclassing the Gtk.Button class, which you can view online if you have a Flash player. View Boo screencast.

Screenshot of Boo screencast

The community

Boo has a free software license. It openly encourages contribution of all kinds, and has an active release schedule.

This post illustrates nicely where Boo is placed with respect to IronPython, and indeed Mono.

blog comments powered by Disqus

You are reading the weblog of Edd Dumbill, writer, programmer, entrepreneur and free software advocate.
Copyright © 2000-2012 Edd Dumbill