# Arrays

• ### General discussion

• I've just started teaching my 9 year old daughter programming using Small Basic.
I think this is a very good tool for introduction to programming with the easy text/graphics windows, friendly editor and simple commands.

What I dread is the point when I have to teach arrays - could it be less intuitive? - why spawn all array commands off an array object with parameters instead of some syntactic sugar? [index] comes to mind...

amif2000

P.S I was on my way to develop something similar to small basic on my own. Looks like MS beat me to it :)
Saturday, January 10, 2009 7:09 PM

### All replies

• Amif2000,

We're still very much on the fence about adding a syntactic sugar for arrays.  At the moment, we're not convinced that the syntax sugar is absolutely necessary - but messages like yours are great feedback for us.

Thanks.
Saturday, January 10, 2009 7:33 PM
• It would be nice to sweeten the arrays.
I may have mentioned this in an earlier post, but in Applesoft Basic, an array is setup at the beginning of the program before any variables are used at all (mine had them on the very first line).
Could it not be done that way in S.B.?

In Applesoft Basic:

DIM X(4,4)

Sets up the variable X to be a 4 by 4 array though out the rest of the program.

Use of the array after that is as easy as X(1,1)  = 1
Or...
DIM X\$(4,4,2)
X\$(y,z,1) = "secret wall"

...which brings up another point.
I think an array is close to (but no completely) useless without having at least 2 dimensions.

So could the could the command for arrays be made easier and could more dimensions (at least 1 more) be added?

...or is there a real-word programming alternative to arrays that should be used instead?

Tuesday, January 13, 2009 4:10 PM
• With fully associative array index, multy dimentional arrays are not a must.
In TCL you can say 'set a(1,2) "something"' and while it looks like a 2D array, "1,2" is actually a single string index. That could also work here.
Friday, January 16, 2009 5:13 AM
• Path_drc,
In other Basics I've used, the syntax has been much the same as the one you cite, although without the obligation to put the Dims at the top of the program.  In GW-Basic, QBasic/QuickBasic and VB, Dim is used.  They all (even GWB) allow more than two dimensions.  In GWB, elements 0 to 10 are implicit, so you can use a(0) to a(10) without needing to declare or dimension "a" first!  Which made one-dimensional array use even easier for beginners.  Note: in GWB you can have a non-array variable called myvar and an array called myvar(10) simultaneously.  In VB you must have one or the other, not both - trying to have both is treated by VB as a duplicate declaration.
Friday, January 16, 2009 3:59 PM
• Arrays should not have more than one dimension at a time.
If you want a 'two-dimensonial' array, it's better to have something like Arr[0][5] than Arr(0, 5) or Arr[0, 5] whic likes too much Func(0, 5).

