Skip to content

Instantly share code, notes, and snippets.

@drslump
Created May 11, 2013 18:03
Show Gist options
  • Save drslump/5560839 to your computer and use it in GitHub Desktop.
Save drslump/5560839 to your computer and use it in GitHub Desktop.

Boo Succinctly Revealed (second edition)

By Rolly Noel, Copyright 2013

THIS DOCUMENT DOESN'T COVER ANYTHING THAT NEEDS AN IMPORT (except for System) FIRST DEFINITION OF BOO LANGUAGE ITEMS IS IN BOLD IN THIS DOCUMENT, LINES OF DESCRIPTION (NOT CODE) START WITH "#", AND ARE CONTINUED WITH " "

print'ACompleteBooprogram'  # O/Ps(outputs)'ACompleteBooprogram'

Order of parts (all parts optional): """module docstring""", namespace, imports, enums/structures/classes/functions, main code, assembly attributes

If you have a "def Main (argv as (string)):", execution begins therein, else it starts at unenclosed lines of code (not in a class, function, structure, ...)

Definitions

# Comments to end of line (also //)
/* Comments (/* can be nested */) (can be multi-line) */
""" docstring comments, on the line below what's being documented, similarly indented """ 
# Multiple Boo statements on the same line are separated by ";" (can't do within a comment) 
# To continue a Boo statement anywhere on the next line, end the continued line with a \

namespace ProjectName  # Set of objects contained herein will be uniquely prefixed with ProjectName (must be at top of file)
import System.Console  # Makes all members of the namespace available. Can say ReadLine() instead of System.Console.ReadLine()
import System as S     # can say S.Console.ReadLine()
import Gtk from "gtk-sharp" # Used when assembly name differs from namespace name

# In the SharpDevelop IDE (#D (available for Windows from http://www.icsharpcode.net/OpenSource/SD/Download/ )),
# typing import then a space, lists all the namespaces you can import (with supplementary info, if available,
# for the highlighted entry)
# #D also does this for Boo keywords. It will anticipate you when you start typing something it recognizes
# #D also lists your options (along with their prototypes & usage info) when you type a "." or "(" immediately 
# following the name of built-in or user defined types - tab to enter the highlighted item

# Variable names begin with an alpha character or an _, contain alphanumerics & _, are case sensitive, & can't be 
# reserved words 
# Value type variables contain the value itself
# Reference type variables (they default to null) point to an object (a string, or ...)
x as duck  # Compiler will not do type checking for uses of this variable. Slows down code execution but useful 
           # with external components such as COM objects, or for prototyping

ain = 1             # Boo does type inference to determine that ain is a value type int (integer) 
ain = int.MaxValue  # is int ( == 2,147,483,647)
alo = 1_000_000L    # is a value type long;
alo = 1e+2L         # is long (== 100)
ain2 as int         # (32 bits) or sbyte (8 bits), or short (16 bits), or long (64 bits) integers. "as" declares a 
                    # variable's type, defaults to 0
inun as uint        # or byte, ushort, or ulong unsigned integers
ain3 as int?        # defaults to and can be assigned null
print(ain = int.Parse("2"))  # O/Ps 2
ain = int.Parse("mouse")     # causes a System.FormatException
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment