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 Structured, imperative, object-oriented
Designed by Microsoft, Vijaye Raji
Developer Microsoft
First appeared July 13, 2011; 3 years ago (2011-07-13)[1]
v1.1 / April 1, 2015; 3 months ago (2015-04-01)[2]
Dynamic, weak
Platform .NET Framework 4.5[2]
OS Windows Vista, Windows 7, Windows 8, Windows 8.1, Windows 10, Windows Server 2008 R2[2]
License Freeware
.sb
Website www.smallbasic.com

Microsoft Small Basic is a programming language and associated IDE. It is Microsoft's simplified variant of the BASIC programming language, intended as an easy programming language for beginners. The associated IDE provides a simplified programming environment with functionality such as syntax highlighting, intelligent code completion, and in-editor documentation access.[3] The language has only 14 keywords.[4]

History[edit]

Microsoft announced Small Basic in October 2008[5] and on 13 June 2011 released it for distribution[1] on a Microsoft Developer Network (MSDN) website together with a teaching curriculum[6] and an introductory guide.[7] A developer's reference, three semesters of self-study tutorials, BASIC Computer Games: Small Basic Edition by David H. Ahl, Ahl's Small Basic Computer Adventures, and Computer Bible Games for Microsoft Small Basic are available for purchase from Kidware Software.[8][9]

Language[edit]

In Small Basic, one writes the illustrative "Hello, world!" program as follows:

TextWindow.WriteLine("Hello World!")

Microsoft Small Basic is Turing complete. It supports conditional branching, loop structures, and subroutines for event handling. Variables are typeless and dynamic with no scoping rules.

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")
For i = 1 To 10
  TextWindow.Write(i * 4)
End For

Data types[edit]

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

In this example, the program requests the user's name and age and then tells the user how old he would 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 graphics[edit]

Microsoft Small Basic ships with a Turtle graphics library that borrows the idea from Logo. For example, the developer of a Small Basic program can draw a square by moving the turtle forward x pixels (in the example below, x is 100) to draw a line segment, then turning the turtle 90 degrees to the right, and iterating this procedure four times:

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

See also[edit]

Related Microsoft technologies:

Related languages:

References[edit]

  1. ^ a b Aldana, Sandra (7 December 2011). "Small Basic 1.0 is here!". Small Basic. MSDN Blogs. Microsoft. Retrieved 9 February 2014. 
  2. ^ a b c "Microsoft Small Basic 1.1". Download Center. Microsoft. 1 April 2015. Retrieved 1 April 2015. 
  3. ^ Price, Ed (22 October 2012). "The Unique Features of Small Basic". Small Basic. TechNet. Microsoft. Retrieved 22 April 2015. 
  4. ^ Price, Ed (8 October 2012). "What are the 14 Keywords of Small Basic?". Small Basic. MSDN Blogs. Microsoft. Retrieved 9 February 2014. 
  5. ^ Raji, Vijaye (23 October 2008). "Hello World". Small Basic. MSDN Blogs. Microsoft. Retrieved 9 February 2014. 
  6. ^ Price, Ed (29 April 2014). "Small Basic Curriculum". TechNet. Microsoft. Retrieved 9 February 2014. 
  7. ^ Price, Ed; Takahashi, Nonki (25 February 2014). "Small Basic Getting Started Guide". TechNet. Microsoft. Retrieved 12 February 2015. 
  8. ^ Price, Ed (12 May 2014). "Small Basic Programming Books". TechNet. Microsoft. Retrieved 12 February 2015. 
  9. ^ "Small Basic". Computer Science For Kids. Kidware Software. 2014. 

External links[edit]