OO BASIC or "B++"?
- From: "SteveB" <steve.bush@xxxxxxxxxx>
- Date: 27 Jun 2006 07:45:10 -0700
Dear All,
I have been working on a strategy to retain the flavour of MV while
moving to mainstream tools like Visual Studio, Eclipse, GNU, CVS etc
for HARD CORE BACK-END BASIC development (not for UI development). I
think I have found a way to use standard C++ with an mv library to
replace BASIC without losing the simplicity of BASIC.
OO TECHNIQUES:
Using C++ provides OO options which are nice. Interestingly it looks
like OO techniques are seeping into various mv basic dialects anyway.
OpenQM has Classes and objects ... and I think D3 has or is getting
them. This makes it conceivable to stay in BASIC to get OO. However
since they will probably have their own IDE for source code debugging
etc and I wont be able to use standard IDE/build tools. Wouldn't it be
nice to single step through some MV BASIC code in say Eclipse or Visual
Studio?
C++/JAVA:
My strategy is to exploit C++'s operator override ability to make it
behave functionally (semantically) like pick basic even if the syntax
is more C-like. A more C-like syntax makes it much easier to wheel in
application programmers to work on the codebase using common build
tools/Ides.
Why C++ not Java? Because Java doesn't allow operator overriding and I
didn't like to go from the BASIC syntax of a=b:c to the syntax of
a=b.cat(c) required by Java. Java cant return results in subroutine
parameters either. I must admit that going C++ instead of java will
seem like a backward step to some. Lack of a GOTO statement makes
conversion of old BASIC to Java more difficult. C++ gives us the option
to have both system programmers *and* application programmers working
in the same IDE/language. I am willing to bet that the core of Java
itself is written in C or C++ plus assembler.
EXAMPLE:
The "MV" in the code sample below declares a C++ object that implements
the semantics of a typical mv type-flexible variable.
NB The "^" character is used for concatenation instead of the usual
pick ":" operator since ":" is used for something else in C++. Using
"^", and sacrificing its normal xor functionality (which has nearly but
not quite the right operator precedence for concat) is a nasty hack.
However, I feel that a dedicated pick-like concat operator is important
for productivity and C's "+" is too ambiguous for application
programmers to use reliably in a dynamically typed environment.
MV a=1;
MV b="2";
(a+b).print();
(a^b).print();
results in
3
12
You might say that this looks like any number of "MV functionality in
other language" tools but the trick here is to provide complete
transparency for all operations not just the famous dynamic array and
file i/o manipulations.
The print function is there to keep old mv hands happy. In fact the
following standard C++ output method also produces the same result
allowing a blending of styles depending on preference.
cout<<a+b;
cout<<a^b;
One of the problems of going C++ is that the opportunity for
application programmers to write obscure code is arguably greater in
C++ than in Basic. Policies limiting application programmers to use
only MV variables,i.e. no native C++ data types, might be a strategy to
control this problem.
IMPLEMENTATION:
I have implemented the main "B++" strategy already, really just the MV
object, and done exhaustive regression testing of all the basic
functions and dynamic array handling, which I coded from scratch.
The C++ systems programming to implement the MV variable/object was
hard work. A more skilled C++ coder will probably find errors in
design. The implementation is probably not very efficient but it can be
refined at leisure if the overall strategy proves worthwhile.
Unicode is perfectly implemented simply because I use standard C++
string library and *not* the primitive zero-terminated cstrings.
PENDING:
Runtime linking of external subroutines as shared objects/dlls instead
of build time linking into monolithic applications.
Design of a C++ syntax to replace the READU|ON ERROR|LOCKED|THEN|ELSE
Basic syntax. Perhaps will use try-catch but this is rather wordy.
I haven't done any db handling code but feel that
read/write/delete/select/index should be done with any traditional mv
db. My objective is to move to standard development tools not to
replace mv db.
Many oconv/iconv patterns have not been implemented yet.
USAGE:
Writing "B++" is supposed to be easy. It is not quite as easy as pure
Basic for the skilled Basic programmer but will feel perfectly
comfortable to people from any C/java style language. You just have to
include the MV.h header and away you go.
Debugging is arguably not quite so easy since the debugger sees an
object instead of a native variable. However, Ides are improving all
the time viz. Visual Studio and Eclipse.
CONVERSION:
I can convert my large Basic codebase into the C++ style using a
decompiler to convert my my op code based object code (plus source code
which is of course available to me) into fully commented C++. Other
people will not find it so easy to convert Basic into "B++".
Gosubs/local subroutines have to be hand converted to have only one
entry point. Inter-routine gotos and return to" are not allowed.
SUPPORT:
If I can interest other people in this project then I will issue the
code under BSD or GPL licence.
SUMMARY:
I realise that I may be in a thin slice of the market here since people
are generally either in the BASIC camp or have made the move into
another language semantically even if they use some mv library to
provide selective mv functionality.
My attempt is to move into another language but retain *all* the
ancient pick semantics e.g. add and concat are *NOT* done by the one
"+" operator. Only this way will I be able to move a large body of code
into another language without exhaustive recoding and debugging. A
change of syntax is just work. A change of the fundamental semantics is
a much harder job. "B++" allows me to retain all the old semantics.
Cheers,
Steve Bush
NEOSYS
.
- Follow-Ups:
- Re: OO BASIC or "B++"?
- From: Anthony Lauder
- Re: OO BASIC or "B++"?
- From: Symeon
- Re: OO BASIC or "B++"?
- Prev by Date: Re: Jane M. Christie joined BlueFinity
- Next by Date: Re: DesignBais - Impressive
- Previous by thread: MV Webring
- Next by thread: Re: OO BASIC or "B++"?
- Index(es):
Relevant Pages
|