Line wrapping
Scope: managed applications, mobile applications, and ordinary applications.
1. Wrap a line if its length exceeds 120 characters. You can keep a single line with more than 120 characters if it is required by the code.
2. To wrap arithmetic 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 1:
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.NoteCount AS NoteCount
|FROM
| InformationRegister.SubjectNotes AS SubjectNotes
|WHERE
| SubjectNotes.Subject = &Subject";
Example 2:
WarningText = StringFunctionsClientServer.SubstituteParametersToString(
NStr("en = 'No address classifier update is needed.
|The last update date is %1.'"),
Format(LastARCAUpdateDate, "DLF=D"));
ShowMessageBox(,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 arithmetic expressions (see item 2). Example:
FilterFields = "Product,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 1:
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:
DocumentNames = New ValueList;
DocumentNames.Add(Metadata.Documents.NoteExpenseLine.Name,
Metadata.Documents.NoteExpenseLine.Synonym);
DocumentNames.Add(Metadata.Documents.CashVoucher.Name,
Metadata.Documents.CashVoucher.Synonym);
5. To wrap complex logical statements—If...ElsIf...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 that you use spaces.
Examples:
If (OperationKind = Enums.OperationKindsInventoryReceipt.ReceiptRetail)
OR (OperationKind = Enums.OperationKindsInventoryReceipt.ReceiptRetailCommission) Then
Return True;
EndIf;
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 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.