Learning Boo
As part of my commitment to The Pragmatic Programmer’s exhortation to learn a new language every year, I decided to tackle Boo. My interest has been piqued by the work Oren is doing in DSLs with Boo. Learning Boo seemed to be an important first step to getting to grips with that.
The first step was to get an environment in which I could write and compile Boo programs. Now this is possible using a decent text editor like Vim, and command line tools like booc and booish, but it is also possible to use an IDE for this. I downloaded SharpDevelop which has support for authoring, building and debugging Boo projects.
To give myself a starting point I have decided to work through the Boo Primer as a way of getting to know the language
One aspect that jumps out is why Boo is called ‘wrist-friendly’. There is a lot of effort expended on giving you less to type. Although it is a statically typed language, Boo does away with the need to declare types before use. Instead Boo infers the type. C# programmers will find this similar to te use of var, without the need for the var keyword.
greeting = "Hello World" //This declares a stringhouseNumber = 42 //This declares an integer
I’m always typing code of the form:
var myString = string.Format("Hello {0}", name);
in C#. Boo makes this a lot easier with string interning. I get to skip the string format statement, along with the seperation of placeholder and variable for
myString = "Hello ${name}"
The use of whitespace (Boo has a Python inspired syntax) to indicate a block is one of the early aspects of the language that strikes me. It makes for great natural language syntax, because it requires no block markers, but coming from a curly brace language “{}” like C# it takes a little for the fingers to get used to. I also seem to keep missing the colon off the end of the conditional
i = 5if i > 0: print "i is greater than 0" if (i < 10): print "i is less than 10" if (i==5): print "i equals 5"
One issue that hit me when working through the Boo Primer was that SharpDevelop disliked me trying to declare a list as follows:
L = List(range(5))
which gave me the error
ERROR: Generic types without all generic parameters defined cannot be instantiated.
Some digging on the Boo Programming Language mailing list established that Boo now has generics and it looks like the Boo interpreter in SharpDevelop uses that type over the non-generic type. Switching to use the generic collection instead, removed the error messages
L = List[of int](range(5))
The built in list initializer syntax seems to work in SharpDevelop though:
barfoo = ['abcdefghijkl']
I like the provision of initializer syntax for arrys, lists, and hashes within the language which provides for concise syntax
Overall I have spent an enjoyable half-a-day familiarizing myself with Boo’s syntax so far. One immediate advantage to learning Boo over say learning Ruby is that you are dealing with .NET libraries. So when you see Console.ReadKey(true) in a line of Boo code your existing knowledge tells you what it is doing. You are able to leverage existing framework skills and apply them to a new language. This speeds up the learning process, because having learnt the new syntax you can to put it to use fare more quickly.
Next time I’ll play with Boo’s methods and classes. Looking forward to it.