Desktop version

Main > Knowledge Base > Best practices > Code conventions > Using 1C:Enterprise script clauses > Expression wrapping rules > Best practices > Code conventions > Using 1C:Enterprise script clauses > Expression wrapping rules > Best practices > Code conventions > Using 1C:Enterprise script clauses > Expression wrapping rules

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 arithmetical expressions as follows:

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:

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:

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.

Next page: Form module event handlers defined in 1C:Enterprise script





© 1C LLC. All rights reserved
1C Company respects the privacy of our customers and visitors
to our Web-site.