Home arrow BrainDump arrow Page 2 - A Quick Tour of Boo

Program Structure and Variables - BrainDump

If you're looking for a portable .NET language and don't want to use a C-style syntax, you might want to take a look at Boo. Don't let the name spook you; if you're comfortable with Python, you'll feel right at home with Boo.

TABLE OF CONTENTS:
  1. A Quick Tour of Boo
  2. Program Structure and Variables
  3. Arrays and Collections
  4. Conditionals and Loops
  5. Functions and Types
By: Peyton McCullough
Rating: starstarstarstarstar / 4
August 06, 2007

print this article
SEARCH DEV SHED

TOOLS YOU CAN USE

advertisement

Unlike C# and Visual Basic.NET, Boo does not require a class to be declared with a static method as the program's entry point. A basic "Hello World" program can be written in a single line:

print "Hello World!"

Here, print is actually a macro. Boo users are free to develop their own macros as substitutes for repetitive code. Using the print macro is the same as calling the built-in print method:

print("Hello World!")

To access a namespace's contents without having to specify the namespace itself, import is used:

import System

Console.WriteLine("Hello World!")

Python programmers should take note: although import looks exactly the same as its Python equivalent, it isn't. Python's import allows the developer to find and access Python modules, while Boo's import merely provides a shortcut to a namespace's types, which could otherwise be accessed by specifying the namespace in front of the target type. Boo may look similar to Python, but their similarities don't extend too deep - watch out, Python users!

Now let's look at defining variables in Boo. Boo is a statically typed language, so the types of variables are determined at compile-time. Let's define some variables of various types:

name as string = "John Doe"

gender as char = char('m')

married as bool = false

age as int = 35

savings as double = 12345.67

Note how we explicitly assign each variable a type. In some instances, such as when we define but don't immediately initialize a variable, this is required. However, Boo can usually determine the type of a variable at compile-time just by looking at what's assigned to it:

name = "John Doe"

gender = char('m')

married = false

age = 35

savings = 12345.67

Although Boo is a statically typed language, there exists a special type called duck that provides support for duck typing. That is, you're free to use a variable of type duck as you see fit, without the compiler watching your back at compile-time:

x as duck

x = 4

x = "four"

x = false

The above code assigns an integer value to x, followed by a string and then false. Normally, this wouldn't compile, but with Boo's duck typing, it does. The above example is poor, however, since the same effect could be achieved by declaring x as type object. Consider this next example, then, where we use methods associated with specific types:

x as duck

x = 4

x = x.MinValue

x = "string"

x = x.Replace("s", "q")

Note, though, that Boo is still a statically typed language and that duck typing should not generally be used.



 
 
>>> More BrainDump Articles          >>> More By Peyton McCullough
 

blog comments powered by Disqus
escort Bursa Bursa escort Antalya eskort
   

BRAINDUMP ARTICLES

- Apple Founder Steve Jobs Dies
- Steve Jobs` Era at Apple Ends
- Google's Chrome Developer Tool Updated
- Google's Chrome 6 Browser Brings Speed to th...
- New Open Source Update Fedora 13 is Released...
- Install Linux with Knoppix
- iPad Developers Flock To SDK 3.2
- Managing a Linux Wireless Access Point
- Maintaining a Linux Wireless Access Point
- Securing a Linux Wireless Access Point
- Configuring a Linux Wireless Access Point
- Building a Linux Wireless Access Point
- Migrating Oracle to PostgreSQL with Enterpri...
- Demystifying SELinux on Kernel 2.6
- Yahoo and Microsoft Create Ad Partnership

Developer Shed Affiliates

 


Dev Shed Tutorial Topics: