1Ci Support Help Center home page
Submit a request
Sign in
  1. 1Ci Support
  2. 1C:Enterprise Development Standards
  3. Code conventions
  4. Using 1C:Enterprise language structures

Moving expressions

  • Using 1C:Enterprise language structures
    • General requirements to creating 1C:Enterprise language structures
    • Moving expressions
    • Using duplicate code
    • Using compilation directives and preprocessor commands
    • Defining variable value type
    • Getting objects metadata
    • Form module event handlers attached in code
    • Using global variables in modules
    • Local variables pre-initializing
    • Using event log
See more

Scope: managed applications, mobile applications, and ordinary applications.

1. Wrap a line if its length exceeds 120 characters. You can keep single line with more than 120 characters if wrapping is impossible or has negative impact on the code readability.

2. To wrap expressions, stick to the following recommendations: 

  • A single line can contain several operands. 
  • Place the last operator at the start of the continuation line. 
  • Continuation lines must be indented 1) at the first operand's level or 2) by one level more than the initial line.

Example:

DocumentTotal = FullPrice
                + ManualDiscountAmount
                + AutomaticDiscountAmount;

Example 2:

DocumentTotal = FullPrice
    + ManualDiscountAmount
    + AutomaticDiscountAmount;

3.1 To wrap string constants, use vertical bar. Example 1:

  QueryText =
  "SELECT ALLOWED
  | SubjectNotes.NumberoOfNotes AS NumberOfNotes
  |FROM
  | InformationRegister.SubjectNotes AS SubjectNotes
  |WHERE
  | SubjectNotes.Subject = &Subject";

Example 2:

WarningText = StringFunctionsClientServer.SubstituteParametersToString(
  NStr("en = 'No address classifier update is needed.
             |The address data from %1 is up-to-date.'"),
  Format(LastARCAUpdateDate, "DLF=D"));
ShowWarning(,WarningText);

Do not wrap text inside UserMessage.

3.2. In general, when you concatenate strings, put the plus sign at the start of the continuation line, like you do for expressions (see item 2). Example:

FilterFields = "Products,Characteristic,Warehouse"
   + AdditionalFilterFields;

3.3. When you concatenate a multiple-line string, for better code readability, it is acceptable to place plus signs at the end of the lines. Example:

QueryText = QueryText +
"SELECT
| Products.Ref AS Ref
|FROM
| Catalog.Products AS Products";

4. To wrap parameters of procedures, functions, and methods, stick to the following recommendations: 

  • Continuation lines must be indented 1) at the first parameter's level or 2) by one level more than the initial line. 
  • Place the closing parenthesis and semicolon on the last parameter's line.
  • It is acceptable to use auto-formatting (see item 6).

Example:

DocumentNames = New ValueList;
DocumentNames.Add(Metadata.Documents.NoteExpenseLine.Name, 
                         Metadata.Documents.NoteExpenseLine.Synonym);
DocumentNames.Add(Metadata.Documents.CashVoucher.Name, 
                         Metadata.Documents.CashVoucher.Synonym);

Example 2:

DocumentsNames = New ValueList;
DocumentsNames.Add(Metadata.Documents.NoteExpenseLine.Name, 
                         Metadata.Documents.NoteExpenseLine.Synonym);
DocumentsNames.Add(Metadata.Documents.CashVoucher.Name, 
                         Metadata.Documents.CashVoucher.Synonym);

5. To wrap complex logical statements—If...ElseIf...EndIf—stick to the following recommendations: 

  • Wrap a conditional expression if its length exceeds 120 characters. 
  • Place logical operators AND and OR at the beginning of the continuation line. 
  • Each logical operator must be indented 1) at the first operator's level or 2) by one level more than the initial line. To indent lines, it is recommended to use spaces.

Examples:

If (OperationKind = Enums.OperationsKindsInventoryReceipt.ReceiptRetail)
  OR (OperationKind = Enums.OperationsKindsInventoryReceipt.ReceiptRetailCommission),
  Return True;
EndIf;

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

6. To format existing code (except for module's code), employ auto-formatting. To format a block of code, select the text. Then, in the menu, select Text — Block — Format. The tool will analyze the code, reset the initial formatting, and indent the lines in accordance with the above-mentioned recommendations. Empty lines will be indented with tabs to keep the indentation of the code block consistent.

To auto-wrap lines, run the data processor.

© 2020 1C INTERNATIONAL LLC www.1Ci.com Support policy