This page is likely outdated (last edited on 19 Oct 2005). Visit the new documentation for updated content.

DB4BOO

Table of contents

Introduction

Doing some research to build new Mono demos for tradeshows, I decided to research db4o, an open source object database that works with Mono as well as Boo, an simple object oriented scripting language for the CLR. Boo’s simple syntax is especially attractive to me as I prototype or build little applications. Also, the Boo shell in Monodevelop (or in a Terminal, using booish) makes it very easy to try things out quickly.

Through this short tutorial, we’ll use a little bit of Boo to create a simplistic little application to test out and explore db4o’s object persistence features.

Boo

Boo is a very interesting dynamic scripting language compatible with Mono and the Microsoft .NET CLR. Its simple syntax make it idea for prototyping quickly and much more. Boo is now packaged with Mono and included as an interactive shell and project wizards within Monodevelop.

While Boo is statically typed, it’s Type Inference feature make it so that you never have to declare the type of “newly declared variables and fields, properties, arrays, for statement variables, overriden methods, method return types and generators”.

I’d like to thank Peter Johanson (latexer), for helping me getting acquainted with Boo)

Let’s Boo first

A very simple demo of Boo I like to give is the following:

  1. Start Monodevelop
  2. Make sure the boo shell is displayed (View-> Boo Shell and then some dragging of the boo shell title bar to the main document dock area)
  3. in the boo shell, type the following (line by line, don’t copy/paste, so that you get the full effect. No need to type the commments):
import Gtk from "gtk-sharp"                                                        // (a)
 
myWindow = Window ("Mono")                                                         // (b)
myWindow.Show()                                                                    // (c)
myWindow.Title = "Boo"                                                             // (d)
 
myButton = Button ("Click me")                                                     // (e)
myWindow.Add(myButton)                                                             // (f)
myButton.Show()                                                                    // (g)
 
myButton.Clicked += { myButton.Label += "-" }                                      // (h)

What happened ?

a: We’re declaring that we’ll be using the Gtk assembly which comes from a pkginfo package identified as ‘gtk-sharp’

b: Here, I create a new Gtk.Window object. Notice the lack of ‘new’ keyword as well as the infered type

c: I ask myWindow to display itself which it does

d: Magic begins, I change the Title for the window, interactively. Go look at the window, you’ll see the title had changed

e: I create a Gtk.Button

f: Which I add to the myWindow window

g: I then ask MyButton to display itself. Go look at the window again and click on the button. It doesn’t do anything yet.

h: I associate a closure (similar to an anonymous method) to the Clicked event for myButton. Each time you click on it, the method will add a ‘-‘ to the button Label. Try it !

Now that you have an idea of what Boo looks like, let’s move forward.

Pilot class

    public class Pilot:
 
        public _name as string
        public _points as int
 
        public def constructor (name as string, points as int):
            _name = name
            _points = points
 
        public Name as string:
            get:
                return _name
 
        public Points as int:
            get:
                return _points
 
        public def  AddPoints(points as int):
 
            _points += points
 
        public def ToString():
 
            /* I could be using
               return _name + "/" + _points
               but latexer mentionned that boo's string interpolation is best : */
            return "${_name}/${_points}"