|
This is a collection of GuiXT programming style tips. Generally speaking, good programming tradition (see e.g. Brian Kernighan's Programming Style Tips) applies to the writing of GuiXT Scripts and InputScripts as well. GuiXT is not meant to be a full programming language with all its capabilities and its complexity. Nonetheless, since GuiXT scripts and InputScripts deal with complex user interfaces (the SAP transactions) it is a good idea to avoid sloppiness with the scripts. It's not just a question of aesthetics! Completely unreadable code might work very well at first, but later on down the line it will boomerang back, producing much more sweat than you saved initially.
The following recommendations reflect our personal style. Please feel free to send us your own opinions and additional hints. We will incorporate them into this collection if appropriate.
| Topic | Date
/ Examples / Link to comments |
1 Apply
the style guide rules during script development Do
not wait until the end of the project for cleaning up your scripts.
Doing it right from the outset
And it will also avoid a situation where the project ends before you have found the time to polish up your scripts. |
|
| 2
Keep the scripts self-documenting This
does not mean putting comments on each and every statement. On the contrary, the code itself should be understandable
and self-explanatory without comments wherever possible. For example the line
del F[Distribution list number] does not need the comment "Delete Distribution list number". But in cases involving technical names del F[S004-DLISN] it is reasonable to add the comment. And in cases involving absolute coordinates (avoid them if possible), it is a must to add a comment: del #[12,74] // Delete Distribution list number Often it makes sense to add a comment about why we are doing something. This typically precedes a block of code: //
Delete the fields that we moved to the main screen //
Disable input for critical fields if user is not authorized In this way you can structure your script, grouping related statements together. Put a blank line before each logical group, but only one line. |
Last update: July 4, 2004 |
| 3
Use consistent
and reasonable indentation This
applies to a sequence of similar statements and to if/endif
statements. Example:
//
Additional text input fields in case of order change |
Last update: July 4, 2004 |
4
Define appropriate settings for development / test / production
|
Last update: July 4, 2004 |
| 5
Apply a consistent and descriptive naming scheme for your variables
A variable that is used only locally within a range of a few
lines, like a line index, can
have a short name like V[i]. All other variables should have
meaningful names. It often makes sense to start with the
transaction code (capital letters) , an underscore, and a short
descriptive name that uses upper and lower case letters:
Set
V[MM01_MaterialType] "&F[Material
type]" A different convention is to use only lower-case letters after the underscore, and to use an underscore as separator between the words: Set
V[MM01_material_type] "&F[Material
type]" Make a decision on which convention to use and then do not mix up the conventions. When your script deals with several transactions, e.g. MM01, MM02, MM03, define a suitable group identifier (e.g. MM for material master transactions, VA for order entry, change and display): Set
V[MM_MaterialType] "&F[Material
type]" Set
V[VA_Type]
"&F[Order type]" Be extremely careful with the naming of internal status variables. A coding like if V[flag=X] is next to useless when we have to deal with the script again a year later. Instead, if V[MM_MaterialCopyDone=X] makes our work easier. A short comment is reasonable: //
Suppress "Copy" button later on if copy already done |
Last update: July 4, 2004 |
| 6
Avoid the expression "&[xyz]"
Use "&V[xyz]" if you address a variable, and
"&F[xyz]" if you address a screen field. It is then
easier to understand what you are doing. In addition, a statement like
Set V[MM_MaterialType] "&[Material type]" will fail, if you have already set a variable with this name before: Set V[Material Type] "..." GuiXT first looks for a variable with the given name, before looking for the screen field. The naming conventions in 5 exclude such problems, but they can nonetheless crop up during script development. Unless you really enjoy endlessly searching for such errors, avoid them by using the explicit notation at all times. Besides, the "&F[name]" notation is faster than "&[name]", since the variable table lookup is not required. |
Last update: July 4, 2004 |
| 7 Minimize using your own status variables It is always better to make decisions based on fields on the screen, or on transaction code, GUI status, current tab page. The fewer status variables you have, the fewer problems you have in keeping everything in sync. If you cannot avoid using your own status variables, add some text to explains where you set and reset the variable, where it is needed and which states are possible. | Last update: July 4, 2004 |