1. Starting out¶
1.1. Overview¶
Boo is an amazing language that combines the syntactic sugar of Python, the features of Ruby, and the speed and safety of C#.
Like C#, Boo is a statically-typed language, which means that types are important. This adds a degree of safety that Python and other dynamically-typed languages do not currently provide.
It fakes being a dynamically-typed language by inference. This makes it seem much like Python’s simple and programmer-friendly syntax.
1.1.1. CSharp¶
int i = 0;
MyClass m = new MyClass();
1.1.2. Boo¶
i = 0
m = MyClass()
1.2. Hello, World!¶
A Hello, World! program is very simple in Boo.
Don’t worry if you don’t understand it, I’ll go through it one step at a time.
1.2.1. helloworld.boo¶
print "Hello, World!"
// OR
print("Hello, World!")
1.2.2. Output¶
Hello, World!
Hello, World!
- First, you must compile the helloworld.boo file to an executable.
- Open up a new command line
cd
into the directory where you placed thehelloworld.boo
file.booc helloworld.boo
(this assumes that Boo is installed and in your system path)helloworld.exe
- If you are using Mono,
mono helloworld.exe
- Using the print macro, it prints the string “Hello, World!” to the screen. OR
- Using the print function, it prints the string “Hello, World!” to the screen.
Now these both in the end, do the same thing. They both call
System.Console.WriteLine("Hello, World")
from the .NET Standard
Library.
And it’s that simple.
Note
Using the macro version print "Hello, World!"
is recommended.
1.3. Comparing code between Boo, C#, and VB.NET¶
Now you may be wondering how Boo could be as fast as C# or VB.NET.
Using their Hello World programs, I’ll show you.
1.3.1. Boo¶
print "Hello World!"
// Output: Hello World!
1.3.2. CSharp¶
public class Hello
{
public static void Main()
{
System.Console.WriteLine("Hello World!");
}
}
// Output: Hello World!
1.3.3. VB.NET¶
Public Class Hello
Public Shared Sub Main()
System.Console.WriteLine("Hello World!")
End Sub
End Class
' Output: Hello World!
All three have the same end result and all three are run in the .NET Framework.
All three are first translated into MSIL, then into executable files.
If you were to take the executables created by their compilers, and disassemble them with ildasm.exe, you would see a very similar end result, which means that the executables themselves are very similar, so the speed between C# and Boo is practically the same, it just takes less time to write the Boo code.
1.4. Booish¶
booish
is a command line utility that provides a realtime
environment to code boo in. It is great for testing purposes, and I
recommend following along for the next few pages by trying out a few
things in booish
. You can invoke it by loading up a terminal, then
typing booish (this assumes that Boo is installed and in your system
path), or by double-clicking the booish icon. In booish
, you can up
arrow to re-enter (with editing) a previously entered line. Here’s what
booish
will look like:
1.4.1. Booish¶
>>> print "Hello, World!"
Hello, World!
1.5. Exercises¶
- Write a Boo program that prints
Hello, World!
, then printsGoodbye, World!
- Play around with
booish
- Advanced: Compile the Hello, World! programs for Boo (using
booc
) and C# (usingcsc
ormcs
), runildasm
on each of them and compare the result.