Learning: Boo and DSL Part 1 – Getting Started

largeOne of the things that are said to help you become a better developer, is to learn a new language. Even  if you never use the language in your everyday working life, it will help you better understand the languages that you are working in, and maybe make you think out of the box.

So I have for some time wanted to get started with a new language. At the same time I have been very eager to look in to meta-programming and internal DSLs, and in that connection it seems that Boo is a very interesting language. Also Boo is a CLR language, which I would prefer for my first new language.

Therefore I have decided that I will learn Boo and when I am feeling confident in Boo, I will write an internal DSL for a not yet specified purpose – I am not quite sure yet what is possible to do, so I will wait a little with decisions on the DSL part.

What is Boo?

Boo is an Open Source, object oriented statically typed language for the CLR with a python inspired syntax, and was started in 2004 by Rodrigo B. de Oliveira. Its is currently in version 0.8.2, but even if its not yet in a version 1.0, it is actually a very stable and mature language that you could use in production.

The main philosophy in Boo is to let the compiler do a lot of work to help the language get a dynamic feel with automatic variable declaration, type inference and type casting. At the same time it leaves the option open to be more specific to get static compile time error checking.

Boo also offers some functional composition in that functions are first class citizens, and can be used as return values, as arguments, stored in variables or as objects. Boo has first class generators, that is constructs capable of producing more than one value when used in an iteration like a loop (“return a for a in apples if a.IsRipe”).

Boo also supports Duck Typing which lets you give up the type safety of static typing, and accepting any object that just has the appropriate methods and properties resolved at runtime. Boo also has extension methods and extension properties.

One of the most interesting features of Boo is the extensible compilation pipeline, that lets you tap in to the compilation and modify it or add features. You could add routines to check coding conventions, write out reports or transform code. Things that you would only be able to do in C# with a post compilation tool as PostSharp, and only to a certain extend. In Boo you could for instance automagically transform a given class to a singleton, just be adding an attribute like so:

[singleton] 
class MySingleton: 
     pass

PostSharp would not be able to do this, as the instance property would be created to late. This really opens up for a lot of possibilities and you are only limited by your understanding of the compiler inner workings and the feature set.

Boo has whitespace significance like python, but does have the option of turning on a “Whitespace Agnostic” mode where you can terminate an expression with “end”, which should limit the problems you could run into.

What Do I Need to Get Started?

Basically if you want to get to know Boo, all you need is the latest distribution of Boo. Included in the bin folder you will find the executable “Booish” which is a command line interpreter of Boo, that allows you to try out the language and syntax in an easy way.

image 

For real development we are going to need an IDE, and we have two options.

A lot of Boo developers swear to SharpDevelop, and if you get the latest version it comes with Boo and is ready for use out of the box. It has the advantage seen from the DSL development approach that it is a lot easier to add code completion and syntax highlighting, which in Visual Studio would require writing a lexer and a parser; In SharpDevelop you can do it with an XML file.

But on the other hand Visual Studio is a nice mature IDE, and with BooLangStudio you get Boo and integration to the Visual Studio environment. People have complained that the project is instable and only an alpha release, but so far I haven’t experienced any problems

For now I will stick with Visual Studio as force of habit, but I might change my mind when I get to the DSL part of this endeavor.

Now that we have seen what Boo is, and have the prerequisites in place, part 2 of the series will focus on getting to know the syntax. Please subscribe to the feed.

Related Links:

Friday, October 03, 2008 7:24:45 PM (Romance Standard Time, UTC+01:00)
Looking forward to part 2...
Erbs
Thursday, October 16, 2008 9:26:16 PM (Romance Standard Time, UTC+01:00)
Also looking forward to your 2nd part.
Friday, October 17, 2008 8:32:22 AM (Romance Standard Time, UTC+01:00)
I am working on part 2, so it won't be long until its out :)
Sunday, October 19, 2008 10:38:48 PM (Romance Standard Time, UTC+01:00)
Part two is up: http://is.gd/4nmv
All comments require the approval of the site owner before being displayed.
OpenID
Please login with either your OpenID above, or your details below.
Name
E-mail
(will show your gravatar icon)
Home page

Comment (HTML not allowed)  

Enter the code shown (prevents robots):

Live Comment Preview