Expression wrapping rules





This article describes the standards that apply to expression wrapping rules. All of the listed recommendations are mandatory unless noted otherwise.

1. We recommend that you wrap lines longer than 120 characters, except the lines where wrapping is impossible.

2. Wrap long ariphmetical expressions as follows:

  • a single line can contain multiple operands;
  • put ariphmetical operators to the beginning of line (not to the end of the previous line);
  • precede each operand that opens a new line with a standard indent, or align it with the first operand;
  • precede each parameter that opens a new line with a standard indent, or align it with the first parameter.

Example:

Message.Text = String(- SelectionDetailRecords.QuantityBalance) 
               + " units shortage for """ + SelectionDetailRecords.Material
               + """ with """ + SelectionDetailRecords.PropertySet
               + """ property set.";

or

Message.Text = String(- SelectionDetailRecords.QuantityBalance) 
    + " units shortage for """ + SelectionDetailRecords.Material
    + """ with """ + SelectionDetailRecords.PropertySet
    + """ property set.";

3. Wrap long string constants using the special wrapping character at the beginning of each new line:

Query = New Query(
    "SELECT ALLOWED
    | ItemNotes.NotesCount AS NotesCount
    |FROM
    | InformationRegister.ItemNotes AS ItemNotes
    |WHERE
    | ItemNotes.Item = &Item");

or

WarningText = StringFunctionsClientServer.SubstituteParametersInString(
    NStr("en = 'The address classifier is up-to-date.
               |Address data as of %1 is loaded to the application.'"),
    Format(LatestClassifierUpdateDate, "DLF=D"));
DoMessageBox(WarningText);

Do not wrap lines that contain user messages (the UserMessage object).

4. Wrap procedure, function, or method parameters as follows:

  • precede each parameter that opens a new line with a standard indent, or align it with the first parameter;
  • put the last parameter, the closing parenthesis, and the operator separator ";" to a single line;
  • the formatting provided by the autoformat feature in Designer is also acceptable (see paragraph 5 later in this article).

Example:

DocumentNames = New ValueList;
DocumentNames.Add(Metadata.Documents.SalesInvoice.Name,
                  Metadata.Documents.SalesInvoice.Synonym);
DocumentNames.Add(Metadata.Documents.PurchaseInvoice.Name,
                  Metadata.Documents.PurchaseInvoice.Synonym);

or

DocumentNames = New ValueList;
DocumentNames.Add(Metadata.Documents.SalesInvoice.Name,
    Metadata.Documents.SalesInvoice.Synonym);
DocumentNames.Add(Metadata.Documents.PurchaseInvoice.Name,
    Metadata.Documents.PurchaseInvoice.Synonym);

5. Wrap complex logical conditions within If...ElsIf...EndIf as follows:

  • if a line is longer than 120 characters, put each elementary logical condition to a new line;
  • put logical operators (AND, OR) to the beginning of line (not to the end of the previous line);
  • precede each condition with a standard indent, or align it with the first condition (we recommend that you use spaces to set an indent);
  • Put the last condition and the Then keyword to the same line.

Example:

If (OperationType = Enums.OperationTypeReceipt.RetailReceipt)
    OR (OperationType = Enums.OperationTypesReceipt.RetailCommissionReceipt) Then
    Return True;
EndIf

or

If ((ModuleStructure[Index].Block = Enums.ModuleBlockTypes.ProcedureTitle)
    OR(ModuleStructure[Index].Block = Enums.ModuleBlockTypes.FunctionTitle))
    AND(Find(Upper(Modulestructure[Index].Text), BlockKey)>0) Then

6. To have your script comply with the listed recommendations, in addition to the automatic module text formatting when you type, you can format any text that you wrote earlier. To format a text block, select it and then, on the Text menu, point to Block and click Format. The text editor parses the module text and formats it by adding a tab indent to each nested clause, regardless of the original indents (leading spaces). Empty lines also gain indents according to their nesting levels.


Comments
0
Add comment