|Small Basic - The Programmer's Guide|
|Written by Mike James|
|Thursday, 15 March 2018|
Page 1 of 2
If you have been looking for a simple language that makes it possible to teach complete beginners then you might be pleased to meet Small Basic. It is, as its name suggests, a small and simple language, but it also has lots of rewards built in to keep the beginner's interest.
A Programmers Guide To Languages
Modern languages are very powerful, but have you ever tried to teach one to a complete beginner?
Before you can write a single program there is so much to master. You find yourself having to explain complicated and sophisticated ideas when you would really prefer to concentrate on the more basic ideas of programming.
You don't need objects, data typing or anything complicated to get in the way of learning the essence of programming. This sort of simplicity was the original intent of BASIC which was so successful at getting people to program that it grew well beyond its initial simplicity. Small Basic is almost a re-creation of this earlier form of Basic.
If you know any form of Basic, be prepared to be surprised at what has been left in and what has been left out. Try to keep in mind that the objective is not to recreate any existing form of Basic - QBasic or the original Visual Basic - but to put together something that is easy for beginners to learn. This said, there are some decisions that you might want to take issue with - but let's find out about Small Basic first.
Small Basic is easy to download and easy to install - as long you you have Windows XP or later and the .NET 3.5 Framework you can run version 1.0. Yes Small Basic is a .NET managed language, but don't imagine for a second that it is a cut down version of Visual Basic - it isn't. If you have Windows 7 or later then you can run version 1.2 and .NET 4.5.
There is a newer version, 1.3 but at the time of writing it is only available from the Windows Store as UWP app and it doesn't support extensions which are very important to making Small Basic an impressive and exciting environment - see the section on extensions at the end.
At the moment the best advice is to stick with version 1.2.
Hello Small Basic
When you first run Small Basic what you will discover is that part of making it easy to use for beginners is the IDE. This presents a simple editor window where you can type commands and issue a the Run command. There is no distinction between run and debug to confuse the beginner - you write your program code and then run it. As you type the IDE prompts with possible completions of what you type and a side panel provides documentation on the command - Intellisense style.
The first important thing to know about Small Basic is that it allows you to use objects but not to create them.
This is very reasonable because beginners often have difficulty with the creation of objects, especially in class based languages, but they have less difficulty with the idea of using an object with properties and methods. Once the idea of an object has sunk in then they are ready to ask the question of how to extend the language by creating new objects - they are also more than ready to move on to a more sophisticated language.
To see this in action, and to see how simple Small Basic is let's write Hello World. To do this you do need to know a little about the Small Basic output window - the TextWindow object.
If you start to type T e x t ... then you can see the possible choices appear and you eventually get to TextWindow
Next you can select the method you require - WriteLine - and enter the string to print.
The entire program is just the single line:
No curly brackets and no semicolons to be seen.
At the far right of the window a summary of the object and its method are presented to make sure you don't have to rush of and consult a manual.
Running the program is just as easy - press F5 or click the Run icon. In this case a command console opens and you see the printed message.
There is also an End Program button that appears in the IDE just in case things don't work out.
So far so good but what do you need to tell the beginner to make progress in Small Basic?
The first thing they need to master is the idea of a variable and a value.
In Small Basic this is stripped down to its bare essentials. There are no data types apart from numbers and strings and these are automatically converted where possible. This means you don't have to draw the beginners attention to the difference between 1 and "1" until they are ready to notice it.
There is also no need to worry about anything beyond simple value assignment - there are no reference or pointer types. All you can do is store a value in a variable. You don't even have to declare variables before using them. Using a variable is enough of a sign that you want to create some storage for a value.
So you can just write
The next simplification might have some programmer worried - all variables are global and they persist for the lifetime of the program. This may be worrying but it means that the beginner doesn't have to worry about scope, shadowing or lifetimes.
It is simple and it works for small programs. Once the beginner has the concept of variable, value and assignment well mastered then they can be introduced to scope and other matters but in some more appropriate language.
The second issue in teaching a programming language is to deal with the flow of control and here I have a problem with Small Basic - it has labels and Goto.
It also uses the Goto in many of its examples.
The problem is that the Goto isn't simple and it doesn't carry over into other languages. Unlike the other simplifications of Small Basic that have to be extended when the beginner moves to a modern and more advanced language the Goto has to be excised, removed, forgotten and generally trampled on.
Why teach something so early that is unnecessary and that has to be unlearned?
There is one tiny excuse for including Goto and this is to teach the very primitive control structures that are found in the machine code and hence assembly language. Perhaps there is value in teaching how to create a loop and a conditional using a jump or Goto - but not to a complete beginner.
If you are using Small Basic to teach some one new and impressionable make sure to avoid the Goto at all costs.
So apart from the Goto and the label, of which no more will be said, what other control structures are there?
The good news is that the control structures are close to the original Basic forms which means they are also closer to the usual English expression of the same idea than the usual curly bracket equivalents.
The If statement takes the form:
Where you can leave out the Else part if you want to create a simpler
Small Basic also supports the usual two of the three structured programming loops - the for and the while.
The for loop takes the easier to use restricted form introduced by Basic:
Of course you can leave out the Step part of the instruction to create a simpler For loop that increments the index by one each time. For example:
This is so much easier to explain to a beginner than the C-style for loop
which is much more general than a simple enumeration loop needs to be and reads like an arcane magical expression than something meaningful.
Notice that the For loop doesn't end with the traditional Next statement but with an arguably more consistent EndFor. You can argue about this for hours. Next has the advantage of being an active instruction in the beginners minds at least in that it says "get the next value of the index and start the loop again" where the "Endfor" is just a terminating punctuation in the general syntax of the language - does it End the For in any active sense? No.
The conditional loop is supported in Small Basic via the While loop:
This provides a loop with an exit point at the start and so the loop can be used to create zero or more alterations.
You can program everything you want to using nothing but the For and While loop - in fact you really only need the While loop as it combined with the If statement are provably sufficient for any program.
However it would be better if Small Basic also supported an Until loop. An Until loop has its exit point at the end and can be used to create one or more iterations. The distinction between While and Until is a subtle one however and something that can best be left for later. The big problem is that without an Until or without a Break statement the temptation is to use the Goto to create more complex loops - this is not good.
|Last Updated ( Thursday, 12 April 2018 )|