ThinBasic | |
Developer: | Eros Olmi |
Latest Release Version: | v1.12 |
Influenced By: | Powerbasic |
thinBasic is a BASIC-like computer programming language interpreter[1] with a central core engine architecture surrounded by many specialized modules. Although originally designed mainly for computer automation, thanks to its modular structure it can be used for wide range of tasks.
As the name suggests, the biggest influence on the syntax of this language was the BASIC language. But, unlike traditional BASICs, as known from the 8-bit era, thinBASIC does differ in few important points.
For example, it requires the programmer to declare variables and it does not feature the infamous GOTO and GOSUB statements. Some aspects of the syntax are even inspired in non-BASIC languages, such as C/C++.[2] Thanks to this, thinBASIC optionally allows use of implicit line continuation, simplified addition, subtraction, multiplication and division operators, shortened variable declaration and initialization:
' C/C++ inspired syntax allowed in thinBASICINTEGER a = 1 ' a is initialized to 1a += 1 ' a now contains 2
' New syntax introduced in 1.9.10.0 allows defining type from string expressionSTRING sType = "INTEGER"DIM a LIKE sType
Another source of inspiration are the modern versions of BASIC, such as Visual Basic or PowerBASIC.
ThinBASIC does offer the main flow control statements, such as SELECT CASE, IF ... THEN/ELSEIF/ELSE/END IF, loops (infinite, conditional, FOR, WHILE/WEND, DO/LOOP WHILE ..., DO/LOOP UNTIL ...) and it also puts very strong effort on providing wide range of built-in functions for number crunching and especially string handling.
ThinBASIC supports a wide range of numeric[3] and string[4] data types.
Integer | Floating point | String | Other | |
---|---|---|---|---|
BYTE | SINGLE | STRING | VARIANT | |
WORD | DOUBLE | STRING * n | GUID | |
DWORD | CURRENCY | ASCIIZ * n | BOOLEAN | |
INTEGER | EXTENDED, EXT | UDT (user-defined type) | ||
LONG | UNIONS | |||
QUAD | iDispatch |
Besides those mentioned in the table above, a programmer can define pointers, user-defined types and unions.
The special features related to user-defined types in thinBASIC are:[5]
Variables can be defined in global, local or static scope.ThinBASIC supports arrays of up to three dimensions.
The elemental functionality of the language is provided by the so-called Core module, which is loaded by default, and takes care of parsing too.
Besides the Core module, thinBASIC offers other modules, each covering a specific area of functionality, for example:
Each module is represented by single DLL, with specific structure. This allows the module to contain not just typical functions and procedures, but also for example constants and user-defined types definitions, immediately available for script without need for header file. The only thing needed is to explicitly mention the usage of module in the code – for file handling it would look like:
' Function File_Load comes from the module, it returns the content of passed file in form of StringString sBuffer = File_Load("C:\text.txt")
To better structure the code, thinBASIC provides the functions and procedures functionality. There is one function with special treatment, called TBMAIN, which is guaranteed to be executed first. It represents the same function as main function in C programming language, but its use is optional.
A programmer can define custom functions and procedures (called Subs); they can have up to 32 parameters. Both functions and procedures do not need to be declared before use. Parameters can be marked as optional, and they can also be initialized to default values. Each parameter can be specified to be passed by value (default) or by reference.
' Program body starts in TBMain functionFunction TBMain
MyFunction(10) ' This will print 10 20 30, because unused optional parameters #2 and #3 are initialized to 20 and 30
MyFunction(10, 3) ' This will print 10 3 30, because unused optional parameter #3 is initialized to 30
MyFunction(10, 3, 5) ' This will print 10 3 5, because we specify all the parameters, so the defaults are discarded
Console_WaitKey
End Function
' User defined function with optional parameters with default valuesFunction MyFunction(a As Number, Optional b As Number = 20, c As Number = 30)
Console_PrintL(a, b, c)
End Function
The functions can be called directly, as in the listing above, or by composing their name at run-time.
ThinBASIC supports calling functions from third-party DLLs; programmer needs to declare them first to be able to access the functionality.
Thanks to this mechanism, thinBASIC allows using technologies such as OpenGL, OpenCL,[6] XML, ODE and many others.
ThinBASIC does not support any form of project files at the moment, but it encourages splitting code to units by providing multiple file extensions for different use:
The main code can reference these files using #include directive, which can use wildcards:
Function TBMain ' -- Main code goes here, and can use functionality from #included files
End Function
The language can be enhanced by module development using SDK for many languages (PowerBASIC, FreeBASIC, C, MASM).
The development team puts strong focus on documentation of the language and on the learning resources. The language itself is documented in extensive help file[7] and the default installation contains tutorial and much example code too.
Various articles on use of thinBASIC have been published in form of ThinBasic Journal and on the homepage of the programming language as well (please see external links).
ThinBASIC comes with own IDE, called thinAir, in the default installation.[8] It offers:
thinAir allows using the debugger as well.
This component is called thinDebug[10] and can be watched on the image linked below.
Console program, which asks user about name and then greets him:
' TBMain represents main body of the programfunction TBMain ' Creates variable to hold user name local UserName as string
' Asks user for the name Console_Print("What is your name?: ")
' Stores it to variable UserName = Console_ReadLine
' If length of username is 0 then no name is specified, else program will say hello if len(UserName) = 0 then Console_PrintLine("No user name specified...") else Console_PrintLine("Hello " + UserName + "!") end if
' Waits for any key from user before program ends Console_WaitKeyend function
ThinBASIC was designed for the Windows platform and this is why it makes a good use of resources provided by this system, such as registry, user interface, work with processes, COM, DLLs. Although interpreted, thinBASIC is considered to have usually fast execution.[11] When the interpreter nature of the language hits the limits, it is possible to perform optimizations using partial JIT compilation. Another strength of the language is a wide range of commands covering various areas of interest and for BASIC traditionally - strong focus on string handling. The language is under continuous development and maintenance.[12]
The fact that thinBASIC is designed for Windows only can be seen as disadvantage as well, for those who seek cross-platform tools. The speed of execution without the use of optimizations is lower compared to output of compilers, thanks to language interpreter nature.
thinBASIC has been developed under Microsoft Windows XP Professional using PowerBASIC,[13] and requires Internet Explorer version 5.50 or above.