![]() |
Script Style GuideThere are no absolute rules which define the layout of scripts. Any style which suits the individual and which satisfies the script syntax rules may be used. The style proposed here, as used in the Mailtraq User Guide, is not mandatory therefore, but should prove to be of considerable benefit not just because it promotes clarity and legibility but also because it enables better use to be made of the many script examples which have already been placed in the public domain. Consider the following script:- msg_txt:=openfile("message.txt");postmessage("postmaster","johns", That script consists of three expressions delimited by semicolons. It is syntactically correct and is interpreted correctly by Mailtraq. Excellent it may be as an exercise in obfuscation but it is not only difficult to read but also difficult to debug if errors are encountered. This script style guide attempts to explain how that sample script can be rewritten to make its structure and purpose clear to the user by following a simple set of rules. Functions Variables Operators Script Layout msg_txt := OpenFile("message.txt"); The three major expressions within the script are now shown on separate lines (broken at the ";" expression separator). Lines one and three can now be easily understood but line two contains too much nested information to make its purpose clear and may also be too long for comfortable reading on some systems. The PostMesssage() function takes three parameters and the natural breaks provided by these can be utilised to good effect:- msg_txt := OpenFile("message.txt"); Three items of note. First, the closing right bracket of the PostMesssage() function now appears on its own line at the end of that expression and is aligned in the same column as the start of the PostMesssage() function to better indicate ownership. Second, the first two parameters to the PostMessage() function remain on the first line because they can easily be accommodated. Third, the third parameter is indented from the start column of the PostMesssage() function by two spaces to indicate dependency. The third parameter to the PostMesssage() function contains a While() loop which is not excessively long in this example but it may also usefully be written on multiple lines to better indicate the scope of the While() loop and to add clarity to the script:- msg_txt := OpenFile("message.txt"); Note how the closing bracket of the While() function is again aligned directly under the start of its function name and that the second parameter of the While() loop is also indented to indicate its dependency. It is now possible to debug the syntax of that script more easily, to spot missing brackets, for example, and it can be read, and its purpose understood, with a minimum of effort.
|
![]() |
| ||||||||||
|