|
Proposal for indentation rules in nested commands to drastically improve readability
|
ShowTable of Contents
Introduction
Formula language programming has a tendency to create horrificly unreadable formula code. The designer is not very helpful in (semi) automatic indentation adding to that issue. Still, it is still often the most powerful, fastest and most security abiding way of getting things done. Part of the issue is legacy: in older versions it was not possible to break lines or use tabs. Later on, more nested commands were added (i.e. @For) adding to deep and often unreadable nesting.
Proposed coding rules
This document proposes simple coding style rules for @Formula language. It is incomplete and informally written.
-
Every opening parenthesis of a control statement (like @If, @For, @Do, etc) is followed by a newline and a new indentation level;
-
Indentation is done through the use of tabs;
-
The corresponding closing parenthesis is on a new line and outdented, usually, but not always followed by the closing semicolon. Caveat: no semicolon on the previous line!;
-
Special case for @If: all even arguments get their own extra indentation, making them easily identifiable to their corresponding condition;
-
Special case for @For: keep arguments 1, 2 and 3 on one line, as those are controlling the loop.
Examples
@If(
choice = 1;
@Setfield("Approved";"Yes");
choice = 2;
@Setfield("Approved";"No");
@Return("")
);
@If(
choice = 1;
@Do(
@Setfield("Approved";"Yes");
@Setfield("ApprovedBy";@Username)
);
@Return("")
);
@For(
n := 1; n <= 10; n++;
result := result + array [n]
);
Conclusion
While this coding style created far more lines than free coding, the end result is extremely readable and easily nested. |