The Unofficial GEMBASE Home Page.
Our Coding Standards - Rules For Indentation.


Basics of Layout.

At the simplest, tabs are used to place code at appropriate indentation levels to identify conditional sections or loops. So, form headers and footers are not indented, blocks within forms are indented only by one tab, continuation should, in most cases, be indented a further tab stop, and code within conditional tests such as the IF/ELSE/END_IF structure should be indented again.

Since blocks may be nested to provide what the Forms Editor refers to as "Before" and "After" DML, a block may be indented by more than one tab position to take this into account. Spaces should rarely be used to adjust the indentation. But within Gembase code, spaces should be used to improve the readability of the code.

The following section defines rules we advise considering, and adopting.



Practices to Avoid.

There are a number of frequent, and common mistakes in writing Gembase code, most are caused by a failure to fully understand Gembase DML, in many cases the practice of cutting and pasting sements of code perpetuates these mistakes. Most will be familiar to anyone with some experience of working on existing systems.

Nesting of IF statements.
Nesting IF statements should be kept as simple as possible. In all but the most exceptional cases, it should not be necessary to indent by more than three levels. In these cases, constructs should be re-evaluated, and a simpler solution sought.
Layout of IF statements.
Since several conditions can be tested in a single IF statement, we advise putting each test on a separate line. These tests would be at the same indentation level as the code being conditionally executed, so a blank line should follow to keep this clear and readable.
Single-statement IF statements.
For simplicity, Gembase allows a single statement to be used on the same line as the IF test, to ensure that confusion is kept to a minimum we advise this only be used with the EXIT statement. Where more than one condition is being tested, and the IF statement is on more than one line, then the code should be on a separate line and the END_IF statement used.
Limiting length of Conditional Code.
Constructs such as IF/ELSE/END_IF should be completely contained in a single block. Where a large amount of code is to be conditionally executed, it should be done in a separate form. As an additional rule of thumb, the construct should not exceed a page (say, 50 lines).
Avoiding INPUT/OUTPUT blocks in Conditional Code.
Both INPUT and OUTPUT blocks allow the use of the conditional qualifier, /USE_IF This should be used in preference to placing a block inside a conditional test. Such as the IF or WHILE constructs.
The Infinite WHILE loop.
The WHILE loop is provided to conditionally repeat a section of code. Again, this should be short, or a PERFORM of another form. It is frequently used in the form WHILE (1) and the CONTINUE statement then used to end the loop. CONTINUE should be used for error handling within a loop, and the conditional test on the WHILE statement define the expected conditions for the loop to end. See the following WHILE construct example.



When developing in Gembase, personal preferences will dictate which editor you use, on VMS systems the supplied editors are pretty good, we advise setting the cursor to be bound to the flow of the text, and ensuring the initial indentation of code is done with tabs. For developing on the PC, we recommend P.F.E. (Programmer's File Editor). This has been developed at Lancaster University's Computer Centre by Alan Phillips. It can be downloaded from http://www.lancs.ac.uk/people/cpaap/pfe It is free software, but please read the terms of use. For those of you developing on UNIX - get something better than vi!


Please note that this site is currently under development! Development was started on the 24th of February 1999, and will be an ongoing process. Check back regularly for updates to this site.



Sign our Guestbook.
Guestbook by GuestWorld
View our Guestbook
Make your contribution on our Forum

Provided as a free service by Delphi.
View our site statistics
Site Meter
http://www.sitemeter.com


This page last updated on 28th February 1999.