Microsoft Small Basic | |
Paradigm: | Structured, imperative, object-oriented |
Developer: | Microsoft |
Latest Release Version: | v1.2 |
Influenced By: | Logo, QBasic, Visual Basic .NET |
File Extensions: | .sb, .smallbasic |
Operating System: | Small Basic Desktop: Windows XP (up to version 1.0), Windows Vista, Windows 7, Windows 8, Windows 8.1, Windows 10, Windows Server 2008 R2[1] Small Basic Online: web browser |
Platform: | .NET Framework 4.5 |
License: | MIT License[2] |
Genre: | Integrated development environment, educational software |
Typing: | Dynamic, weak |
Designer: | Microsoft, Vijaye Raji[3] [4] |
Status: | Active |
Microsoft Small Basic is a programming language, interpreter and associated IDE. Microsoft's simplified variant of BASIC, it is designed to help students who have learnt visual programming languages such as Scratch learn text-based programming.[5] The associated IDE provides a simplified programming environment with functionality such as syntax highlighting, intelligent code completion, and in-editor documentation access.[6] The language has only 14 keywords.[7]
The best forum for SB now is https://litdev.uk/mybb.
Version | Release date | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
October 23, 2008[8] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
December 17, 2008[9] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
February 10, 2009[10] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
April 14, 2009[11] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
June 16, 2009[12] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
August 19, 2009[13] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
October 23, 2009[14] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
February 4, 2010[15] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
June 11, 2010[16] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
November 17, 2010[17] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
February 8, 2011[18] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
July 12, 2011[19] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
March 27, 2015[20] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
October 1, 2015[21] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Microsoft announced Small Basic in October 2008, and released the first stable version for distribution on July 12, 2011, on a Microsoft Developer Network (MSDN) website, together with a teaching curriculum[22] and an introductory guide.[23] Between announcement and stable release, a number of Community Technology Preview (CTP) releases were made.
On March 27, 2015, Microsoft released Small Basic version 1.1, which fixed a bug and upgraded the targeted .NET Framework version from version 3.5 to version 4.5, making it the first version incompatible with Windows XP.
Microsoft released Small Basic version 1.2 on October 1, 2015. Version 1.2 was the first update after a four-year hiatus to introduce new features to Small Basic. The update added classes for working with Microsoft's Kinect motion sensors,[21] increased the number of languages supported by the included Dictionary object, and fixed a number of bugs.[1]
On February 19, 2019, Microsoft announced Small Basic Online (SBO). It is open source software released under MIT License on GitHub.[24] [25]
In Small Basic, one writes the illustrative "Hello, World!" program as follows:
Microsoft Small Basic is Turing complete. It supports conditional branching, loop structures, and subroutines for event handling. Variables are weakly typed and dynamic with no scoping rules.
The following example demonstrates conditional branching. It ask the user for Celsius or Fahrenheit and then comments on the answer in the appropriate temperature unit.
If tempunit = "C" OR tempunit = "c" Then TextWindow.WriteLine("Celsius selected!") tempunit = "C" ' Could be lowercase, thus make it uppercaseElseIf tempunit = "F" OR tempunit = "f" Then TextWindow.WriteLine("Fahrenheit selected!") ' We calculate the temperature values for Fahrenheit based on the Celsius values tempArray["hot"] = ((tempArray["hot"] * 9)/5) + 32 tempArray["pretty"] = ((tempArray["pretty"] * 9)/5) + 32 tempArray["cold"] = ((tempArray["cold"] * 9)/5) + 32 tempunit = "F" ' Could be lowercase, thus make it uppercaseElse GOTO question_temp ' Wrong input, jump back to label "question_temp"EndIfTextWindow.Write("Enter the temperature today (in " + tempunit +"): ")temp = TextWindow.ReadNumberIf temp >= tempArray["hot"] Then TextWindow.WriteLine("It is pretty hot.")ElseIf temp >= tempArray["pretty"] Then TextWindow.WriteLine("It is pretty nice.")ElseIf temp >= tempArray["cold"] Then TextWindow.WriteLine("Don't forget your coat.")Else TextWindow.WriteLine("Stay home.")EndIf
Small Basic does not support an inline If
statement as does Visual Basic, for example:
This example demonstrates a loop. Starting from one and ending with ten, it multiplies each number by four and displays the result of the multiplication.
[[While loop|While]]
loops are also supported, and the demonstrated [[For loop|For]]
loop can be augmented through the use of the Step
keyword. The Step
keyword is used in setting the value by which the counter variable, i
, is incremented each iteration.
Small Basic supports basic data types, like strings, integers and decimals, and will readily convert one type to another as required by the situation. In the example, both the Read
and ReadNumber
methods read a string from the command line, but ReadNumber
rejects any non-numeric characters. This allows the string to be converted to a numeric type and treated as a number rather than a string by the +
operator.
TextWindow.Write("Enter your age: ")age = TextWindow.ReadNumber
TextWindow.WriteLine("Hello, " + name + "!")TextWindow.WriteLine("In 5 years, you shall be " + (age + 5) + " years old!")
As Small Basic will readily convert among data types, numbers can be manipulated as strings and numeric strings as numbers. This is demonstrated through the second example.Text.Append(''text1'', ''text2'')
method.
The Small Basic standard library includes basic classes for mathematics, string handling, and input/output, as well as more exotic classes that are intended to make using the language more fun for learners. Examples of these include a Turtle graphics class, a class for retrieving photos from Flickr, and classes for interacting with Microsoft Kinect sensors.[26]
To make the classes easier to use for learners, they have been simplified. This simplification is demonstrated through the code used to retrieve a random mountain-themed image from Flickr:
Small Basic includes a "Turtle" graphics library that borrows from the Logo family of programming languages. For example, to draw a square using the turtle, the turtle is moved forward by a given number of pixels and rotated 90 degrees in a given direction. This action is then repeated four times to draw the four sides of the square.
More complex drawings are possible by altering the turning angle of the turtle and the number of iterations of the loop. For example, one can draw a hexagon by setting the turn angle to 60 degrees and the number of iterations to six.
Small Basic allows the use of third-party libraries. These libraries must be written in a CLR-compatible language, and the compiled binaries must target a compatible .NET Framework version. The classes provided by the library are required to be static, flagged with a specific attribute, and must use a specific data type.
An example of a class to be used in Small Basic is provided below, written in C#.
If available, the Small Basic development environment will display documentation for third-party libraries. The development environment accepts documentation in the form of an XML file, which can be automatically generated from source code comments by tools such as Microsoft Visual Studio and MonoDevelop.[27]