QuickBASIC/QBASIC newsletter
Article of the Month
The Power of the BASIC Programming Language
By Richard Russo
The acronym BASIC stands for Beginners All-Purpose Symbolic
Instruction
Code. It was developed at Dartmouth College in 1964 in
order to give beginning
programmers a language that is simple to use and read, and at
the same time, provide
sufficient power. However, the first word in the
acronym usually causes people to
consider it a simple and weak language. I intend to point
out the differences between
BASIC and comparable languages, namely Pascal and C, and show
that the differences
in the language are for the most part superficial. I stress
that it is the languages I am
comparing, and not a specific compiler package.
The most significant difference between BASIC, Pascal and C
is that the
latter two allow the programmer to declare pointers. A
pointer, in a high level
language, is a variable that acts as a reference to another
variable. In the case
of C and Pascal, it is a variable that holds a memory address.
This address can
be the location in memory of a variable or a function or even
a subroutine. To
learn more about pointers, support a local library, or search
on the Internet. Pascal
and C both allow the programmer to declare pointers. Sample
code follows:
In C: int *aPointer;
In Pascal: var aPointer: ^Integer;
Both of these lines of code declare a pointer to an integer
variable with
name 'aPointer'. After declaring these variables, the
addresses they contain can
be manipulated directly, and the contents of the memory at that
address can be
manipulated by syntax that is built into the language.
BASIC contains no such
syntax. In BASIC, direct memory manipulation is accomplished
by the POKE and
PEEK statements. POKE allows a direct memory write, and
PEEK a direct read.
BASIC has the power (and destructive power included) that come
with pointers.
However, if two similar routines were programmed in BASIC and
Pascal that used
pointers, the BASIC code would be "dirtier." The Pascal
code would contain "clean"
definitions of pointers, whereas the BASIC code would have to
use the POKE and
PEEK commands.
A C programmer will tell you that his or her language is faster
than BASIC.
This isn't true because the speed depends upon the compiler
or interpreter, but not on
the actual language. C does have commands that translate
directly into machine code,
such as the ++, +=, -=, and so on operators. However,
a good compiler will realize that
the following two lines of code are the same, and produce efficient
code:
variable = variable + 1
'In BASIC
variable++;
/*the 'fast' way in C*/
My computer science professor has written several compilers,
and will tell you
that good compilers can optimize the first line so that it compiles
into the same
machine code as the second.
Speaking of operators, C doesn't have a built-in XOR logical
operator :P
In conclusion, BASIC can be just as powerful as C and Pascal,
because the
differences are only surface deep. The particular syntax
of a language does not change
its potential. Whether you set off a block of code with
BEGIN and END (Pascal), { } (c),
or FOR NEXT (BASIC) does not matter. The main difference
between the languages is
the way pointers are used. While pointers cannot be declared
in BASIC, they can be
implemented. The difference in speed between languages
is not relative, because speed
depends on the compiler used. The direct translation instructions
in C are superficial
because a good compiler can optimize and create the same effect.
About the author:
I am a freshman at the University of Central Florida studying
computer science.
I have experience programming in MS-DOS with QBasic, QB 4.5,
Turbo C, Turbo
Pascal, and 16-bit assembly (8086). I use Java primarily
now, because I like object
oriented programming, and the reasons that Java was created.
On the side, I have to
learn it for my computer science class : ). I was a friend
of the president of VirtuaSoft
while in high school. We went to the programming club
(about 8 students of 2200 in the
school were in the club) and math club together. We exchanged
code and ideas freely,
and I learned a lot from him. I hope he can say the same
thing : ).
--------------------
(The names BASIC, Pascal, and C refer to the ANSI definitions
of these languages.)
Editor's note: Assembly language
also has pointers. :)
Back