Boo Presentation 2008

I am making available my boo presentation source code and slide deck in case anyone would like to take a look at it. It has many examples of the various features of boo. The way the presentation starts out is by quickly running through the boo slides and answering any preliminary questions as they come up then by going project by project down the list in the solution.

I gave this presentation at the Fall 2008 Twin Cities Code Camp and I will be giving it again November 11th at the Twin Cities Languages User Group.
Some of the various examples provided by this presentation include:
1.       Hello World!
2.       Strong Typing
3.       Type Inference
4.       Auto Casting
5.       Indentation for Blocks
6.       Object Oriented, uses the CTS
7.       Syntax features
a.       Array, List and Hash literals
b.      Slicing
c.       Comprehensions (generators)
d.      Time
e.      Commenting
8.       Regular expressions
9.       Functional
10.   Closures
a.       Lambdas
b.      Anonymous methods
c.       Currying
11.   Duck Typing and IQuackFu
12.   Extensibility
a.       Macros
b.      Attribute Macros
13.   Internal DSLs
a.       Specter
14.   Compiler Pipline

Specter – A Specification DSL for Boo

Specification frameworks are a great way to enable a smooth approach to test driven development. A nice and simple specification framework called Specter has been created specifically for Boo, which includes a simple and elegant internal Specification DSL. If you’re curious to learn about specification frameworks, Boo or DSLs you should check out Specter for an elegant and useful example of all 3.

Here is a really great video of the step-by-step process:

Space Ship Operator

This is a pretty neat idea:

This gist of the post is that instead of overloading <, <=, ==, !=, >= and > operators you can just overload an <=> operator which will behave similar to what you would do to implement IComparable and the compiler will take care of the rest.

Of course this isn’t implemented in C# or VB currently but it is in Boo!

Boo Shirts

I think I am going to order some boo shirts, I want one for myself and I’ll probably give a few away at my upcoming boo presentations so I’ll order in bulk. Here’s the shirt:

If anyone wants one let me know because I can get them a little bit cheaper since there is a discount for bulk ordering. Send me an email directly with the following information:

  • Your name
  • Your mailing address
  • Shirt size

We’ll work out payments be it through pay pal or some-other means. The price of the shirt will be exactly what I paid to have them made plus shipping. The more people who want one the cheaper they will be. If you’re willing to pay for international shipping than I’m willing to send it!

[EDIT] The cafe press widget I was linking to was broken so I just swapped it out with a picture of the actual shirt. See representing boo for more. I can still order more if you want.

Creating Attribute Macros in Boo


Here is a simple example of writing an Attribute Macro in boo. I have created a macro that you can use to ensure that parameters are not null and raise a ArgumentNullException if they are. The interesting thing to note about this is that if you were to do this in C# you would need to use a factory method to inject these methods as aspects at runtime. With Boo macros you are actually changing the code at build time, which has both positive runtime performance implications and positive architectural changes since you do not need a factory method.
Here is an example of how you might use such an attribute:
namespace MacroExample
import System
import Macros
class Example:
       def DoSomething(example as string):
              print example.ToUpper()
e = Example()
print “Press any key to continue . . . “
I have declared a class called Example with a single method DoSomething. On that method we have attached an Attribute called Ensure. If you were using standard Aspect Oriented Programming techniques you would need some custom code to inspect this attribute at runtime and build a dynamic type and method to wrap the logic of the ensure attribute.
In Boo, since my EnsureAttribute inherits from AbstractMacroAttribute the logic of the Attribute will actually be run at build time, not runtime. Note the parameter in the constructor, the ‘example’. There are no quotes around this because it is not a string. It actually comes into the constructor as a ReferenceExpression which I can use to match to the methods parameters.
Here is the ensure Attribute code:
namespace Macros
import System
import Boo.Lang.Compiler.Ast
class EnsureAttribute(Boo.Lang.Compiler.AbstractAstAttribute):
       private _parameter as ReferenceExpression
       public Parameter as ReferenceExpression:
                     return _parameter
       def constructor(parameter as ReferenceExpression):
              _parameter = parameter
       override def Apply(node as Node):
        target = cast(Boo.Lang.Compiler.Ast.Method, node)
        parameter as ParameterDeclaration
        for p in target.Parameters:
              if p.Name == _parameter.Name:
                     parameter = p
        code = [|
              if $(parameter) is null:
                     raise ArgumentNullException($(parameter.Name))
        target.Body.Insert(0, code)
One of the most amazing parts about constructing macros in Boo is the built in code templating features. If you notice towards the bottom of the example where we are assigning to the variable ‘code’ there is a special block wrapped in [| … |]. This is a special type of operator that tells Boo that whatever is inside of this block is to be parsed and returned as an AST (abstract syntax tree) node. This is a helper for replacing reliance upon manually constructing Boo CodeDom objects. You can see on the following line that this compiled code is being inserted into the body of the method this attribute has been applied to.
It is important to note that while we are affecting the body of the method that method knows about the class it is attached to and that class knows about all other classes in the assembly and so on. This is the difference in power between Boo macros and C++ macros.