Skip to content

Language differences

Wang Renxin edited this page Jul 21, 2018 · 6 revisions

Overview

The BASIC8 programming language is unique, it's based on an open source scripting interpreter, which is aimed to be a glue on top of native languages. In this page I'll explain some differences between BASIC8 and some other programming languages, and ideas in common.

8-bit BASIC C C# BASIC8
Phases interpreting compiling, linking, running compiling to MSIL, compiling to machine code, running parsing, running
Typing static, strong static, weak static, strong dynamic, strong
Passing by value value, reference value, reference value, reference
Has pointer no, but can PEEK&POKE yes, you take all the risks unsafe, MS guarantees you won't hurt yourself BASIC8 guarantees you won't hurt yourself
Allocator raw malloc, free managed by GC managed by GC
Running slow fast fast slow
Development limited by onscreen editor limited by low-level abstraction quick quick
Dependency the same BASIC computer to the development machine no .NET desktop player, html player

Comparing to the C family

It's not difficult to tell that the code structure in the C language family is organized by { ... }; the BASIC family uses more English less punctuation marks. But beneath the surface, memory in C is referenced/dereferenced by &/*, accessed by ->/., which brings fine grain, but requires more time in practice to manage. There are both value and referenced types in BASIC8, but you won't see that many different idioms aside variables, data types and valid operations are determined at runtime instead. This makes the major difference that you think way different to solve problems. All the purposes in C are for running fast as possible and taking full control of hardware, so the designers of C have entitled the users of this language to allocate/free memory precisely to bytes and accurately manipulate each allocated piece, but you have to know what's exactly going on in "memory" as a C developer. An important goal of a Fantasy Computer language is making quick prototyping and rapid development iteration, so it's more sensitive to compiling/parsing time, and helping you thinking higher-level to focus on creativity. It delays a part of the computing till runtime, which makes it not so fast comparing to C, but enforces to get one's ideas into shape. BASIC8 itself is programmed in C/C++ to encapsule compute-intensive tasks, and exposes functions and libraries, to minimize your opportunity to worry about low-level matters.

Comparing to 8-bit BASIC

It's also different from 8-bit BASIC. The commands in an 8-bit BASIC are more or less assembly aliases, it is also powerful and fun, I don't mean it's bad, but I prefer making BASIC8 more productive. BASIC8 is not inventing anything new, in fact some concepts such as LAMBDA, CLASS and other facilities existed for decades already. But it's fair to claim it to be "modern", because it offers something that 8-bit ones don't, and shares common concepts with other modern languages.

You'll find keywords and syntax in common between 8-bit BASIC and the new BASIC8, but the latter is not line-number based and offers some newer concepts (such as DEF routines, CLASS, LAMBDA, COROUTINE, LIST, DICT, etc.) than the former. BASIC8 is almost a superset of the 8-bit ones, for instance to port the following line-number based code:

10 INPUT "What is your name: "; U$
20 PRINT "Hello "; U$
30 INPUT "How many stars do you want: "; N
40 S$ = ""
50 FOR I = 1 TO N
60 S$ = S$ + "*"
70 NEXT I
80 PRINT S$
90 INPUT "Do you want more stars? "; A$
100 IF LEN(A$) = 0 THEN GOTO 90
110 A$ = LEFT$(A$, 1)
120 IF A$ = "Y" OR A$ = "y" THEN GOTO 30
130 PRINT "Goodbye "; U$
140 END

By removing the line numbers (using GOTO LABEL instead) and making some other adaptions, it runs perfectly in BASIC8 with:

SET_OUTPUT_VISIBLE(TRUE)
INPUT "What is your name: ", U$
PRINT "Hello ", U$;
LABEL30:
INPUT "How many stars do you want: ", N
S$ = ""
FOR I = 1 TO N
S$ = S$ + "*"
NEXT I
PRINT S$;
LABEL90:
INPUT "Do you want more stars? ", A$
PRINT ;
IF LEN(A$) = 0 THEN GOTO LABEL90
A$ = LEFT(A$, 1)
IF A$ = "Y" OR A$ = "y" THEN GOTO LABEL30
PRINT "Goodbye ", U$;
END

What makes big difference is that BASIC8 is designed for graphics mode, and only offers a pseudo terminal mode with a Workshop program. And games in graphics mode often run in an infinite-loop pattern that refreshes the screen dozens of times per second, other than top-down flows.

Ideas in common

Actually all programming languages are abstractions at some levels, and encapsule lower-level facilities. If you take a look at any hardware instruction set, assembly, 8-bit BASIC, C, C# (or MSIL per se), BASIC8, or LISP, Haskell, etc, they look more or less different from each other. But programming is all about organizing some data, and defining functionality and relation of them efficiently.