DBPro Coding Standard
This topic has been raised before and, failed drastically. From what I remember it was through trying to encompass all developers to adopt a single unified coding style without knowing the context in which the code was to be used. IE. a single inflexible coding standard does not suit everybody - especially in a predominantly beginner-orientated language. As such I shall approach this topic treading lightly, I aim to write this from a neutral and unbiased viewpoint, but the whole topic should be taken with a pinch of salt - please think things through before stepping in to reply, taking consideration of both sides of the argument. I am hoping that this topic will serve its purpose as a well structured debate as to the pros and cons of having a coding standard, and what its introduction (if any) to the community would entail.
To begin with I think it would be useful to take a step back and take a look at some of the advantages and disadvantages of the current DBPro language.
Pros:
-Mature and (fairly) stable IDE
-Efficient rapid prototyping language
-Easily accessible to newcomers
-[Syntactically lax compiler] (Read: Flexible and forgiving compiler)
-Simplistic and logical syntax
-Expandability with third party libraries
-Sufficient number of data types
Cons:
-Poorly (for the most part) written documentation
-Inconsistent naming conventions across language
-[Syntactically lax compiler]
-Low portability to other languages
-Array of different coding styles leads to confusion when studied externally (common to all languages)
-Poor integration with third party libraries (due to lack of standard naming conventions)
-Inefficiently-long function names
-Character encoding (tabs) incompatibility between IDEs
-Lack of operators
It should be made very clear now that the majority of the disadvantages listed are not of great concern to casual users / beginners for the sole reason that they are not likely to stumble upon any of these issues until a point such that they are ready to move on to another more advanced language.
But, for those that do wish to progress from DBPro onto such languages it is a relatively difficult process due to suddenly having compilers which are very strict, people who rely on the cleanliness and readability of your code, and the need to port the codebase to other languages and / or platforms. In short the lax coding standards of DBPro set you up in a very bad position to progress onwards. As such, collaborative projects done in DBPro are made infinitely more complex by the fact that each individual will have a different (not necessarily bad) style of coding - meaning that incompatibility manifests itself because the code will simply not work together in harmony as intended. For the individual it means that finding a foothold to progress from BASIC to industry-standard becomes a great challenge.
A coding standard would have many benefits as I shall now outline. DBPro is often used for prototyping, with the final project being developed in a lower-level language such as C or Java. While such languages have many syntactical differences, they are far more similar than the vast difference between BASIC and C. Thus porting the codebase of a project from BASIC to C becomes a monumental undertaking (almost a complete re-write is needed) - something which would not be necessary if the project were to be ported from C to Java. Ironically it is possible to code in a style which is fairly similar to C (or any other such language). The code sample bellow showcases the similarities:
REM CODE IN BASIC
function myFunc(myVar as integer)
testObject as integer
if (myVar)
inc(testObject, myVar)
loadObject("object.dbo", testObject)
deleteObject(testObject)
endif
endfunction myVar
/* CODE IN C
int myFunc(int myVar) {
int testObject = 0;
if (myVar) {
testObject += myVar;
loadObject("object.dbo", testObject);
deleteObject(testObject);
}
return myVar;
}
The two examples listed are nearly identical, where the first was copied from the second and then the relevant changes made to get it to a state where it would compiled under C - the changes taking about 30 seconds or so. Compared to if our original code was like this:
Rem Code in basic
Function My_Function(My_Variable)
If My_Variable=1
Test_Object = Test_Object + My_Variable
Load Object("Object.dbo",Test_Object)
Delete Object(Test_Object)
Endif
Endfunction My_Variable
Converting such code to C would be so inefficient it would be quicker to just rewrite it from scratch. The example also showcases perfectly how lax the compiler is: variables do not have to be defined before use, there are multiple ways to construct an
if statement, an irregular number of spaces is used for tabbing than standard etc. etc. Having standards is key to maintaing bug-free and easily portable code.
One thing to note is that I used functions such as
loadObject() as opposed to
Load Object. This is both on the grounds of portability and consistent naming conventions - I would propose a wrapper to truncate all DBPro functions removing any spacing, adding brackets and in lowerCamelCase.
I do not want to overwhelm anyone so I think I shall cut my introduction there. But the point I would like to raise is the sheer usefulness of at least having some kind of standard in place:
-Portable code
-Improved maintainability and readability
-Simplifies transition to lower-level languages
-Instills good programming etiquette
-Greater stability among collaborative code
-Showcases professionalism
Many thanks for reading and I would be very eager to hear people's opinions.
Regards,
Mike
[EDIT]
Just found the previous attempt to introduce a standard
here. I hasten to add that what I propose is a community effort - the previous attempt all seemed very one-sided. I feel that those rules proposed digressed from the whole point of creating a standard because many of the points suggested were simply very irregular ways of doing things. Finally I do not at all like the way it was named a "ruleset" - rules define a singular and strict methodology that is compulsory to follow - a standard is an optional set of guidelines with the intention of bringing improvements about.