Microsoft Small Basic

From Wikipedia, the free encyclopedia
Microsoft Small Basic

Small Basic running on Windows 7
Original author(s) Microsoft DevLabs
Developer(s) Microsoft DevLabs
Initial release 2008
Stable release Microsoft Small Basic v1.0 / 12th July 2011
Written in Microsoft .Net 3.5
Operating system Microsoft Windows
Platform Microsoft Windows
Type Integrated development environment
Website http://www.smallbasic.com/

Microsoft Small Basic is a simplified variant of the BASIC programming language introduced by Microsoft in October 2008.[1] With a bare minimum of concepts, Microsoft accredits this as an easy programming language for beginners to grasp. The language itself has only 14 keywords,[2] and the environment is beginner-friendly, with a straightforward interface. Small Basic Version 1.0 (12 June 2011)[3] was released with an updated Microsoft MSDN website that included a full teacher curriculum,[4] a Getting Started Guide,[5] and several new Small Basic e-books for beginners through a partnership with ComputerScienceForKids.com. The published Small Basic guides include a complete Developer's Reference Guide, a Beginning Small Basic tutorial, and a republished classic programming book by David H. Ahl.[6]

Microsoft Small Basic was designed by Microsoft DevLabs and released as a Technology Preview[7] in October 2008. Its intended audience is anyone looking to begin programming, including children and beginner adults as well. Small Basic exists to help students as young as age eight[8] learn the foundations of computer programming and then graduate to Visual Basic using Visual Studio Express, where they can continue to build on the foundation by learning Visual C#, VB.NET, and Visual C++.[9]

Language

The traditional 'Hello World' is

TextWindow.Write("Hello World")

or

TextWindow.WriteLine("Hello World")

The first example just writes 'Hello World', but the second example writes 'Hello World' then enters a new line below it.

The language itself is Turing complete and supports concepts like conditional branching and loops. Variables are typeless and dynamic, and there are no scoping rules. The language supports subroutines and the runtime uses them for event handling purposes.

Conditional Branching

TextWindow.Write("Enter the temperature today (in F): ")
temp = TextWindow.ReadNumber()
If temp > 100 Then
  TextWindow.WriteLine("It is pretty hot.")
ElseIf temp > 70 Then
  TextWindow.WriteLine("It is pretty nice.")
ElseIf temp > 50 Then
  TextWindow.WriteLine("Don't forget your coat.")
Else
  TextWindow.WriteLine("Stay home.")
EndIf

Looping

TextWindow.WriteLine("Multiplication Tables")
table = 4
For i = 1 to 10
  TextWindow.WriteLine(i + " x " + table + " = " + table * i)
EndFor

Data Types

The language supports basic implementation of data types, like strings, integers and decimals.

TextWindow.WriteLine("Enter your name:")
name = TextWindow.Read()
TextWindow.Write("Enter your age: ")
age = TextWindow.ReadNumber()
TextWindow.WriteLine("Hello " + name + "!")
TextWindow.WriteLine("In 5 years you will be " + ( age + 5 ) + " years old!")

In the above example, the TextWindow library gets user input twice- Read() for a text value and ReadNumber() to get a number. ReadNumber also makes the language more user-friendly by preventing invalid numerical values, such as "asdf", from being typed.

Advanced programmers should note that Small Basic stores all values- including Arrays- as formatted strings. Hence, strings containing numerical data can be manipulated as numbers in various contexts, and vice versa:

TextWindow.WriteLine(Math.log("100")) 'Prints 2
TextWindow.WriteLine("100" + "3000") ' Prints 3100
TextWindow.WriteLine("Windows " + 8) ' Prints Windows 8
TextWindow.WriteLine(Text.GetLength(1023.42)) ' Prints 7 (length of decimal representation including decimal point)

(The second example can be overcome by using Text.Append().)

Libraries

Standard Library

Small Basic ships with a standard library that is fairly extensive, considering the language is intended to be used to learn, rather than to develop production-grade applications. This standard library has the basic classes you would expect from a library, such as the ability to create and read files, as well as providing a "Turtle" class, similar to Logo, and the ability to retrieve images from Flickr.

As this is a language for learning, the process of retrieving images from Flickr has been vastly simplified, as demonstrated in the Small Basic code below.

For i = 1 To 10
  pic = Flickr.GetRandomPicture("mountains")
  Desktop.SetWallPaper(pic)
  Program.Delay(10000)
EndFor

Third-party Libraries

Small Basic also allows the use of libraries created by a third party. These libraries must be written in a CLR-compatible language, and the classes that are intended for use with Small Basic must be static, and must be flagged with an attribute showing that Small Basic is to use them. Functions, properties, and variables within these classes must return a "Primitive" structure, which is contained within the Small Basic standard library.

An example of a class to be used in Small Basic is provided below, written in C#.

[SmallBasicType]
public static class ExampleSBClass
{
  public static Primitive Add(Primitive A, Primitive B)
  {
    return A + B;
  }
 
  public static Primitive SomeProperty { get; set; }
 
  public static Primitive Pi
  {
    get
    {
      return (Primitive)3.14159;
    }
  }
}

Turtle

Microsoft Small Basic ships with a Turtle graphics library that borrows the idea from Logo. For example, you can make the turtle draw a square by simply saying:

For i = 1 to 4
  Turtle.Move(100)
  Turtle.TurnRight()
EndFor

Testing

The first trials were successfully done with several middle school children, most of them children of workers at Microsoft. Small Basic was also successfully tested using a hands-on lab approach to a group of 25 high school girls.[10]

See also

Related Microsoft technologies:

Related languages:

References

  1. Small Basic Blog: Hello World
  2. What are the 14 keywords of Small Basic?
  3. Small Basic 1.0 is here!
  4. Small Basic Curriculum
  5. Small Basic Getting Started Guide
  6. Small Basic E-Books
  7. About DevLabs
  8. Small Basic - Elementary and Middle School Student Testimonials
  9. Graduating from Small Basic
  10. The Basics of Small Basic

External links

This article is issued from Wikipedia. The text is available under the Creative Commons Attribution/Share Alike; additional terms may apply for the media files.