locked
Small Basic for Beginners? RRS feed

  • Question

  • The tag line is that "Small Basic is for beginners."

    Yet, there are things going on that give pause to seasoned programmers, and I only shudder to think of how they might affect true beginners.

    My latest discovery is a peculiarity in handling strings. 

     

    TextWindow.Show

    TextWindow.WriteLine(1 + 2)

    TextWIndow.WriteLine("A" + "B)

    Textwindow.writeline("1" + "2")

     

    produces:

    3

    AB

    3

     

    Rather un expected, and I'm not aware of ANY other computer programming language that exhibits this behavior.

    There are other strangenesses.

    I feel that SB illustrates some odd-ball thinking on the part of it's designers.

    SB is definitely a poor choice for beginning programmers.

     


    RussPC
    Tuesday, November 29, 2011 11:34 AM

Answers

  • The logic is + will add input as numbers if the numbers are found to be numbers, if the number cannot be parsed as numbers they will be added as strings.

    This is the bug. + operator first tries to parse values to decimals. If the the parsing fails then values will be appended as strings.

    TextWindow.WriteLine(Text.Append(3,2)) ' Values are handled as strings
    TextWindow.WriteLine("3"+"4")   ' Ints can be parsed to decimals
    TextWindow.WriteLine("3."+"4")  ' Can be parsed to decimals
    TextWindow.WriteLine("3,"+"4")  ' Can't be parsed to decimals
    TextWindow.WriteLine("3"+"1.5") ' Can be parsed to decimals
    TextWindow.WriteLine("3"+"1,5") ' Can't be parsed to decimals
    This bug could be solved easily by for example adding type property to primitive.

    It could be something like this: 

    public enum PrimitiveType
    {
       array,
       decimal,
       int,
       string  
    }
    
    /// <summary>
    /// Value that stores type of the primitive
    /// </summary>
    public PrimitiveType type
    {
       get;
       private set;
    }

    Then initializers and operators can set the type property when primitive is created or changed.

    Tuesday, November 29, 2011 9:21 PM

All replies

  • TextWIndow.WriteLine("A" + "B) produces Syntax error

    You're right about Textwindow.writeline("1" + "2"), it should produce 12 instead of 3. There has already been some discussion about this type conversion bug if I remember right.

    Tuesday, November 29, 2011 3:10 PM
  • This code:

    xx = "1" + "2"
    TextWindow.WriteLine(xx)

    Also produces the output:

    3

     


    RussPC
    Tuesday, November 29, 2011 8:41 PM
  • There are no types in SB, so operators (e.g +) interpret its functionality (left to right, accounting for parentheses) depending on inferred type. Eg "3" is intrepreted as a number.  You can always use Text.Append to concatenate strings, eg TextWindow.WriteLine(Text.Append(3,2)).

    Also for example consider:

    TextWindow.WriteLine(Text.Append(3,2))
    TextWindow.WriteLine(3+","+4)
    TextWindow.WriteLine(3+4+","+5)
    TextWindow.WriteLine(3+(4+","+5))

    The logic is + will add input as numbers if the numbers are found to be numbers, if the number cannot be parsed as numbers they will be added as strings.

    Tuesday, November 29, 2011 8:49 PM
  • It is all goofy!  The programmer ought not to be forced to do "work arounds", in my opinion.

    I have serious doubts as to the suitability of "The Beginner's Programming Language", expecially the declaration that it "Puts the fun back into programming!" 

    From what I've seen so far, it appears to me that SB does all of its variable storage as character strings, converting between strings and actual number on the fly.  Shudder!

    With all of SB's quirks, twists and turns, I believe I'd be spending far more time with my students puzzling over why their obvious code does not work as we expect it to.

    A loud razzberry to MS on this one!

     


    RussPC
    Tuesday, November 29, 2011 9:15 PM
  • The logic is + will add input as numbers if the numbers are found to be numbers, if the number cannot be parsed as numbers they will be added as strings.

    This is the bug. + operator first tries to parse values to decimals. If the the parsing fails then values will be appended as strings.

    TextWindow.WriteLine(Text.Append(3,2)) ' Values are handled as strings
    TextWindow.WriteLine("3"+"4")   ' Ints can be parsed to decimals
    TextWindow.WriteLine("3."+"4")  ' Can be parsed to decimals
    TextWindow.WriteLine("3,"+"4")  ' Can't be parsed to decimals
    TextWindow.WriteLine("3"+"1.5") ' Can be parsed to decimals
    TextWindow.WriteLine("3"+"1,5") ' Can't be parsed to decimals
    This bug could be solved easily by for example adding type property to primitive.

    It could be something like this: 

    public enum PrimitiveType
    {
       array,
       decimal,
       int,
       string  
    }
    
    /// <summary>
    /// Value that stores type of the primitive
    /// </summary>
    public PrimitiveType type
    {
       get;
       private set;
    }

    Then initializers and operators can set the type property when primitive is created or changed.

    Tuesday, November 29, 2011 9:21 PM
  • It seems SB isn't for you or your teaching requirements.

    SmallBasic is intentionally small without syntax bloat that comes with adding full functionality.  In my opinion, the small syntax and indeed the performance issues actually encourages good coding where the emphasis is on efficient algorithms and logic rather than a memory test of syntax - a bit like the early days such as Sinclair Spectrum where I started.

    Bug fixes are another thing, and I hope they will be taken on board.  The last year's update cycle has been a bit stalled and I hope it will pick up at some point with an emphasis on the known bugs.

    SmallBasic is more about teaching the fundamentals of software, converting ideas into structured logic.  It is less about the actual end product.  Having said that, some of the SmallBasic programs that have been written are very impressive - emphasising the skills of algorithm development over brute force.

    Recommend you look seriously at the following options:

    Consider trying the free Express versions of VB or C# (including WPF) where you have full control (albeit with thousands of methods to choose from and a complex IDE).  You can also use all SB commands inside VB/C# by referencing SmallBasicLibary.dll as a starting point, harnessing the performance and versatility of these .Net languages in addition to the simple SB command set.  This is a bit like using SmallBasic and writing an extension alongside the SB code, for example to use standard data types and array methods, just using the SB for graphics.

    There are many non-MS alternatives, in particular Java (http://www.java.com), Ruby (http://www.ruby-lang.org) and Python (http://www.python.org).  I would certainly look at these, they are modern takes on computing (quite different paradigms taking their roots from AI-lisp or scripting languages) designed to be 'user friendly'; at least read about them, download them and learn enough to evaluate.  There is also another software called SmallBASIC (http://smallbasic.sourceforge.net) (not MS), it is a more traditional BASIC.  There are large user communities with most of these to help.

    There are plenty of linux alternatives too (MonoDevelopment, Eclipse etc), but probably harder for most beginners.  Also Scratch (http://scratch.mit.edu) pre-programming really.

    Having used all of these my feeling is that SB is actually a very good starting language (gives me the similar feeling to my early programming experimentation and works well for my children), but clearly not for your purposes.  Whether a language is intuitive or not depends on previous experience (most SB users have none) - try Python, one the most popular new languages and consider the intuitiveness of arrays (tuples as they are called).

    Anyway good luck with whatever you choose.

    Tuesday, November 29, 2011 9:48 PM
  • Thank you for your suggestions.  They do seem to offer some good options.  Also, I didn't know there are free versions of VB and C#.  Perhaps most interesting is the idea of using SB to do the GUI with VB or C# for the main "guts" of a program.  A definite possibility.

     


    RussPC
    Wednesday, November 30, 2011 1:40 PM
  • Now explain THAT to a beginner!  :)

     


    RussPC
    Wednesday, November 30, 2011 1:43 PM
  • I'm a beginner and I think SB is great.  I tried learning C++ but it would have taken far more time than I'm willing to put into some minor hobby programming.  Eventually I'll probably switch to VB and hope to be able to enter some small games for challenges, but for now I'm having fun with SB... just like the MS webpage for SB says.  I'd consider bugs in a free program that's at v1.0 to be acceptable, if still annoying.

     

    Allen

    Wednesday, November 30, 2011 1:58 PM
  • Allen,

    Good for you!  I'm glad you are learning and enjoying your experience.

    My position as a long time professions software designer and progeammer is perhaps jaded from many experiences along the way.

    I am contemplating teaching a programming course at our local library, and I do like the over all capabilities of SB.  That said, my concerns are over what happens when one of my students does something that at first glance appears to be proper, yet does not work as expected.

    I have also downloaded VB Express, and will get C# express as well.  As was suggested above, using SB for the GUI part and VBE/C#E for the "guts" makes sense.

    When I taught a graduate level programming class (to groups of health sciences students), my first year used a main-frame version of BASIC, and I well recall the troubles my students had which were traced to the language's lack of typing and scoping.  The second year I taught FORTRAN, and the students had a much easier time of it, and continued for several more years.  Two of my students produced programs that ended up being used by the department of radiology routinely.

    I wish you the best in your pursuits.  I got hooked on programming long, long ago, and still enjoy keeping my skills in use, more for fun now than for "real" work!  Being retired, I wonder, as my father did, how I managed to give so much of my time to employers! :()

     


    RussPC
    Wednesday, November 30, 2011 7:47 PM