Microsoft Small Basic

From Wikipedia, the free encyclopedia
Jump to: navigation, search
This article is about the Microsoft programming language. For the GPL programming language, see SmallBASIC.
Microsoft Small Basic
Microsoft Small Basic icon.png
Small Basic.png
Small Basic running on Windows 7
Paradigm(s) Structured, imperative, object-oriented
Developer Microsoft
Appeared in July 13, 2011; 2 years ago (2011-07-13)[1]
Stable release v1.0 / July 18, 2011; 2 years ago (2011-07-18)[2]
Influenced by Visual Basic .NET
Platform .NET Framework 3.5 SP1[2]
OS Windows XP, Windows Vista, Windows 7, Windows Server 2003, Windows Server 2008[2]
License Freeware
Filename extension(s) .sb
Website www.smallbasic.com

Microsoft Small Basic is a simplified variant of the BASIC programming language, developed by Microsoft and intended as an easy programming language for beginners. The language itself has only 14 keywords,[3] and the environment is beginner-friendly, with a straightforward interface.

History[edit]

Small Basic was first introduced by Microsoft in October 2008[4] and was released on 13 June 2011[1] on an updated MSDN website that included a full teacher curriculum,[5] a Getting Started guide,[6] and several 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.[7]

Microsoft Small Basic was designed by Microsoft DevLabs and released as a Technology Preview[8] 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[9] 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++.[10]

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.[11]

Language[edit]

In Small Basic, the traditional "Hello world" program is written as follows:

TextWindow.WriteLine("Hello World")

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 for event handling.

Conditional branching[edit]

The following example demonstrates conditional branching. It requests the current temperature in Fahrenheit and comments on the answer.

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[edit]

This example demonstrates a loop. Starting from one and ending with ten, it multiplies each number by four and displays the result of multiplication.

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

Data types[edit]

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

In this example, the program request the user's name and age and tell the user how old would he be in five years. However, it treats the age as a number and won't accept characters in age.

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!")

Small Basic stores all values – including arrays – as formatted strings.[citation needed] 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)

In the second example, both strings are treated as numbers and added together, producing the output 3100. To concatenate the two values, producing the output 1003000, it is necessary to use the Text.Append(text1, text2) method.

Libraries[edit]

Standard library[edit]

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 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[edit]

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[edit]

Microsoft Small Basic ships with a Turtle graphics library that borrows the idea from Logo. For example, the developer can make the turtle draw a square by drawing four lines and turning right after each one:

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

See also[edit]

Related Microsoft technologies:

Related languages:

References[edit]

  1. ^ a b "Small Basic 1.0 is here! - Small Basic - Site Home - MSDN Blogs". Blogs.msdn.com. 2011-07-12. Retrieved 2014-02-09. 
  2. ^ a b c "Microsoft Small Basic". Downloads. Microsoft. 18 July 2011. Retrieved 16 February 2014. 
  3. ^ "What are the 14 Keywords of Small Basic? - Small Basic - Site Home - MSDN Blogs". Blogs.msdn.com. 2012-10-08. Retrieved 2014-02-09. 
  4. ^ "Hello World - Small Basic - Site Home - MSDN Blogs". Blogs.msdn.com. 2008-10-23. Retrieved 2014-02-09. 
  5. ^ "Small Basic Curriculum - TechNet Articles - United States (English) - TechNet Wiki". Social.technet.microsoft.com. Retrieved 2014-02-09. 
  6. ^ "Small Basic Getting Started Guide - TechNet Articles - United States (English) - TechNet Wiki". Social.technet.microsoft.com. Retrieved 2014-02-09. 
  7. ^ "Small Basic E-Books - TechNet Articles - United States (English) - TechNet Wiki". Social.technet.microsoft.com. Retrieved 2014-02-09. 
  8. ^ "Products and Extensions for Visual Studio". Msdn.microsoft.com. Retrieved 2014-02-09. 
  9. ^ "Small Basic - Elementary & Middle Student Testimonials - Small Basic - Site Home - MSDN Blogs". Blogs.msdn.com. 2012-10-25. Retrieved 2014-02-09. 
  10. ^ "Graduating from Small Basic - Small Basic - Site Home - MSDN Blogs". Blogs.msdn.com. 2009-10-25. Retrieved 2014-02-09. 
  11. ^ "Expert to Expert: The Basics of SmallBasic | Charles | Channel 9". Channel9.msdn.com. 2009-01-20. Retrieved 2014-02-09. 

External links[edit]