Please also notices that Array's in SmallBasic are in fact Dictionnaries(Of Primitive, Primitive), so I don't see how it would be possible to implements multidimensional arrays here (it's possible to map an Array to a Primite (its name), but I don't see how you'll map two dimensions in a single parameter).

But I agree with you when you say that Arrays are needed. I didn't know any language that haven't arrays. Self very old programmatic languages were already having such arrays.

Fremy
Fremy VB & C#
Saturday, January 17, 2009 5:50 PM
• So SB doesn't have any form of arrays? I find these very useful in Just Basic (which I began to learn after experiencing SB).
Sunday, January 18, 2009 3:43 AM
• Here's a vote for multi-dimensional arrays in Small Basic.  When learning to program, a two-dimensional array for a chessboard is much less confusing than a single dimensional array with offsets.

Multi-dimensional arrays have proven very handy to use in other BASIC languages, both for board games and for business uses.  A simple chessboard array is Bd(n1,n2) where n1 and n2 can be any number 1 through 8.  An entire inventory can be held, and easily accessed, in Inventory(Yr, Mo, Da, Item, Count).
Tuesday, March 17, 2009 6:59 PM
• My 2 cents on the topic:

The Arrays are both necessary for any kind of real data processing; and, because of the required syntax , complex and foreign for a beginner.

Something different is required.

Personally, I would be happiest with an object akin to the ArrayList class in java. It has dynamic memory management, syntax at least reminiscent of standard arrays, and since the memory is indexed, look ups happen in O(1) time. The downside is the inability to create multi-dimensional arrays without some funky syntax or method calls.

What SB currently has is a good compromise. While called an array, what the Array object actually is, is a two-dimensional map structure. With a map you can simulate almost any other type of data structure, including an array.

Import this project for an example: XBN618

The program is the solution of Euler Projects 18 and 67. It makes use of the Array object to simulate two two-dimensional arrays (or one two dimensional array holding two pieces of data -- depending on your point of view).

It shows that the Array object is effective, but slow.

My one suggestion: Don't call it an array. It is a map structure, so call it a Map. Calling it an array leads to nothing but confusion now, and sets the newbie up for more confusion in the future when they learn about true arrays.

Tuesday, March 17, 2009 8:19 PM
• The name doesn't matter. Only the syntax can matter.

In my proposal, there is nothing wrong to have

myArray["str"] = "xxx"

As you currently can have

Array.SetValue("myArray", "str", "xxx")

Please also notice that arrays are 'map' in some langages like PHP or JScript.
And they are called Arrays too. If you refer to the definition of an array, it's not an error :

 In computer science, an array[1] is a data structure consisting ofa group of elements that are accessed by indexing. In most programming languages each element has the same data type and the array occupies a contiguous area of storage.

and

 In computer science, an index can be: * an integer which identifies an array element * a pointer data element. * a data structure that enables sublinear-time lookup

Fremy - Developer in VB.NET, C# and JScript ... - Feel free to try my extension
Wednesday, March 18, 2009 8:44 PM
• I've been playing around with Small Basic for a while, so I decided to give my input here as well.  I was recently making a small game that didn't exactly require multi-dimensional arrays, but it sure would have made it easier.  After a bit of fooling around, I discovered a way to essentially bypass the needs.  Here's how I did it:

For i=1 To 5
For j=1 To 5
Array.SetValue("Data"+i,j,i*j)
EndFor
EndFor

For i=1 To 5
For j=1 To 5
TextWindow.Write("Data" + "[" + i + "][" + j + "]=" + Array.GetValue("Data"+i,j) + " ")
EndFor
TextWindow.WriteLine("")
EndFor

TextWindow.WriteLine(Array.GetValue("Data2",3))
'or
TextWindow.WriteLine(Array.GetValue("Data"+2,3))
'or
TextWindow.WriteLine(Array.GetValue("Data"+"2",3))

All I'm really doing is making 5 arrays (Data1, Data2, etc...), but because you can use the + sign when assigning and calling arrays, you can use it like a multi-dimensional array.  I know that this method isn't exactly the best way to do it, but it works.

If nothing else, I'm also agreeing that arrays are all but useless without more than 1 dimension.  I would like to see multi-dimensional arrays in small basic, I think it would help beginners learn what they're really getting in to.  Just my two cents.  Small Basic Rocks!

Friday, March 27, 2009 9:20 PM
• I've revisited this thread as I've just had an idea for 2-dimensional arrays. As Vijaye pointed out in another thread, arrays are accessed by value, not by reference. this led me to think that the array "name" could actually be an integer and thus the first index of a two-dimensional array. The following code prints out the numbers 0 to 99. The main point to note is that the required value is accessed as Array.GetValue(i,j). This looks like a nameless array in two dimensions whereas it is actually a set of 1-dimensional arrays.

For i = 0 To 9
For j = 0 To 9
Array.SetValue(i,j, i*10 + j)  'Load the array values
EndFor
EndFor

For i = 0 To 9
For j = 0 To 9
TextWindow.WriteLine(Array.GetValue(i,j))  'Output the array values
EndFor
EndFor

Wednesday, May 6, 2009 6:52 PM
• Stendec,

This is a good observation. I have a feeling that it is inefficient as far as processing time and memory management goes, but the syntax is close to that of standard arrays.

Jumping straight into two dimensional arrays is a big step, but drawing a grid of boxes is a clear enough analogy to make it palatable.

This is cool, because I will now be able to add Arrays to the topic list for my Intro class in the fall.

Thank you.
Wednesday, May 6, 2009 8:05 PM
• Saturday, August 29, 2009 12:06 PM
• ShariqDON,

You are in the Small Basic Forum.  Your thread is pointing to Visual Basic.  Arrays in Small Basic are totally different than in Visual Basic.  I would suggest that you move your request to the Visual Basic Forum.

JR
Saturday, August 29, 2009 4:14 PM