Small Basic - Coding Patterns

I started to organize coding patterns for Small Basic here in CodePlex.  I sometimes use these patterns in my Small Basic programs.

For example, I use three patterns in following code (from WNK213). 

  `` mcol `` = ``0  ``' mouse column

  `` For `` col `` = `` 1 `` To ``3

    `` If ``x1``[``col`` ] `` < `` x `` And `` x `` < ``x2``[``col`` ] ``Then

      `` mcol `` = ``col

      `` col `` = `` 3 ``' exit for

    ``EndIf

  ``EndFor

I named the first pattern as CamelVar.  I named each pattern.  A pattern has it's name, descriptions, codes, pictures, exceptions, links to other patterns and external links.  This concept is come from Pattern Browser described with HyperCard.

CamelVar

Use camel notation for variable names.

ex. angle, mouseDown

Exceptions

See Also

Other Resources

The second pattern is PseudoExit.  This pattern is alternative for Exit For or Exit While in Visual Basic.  Because Small Basic doesn't have these keywords.

PseudoExit

Use i = n to exit For loop.

 For i = 1 To n
  Judge()
  If exit Then
    i = n  ' exit for
  EndIf
EndFor

Use cond = "False" to exit While loop.

 While cond
  Judge()
  If exit Then
    cond = "False" ' exit while
  EndIf
EndWhile

The third one is IndentByIDE.

IndentByIDE

Follow the IDE about the indentation rules (use [Format Program] below).

Screen shot of Small Basic IDE with a popup including Format Program

Some of these patterns may become snippets for Small Basic.

Happy coding with Small Basic!


Other Resources