BrainDump
  Home arrow BrainDump arrow Page 2 - A Quick Tour of Boo
The Best Selling PC Migration Utility.
Dev Shed Forums 
Administration  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Forums Sitemap 
IBM® developerWorks 
Dedicated Servers 
E-Commerce Hosting 
Linux Web Hosting 
Managed Hosting 
Small Business Hosting 
Download TestComplete 
VPS Hosting 
Weekly Newsletter

 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
BRAINDUMP

A Quick Tour of Boo
By: Peyton McCullough
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 2
    2007-08-06

    Table of Contents:
  • A Quick Tour of Boo
  • Program Structure and Variables
  • Arrays and Collections
  • Conditionals and Loops
  • Functions and Types

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
     
    ADVERTISEMENT

    The Web Buyer's Guide is your best source for white papers on a wide range of IT products and services. This Week's Featured White Papers: Help Simplify Virtualization by IBM

    A Quick Tour of Boo - Program Structure and Variables
    (Page 2 of 5 )

    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


       · Hello, all,I've always found Python's syntax particularly pleasing, but, at the...
     

       

    BRAINDUMP ARTICLES

    - Outsourcing: the Hoopla, the Reality
    - MySQL Plays in the Sun
    - All About SQL Functions
    - SQL: Functioning in the Real World
    - More Advanced SQL Statements
    - Beginning SQL the SEQUEL: Working with Advan...
    - Beginning SQL
    - A Look at the VI Editor
    - A Quick Tour of Boo
    - Book Review: Open Source Licensing
    - PGP and GPG: Email for the Practical Parano...
    - Microsoft Continues War on Open Source
    - Secure Remote Desktop Sharing with VNC on Li...
    - A Look at Google Project Hosting
    - What we can Learn from Two Linux vs. Microso...




    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway