formatted nav patterns 2 to 4

This commit is contained in:
christianbraeunlich 2022-02-05 19:44:44 +01:00
parent 2fad891a77
commit f1f4aab1d7
55 changed files with 788 additions and 506 deletions

View file

@ -2,15 +2,21 @@
title = "Begin as an 'After Word'"
weight = 230
+++
When BEGIN follows THEN, ELSE, DO, it should be on the same line, preceded by one space character. Bad code
When BEGIN follows THEN, ELSE, DO, it should be on the same line, preceded by one space character.
IF ICPartnerRefType = ICPartnerRefType::"Common Item No." THEN
Bad code
```al
IF ICPartnerRefType = ICPartnerRefType::"Common Item No." THEN
BEGIN
...
END;
END;
```
Good code
IF ICPartnerRefType = ICPartnerRefType::"Common Item No." THEN BEGIN
```
IF ICPartnerRefType = ICPartnerRefType::"Common Item No." THEN BEGIN
...
END;
END;
```

View file

@ -3,52 +3,67 @@ title = "Begin-End - Compound Only"
weight = 240
+++
Only use BEGIN..END to enclose compound statements.
Bad code
IF FINDSET THEN BEGIN
```al
IF FINDSET THEN BEGIN
REPEAT
...
...
UNTIL NEXT = 0;
END;
END;
```
Good code
IF FINDSET THEN
```al
IF FINDSET THEN
REPEAT
...
...
UNTIL NEXT = 0;
```
Bad code
IF IsAssemblyOutputLine THEN BEGIN
```al
IF IsAssemblyOutputLine THEN BEGIN
TESTFIELD("Order Line No.",0);
END;
END;
```
Good code
IF IsAssemblyOutputLine THEN
```al
IF IsAssemblyOutputLine THEN
TESTFIELD("Order Line No.",0);
```
Bad code
IF FINDSET THEN
```al
IF FINDSET THEN
REPEAT
BEGIN
...
END;
BEGIN
...
END;
UNTIL NEXT = 0;
```
Good code
IF FINDSET THEN
```al
IF FINDSET THEN
REPEAT
...
...
UNTIL NEXT = 0;
```
Exception
// Except for this case
IF X THEN BEGIN
```al
// Except for this case
IF X THEN BEGIN
IF Y THEN
DO SOMETHING;
END ELSE (not X)
DO SOMETHING;
END ELSE (not X)
```

View file

@ -2,14 +2,20 @@
title = "Binary Operator to Start Line"
weight = 250
+++
Do not start a line with a binary operator. Bad code
Do not start a line with a binary operator.
"Quantity to Ship" :=
Bad code
```al
"Quantity to Ship" :=
Quantity
- "Quantity Shipped"
```
Good code
"Quantity to Ship" :=
```al
"Quantity to Ship" :=
Quantity -
"Quantity Shipped"
```

View file

@ -2,30 +2,43 @@
title = "Blank Lines"
weight = 260
+++
Do not use blank lines at the beginning or end of any functions, after BEGIN, before END, or inside multiline expressions. Bad code
PROCEDURE MATRIX\_OnDrillDown@1133(MATRIX\_ColumnOrdinal : Integer);
BEGIN
SetupDrillDownCol(MATRIX\_ColumnOrdinal);
DrillDown(FALSE,ValueType);
END;
Good code
PROCEDURE MATRIX\_OnDrillDown@1133(MATRIX\_ColumnOrdinal : Integer);
BEGIN
SetupDrillDownCol(MATRIX\_ColumnOrdinal);
DrillDown(FALSE,ValueType);
END;
Do not use blank lines at the beginning or end of any functions, after BEGIN, before END, or inside multiline expressions.
Bad code
IF NameIsValid AND
Name2IsValid
THEN
```al
PROCEDURE MATRIX_OnDrillDown@1133(MATRIX_ColumnOrdinal : Integer);
BEGIN
SetupDrillDownCol(MATRIX_ColumnOrdinal);
DrillDown(FALSE,ValueType);
END;
```
Good code
IF NameIsValid AND
```al
PROCEDURE MATRIX_OnDrillDown@1133(MATRIX_ColumnOrdinal : Integer);
BEGIN
SetupDrillDownCol(MATRIX_ColumnOrdinal);
DrillDown(FALSE,ValueType);
END;
```
Bad code
```al
IF NameIsValid AND
Name2IsValid
THEN
THEN
```
Good code
```al
IF NameIsValid AND
Name2IsValid
THEN
```

View file

@ -2,16 +2,22 @@
title = "CASE Action"
weight = 310
+++
A CASE action should start on a line after the possibility. Bad code
A CASE action should start on a line after the possibility.
CASE Letter OF
Bad code
```al
CASE Letter OF
'A': Letter2 := '10';
'B': Letter2 := '11';
```
Good code
CASE Letter OF
```al
CASE Letter OF
'A':
Letter2 := '10';
Letter2 := '10';
'B':
Letter2 := '11';
Letter2 := '11';
```

View file

@ -2,14 +2,20 @@
title = "Colon usage in CASE"
weight = 340
+++
The last possibility on a CASE statement must be immediately followed by a colon. Bad code
The last possibility on a CASE statement must be immediately followed by a colon.
CASE DimOption OF
Bad code
```al
CASE DimOption OF
DimOption::"Global Dimension 1" :
DimValue."Dimension Code" := GLSetup."Global Dimension 1 Code";
DimValue."Dimension Code" := GLSetup."Global Dimension 1 Code";
```
Good code
CASE DimOption OF
```al
CASE DimOption OF
DimOption::"Global Dimension 1":
DimValue."Dimension Code" := GLSetup."Global Dimension 1 Code";
DimValue."Dimension Code" := GLSetup."Global Dimension 1 Code";
```

View file

@ -2,38 +2,45 @@
title = "Comments inside Curly Brackets"
weight = 350
+++
Never use curly bracket comments. During development, the "Block comment" functionality can be used instead. However, in production code, block comments are not recommended. Bad code
Never use curly bracket comments. During development, the "Block comment" functionality can be used instead. However, in production code, block comments are not recommended.
PeriodTxt: {Period}
Bad code
```al
PeriodTxt: {Period}
```
Good code
PeriodTxt: // Period
```al
PeriodTxt: // Period
```
Bad code
PROCEDURE MATRIX\_OnAfterGetRecord@10(MATRIX\_ColumnOrdinal : Integer);
BEGIN
```al
PROCEDURE MATRIX_OnAfterGetRecord@10(MATRIX_ColumnOrdinal : Integer);
BEGIN
{
IF ShowColumnName THEN
MatrixHeader := MatrixRecords\[MATRIX\_ColumnOrdinal\].Name
MatrixHeader := MatrixRecords[MATRIX_ColumnOrdinal].Name
ELSE
MatrixHeader := MatrixRecords\[MATRIX\_ColumnOrdinal\].Code;
MatrixHeader := MatrixRecords[MATRIX_ColumnOrdinal].Code;
}
MatrixRecord := MatrixRecords\[MATRIX\_ColumnOrdinal\];
MatrixRecord := MatrixRecords[MATRIX_ColumnOrdinal];
AnalysisValue := CalcAmt(ValueType,TRUE);
MATRIX\_CellData\[MATRIX\_ColumnOrdinal\] := AnalysisValue;
END;
MATRIX_CellData[MATRIX_ColumnOrdinal] := AnalysisValue;
END;
```
Good code
PROCEDURE MATRIX\_OnAfterGetRecord@10(MATRIX\_ColumnOrdinal : Integer);
BEGIN
MatrixRecord := MatrixRecords\[MATRIX\_ColumnOrdinal\];
```al
PROCEDURE MATRIX_OnAfterGetRecord@10(MATRIX_ColumnOrdinal : Integer);
BEGIN
MatrixRecord := MatrixRecords[MATRIX_ColumnOrdinal];
AnalysisValue := CalcAmt(ValueType,TRUE);
MATRIX\_CellData\[MATRIX\_ColumnOrdinal\] := AnalysisValue;
END;
MATRIX_CellData[MATRIX_ColumnOrdinal] := AnalysisValue;
END;
```

View file

@ -3,12 +3,16 @@ title = "Comment Spacing"
weight = 360
+++
Always start comments with // followed by one space character.
Bad code
RowNo += 1000; //Move way below the budget
```al
RowNo += 1000; //Move way below the budget
```
Good code
RowNo += 1000; // Move way below the budget
```al
RowNo += 1000; // Move way below the budget
```

View file

@ -3,19 +3,24 @@ title = "END ELSE Pair"
weight = 540
+++
The END ELSE pair should always appear on the same line.
Bad code
IF OppEntry.FIND('-') THEN
```al
IF OppEntry.FIND('-') THEN
IF SalesCycleStage.FIND('-') THEN BEGIN
...
...
END
ELSE
ELSE
...
```
Good code
IF OppEntry.FIND('-') THEN
```al
IF OppEntry.FIND('-') THEN
IF SalesCycleStage.FIND('-') THEN BEGIN
...
END ELSE
...
END ELSE
...
```

View file

@ -3,82 +3,110 @@ title = "Indentation"
weight = 650
+++
In general, use an indentation of two space characters. Logical expressions in the IF, WHILE, and UNTIL parts are indented at least 3, 6, and 6 spaces respectively.
Bad code
IF GLSetup."Unrealized VAT" OR
(GLSetup."Prepayment Unrealized VAT" AND NewCVLedgEntryBuf.Prepayment)
Good code
IF GLSetup."Unrealized VAT" OR
```al
IF GLSetup."Unrealized VAT" OR
(GLSetup."Prepayment Unrealized VAT" AND NewCVLedgEntryBuf.Prepayment)
```
Good code
```al
IF GLSetup."Unrealized VAT" OR
(GLSetup."Prepayment Unrealized VAT" AND NewCVLedgEntryBuf.Prepayment)
```
Bad code
IF GenJnlLine."Account No." <\> ICPartner.Code THEN
ICPartner.GET("Account No.");
IF GenJnlLine.Amount \> 0 THEN BEGIN
```al
IF GenJnlLine."Account No." <> ICPartner.Code THEN
ICPartner.GET("Account No.");
IF GenJnlLine.Amount \> 0 THEN BEGIN
...
```
Good code
IF GenJnlLine."Account No." <\> ICPartner.Code THEN
ICPartner.GET("Account No.");
IF GenJnlLine.Amount \> 0 THEN BEGIN
...
```al
IF GenJnlLine."Account No." <> ICPartner.Code THEN
ICPartner.GET("Account No.");
IF GenJnlLine.Amount > 0 THEN BEGIN
...
```
Bad code
Dialog.OPEN(WindowTxt +
'@1@@@@@@@@@@@@@@@@@@@@@@@');
```al
Dialog.OPEN(WindowTxt +
'@1@@@@@@@@@@@@@@@@@@@@@@@');
```
Good code
Dialog.OPEN(
```al
Dialog.OPEN(
WindowTxt +
'@1@@@@@@@@@@@@@@@@@@@@@@@');
```
Bad code
TempOldCustLedgEntry.DELETE;
// Find the next old entry for application of the new entry
```al
TempOldCustLedgEntry.DELETE;
// Find the next old entry for application of the new entry
```
Good code
TempOldCustLedgEntry.DELETE;
// Find the next old entry for application of the new entry
```al
TempOldCustLedgEntry.DELETE;
// Find the next old entry for application of the new entry
```
Bad code
IF NOT ("Applies-to Doc. Type" IN
\["Applies-to Doc. Type"::Receipt,
"Applies-to Doc. Type"::"Return Shipment"\])
```al
IF NOT ("Applies-to Doc. Type" IN
["Applies-to Doc. Type"::Receipt,
"Applies-to Doc. Type"::"Return Shipment"])
```
Good code
IF NOT ("Applies-to Doc. Type" IN
\["Applies-to Doc. Type"::Receipt,
"Applies-to Doc. Type"::"Return Shipment"\])
```al
IF NOT ("Applies-to Doc. Type" IN
["Applies-to Doc. Type"::Receipt,
"Applies-to Doc. Type"::"Return Shipment"])
```
Bad code
WHILE (RemAmt \> 0) OR
(RemAmtLCY \> 0)
DO
```al
WHILE (RemAmt > 0) OR
(RemAmtLCY > 0)
DO
```
Good code
WHILE (RemAmt \> 0) OR
(RemAmtLCY \> 0)
DO
```al
WHILE (RemAmt > 0) OR
(RemAmtLCY > 0)
DO
```
Bad code
UNTIL (RemAmt \> 0) AND
(RemAmtLCY \> 0);
```al
UNTIL (RemAmt > 0) AND
(RemAmtLCY > 0);
```
Good code
UNTIL (RemAmt \> 0) AND
(RemAmtLCY \> 0)
```al
UNTIL (RemAmt > 0) AND
(RemAmtLCY > 0)
```

View file

@ -2,13 +2,19 @@
title = "Keyword Pairs - Indentation"
weight = 730
+++
The IF..THEN pair, WHILE..DO pair, and FOR..DO pair must appear on the same line or the same level of indentation. Bad code
The IF..THEN pair, WHILE..DO pair, and FOR..DO pair must appear on the same line or the same level of indentation.
IF (x = y) AND
(a = b) THEN
Bad code
```al
IF (x = y) AND
(a = b) THEN
```
Good code
IF (x = y) AND
(a = b)
THEN
```al
IF (x = y) AND
(a = b)
THEN
```

View file

@ -2,19 +2,25 @@
title = "Line Start Keywords"
weight = 740
+++
The END, IF, REPEAT, FOR, WHILE, ELSE and CASE statement should always start a line. Bad code
The END, IF, REPEAT, FOR, WHILE, ELSE and CASE statement should always start a line.
IF IsContactName THEN ValidateContactName
ELSE IF IsSalespersonCode THEN ValidateSalespersonCode
Bad code
```al
IF IsContactName THEN ValidateContactName
ELSE IF IsSalespersonCode THEN ValidateSalespersonCode
ELSE IF IsSalesCycleCode THEN ValidatSalesCycleCode;
```
Good code
IF IsContactName THEN
ValidateContactName
ELSE
IF IsSalespersonCode THEN
```al
IF IsContactName THEN
ValidateContactName
ELSE
IF IsSalespersonCode THEN
ValidateSalespersonCode
ELSE
ELSE
IF IsSalesCycleCode THEN
ValidatSalesCycleCode;
ValidatSalesCycleCode;
```

View file

@ -3,13 +3,18 @@ title = "Lonely Repeat"
weight = 760
+++
The REPEAT statement should always be alone on a line.
Bad code
IF ReservEntry.FINDSET THEN REPEAT
```al
IF ReservEntry.FINDSET THEN REPEAT
```
Good code
IF ReservEntry.FINDSET THEN
REPEAT
```al
IF ReservEntry.FINDSET THEN
REPEAT
```

View file

@ -3,12 +3,16 @@ title = "Named Invocations"
weight = 830
+++
When calling an object statically use the name, not the number
Bad code
PAGE.RUNMODAL(525,SalesShptLine)
```al
PAGE.RUNMODAL(525,SalesShptLine)
```
Good code
PAGE.RUNMODAL(PAGE::"Posted Sales Shipment Lines",SalesShptLine)
```al
PAGE.RUNMODAL(PAGE::"Posted Sales Shipment Lines",SalesShptLine)
```

View file

@ -3,19 +3,24 @@ title = "Nested WITHs"
weight = 850
+++
Do not nest WITHs that reference different types of objects.
Bad code
WITH PostedWhseShptLine DO BEGIN
...
WITH ItemLedgEntry DO
```al
WITH PostedWhseShptLine DO BEGIN
...
WITH ItemLedgEntry DO
InsertBufferRec(...,"Serial No.","Lot No.",...);
...
END;
END;
```
Good code
WITH PostedWhseShptLine DO BEGIN
...
InsertBufferRec(...,ItemLedgEntry."Serial No.",ItemLedgEntry."Lot No.",...);
...
END;
```al
WITH PostedWhseShptLine DO BEGIN
...
InsertBufferRec(...,ItemLedgEntry."Serial No.",ItemLedgEntry."Lot No.",...);
...
END;
```

View file

@ -3,26 +3,34 @@ title = "One Statement Per Line"
weight = 910
+++
A line of code should not have more than one statement.
Bad code
IF OppEntry.FIND('-') THEN EXIT
```al
IF OppEntry.FIND('-') THEN EXIT
```
Good code
IF OppEntry.FIND('-') THEN
EXIT
```al
IF OppEntry.FIND('-') THEN
EXIT
```
Bad code
TotalCost += Cost; TotalAmt += Amt;
```al
TotalCost += Cost; TotalAmt += Amt;
```
Good code
TotalCost += Cost;
TotalAmt += Amt;
```al
TotalCost += Cost;
TotalAmt += Amt;
```

View file

@ -2,16 +2,22 @@
title = "Separate IF and ELSE"
weight = 1050
+++
IF and ELSE statements should be on separate lines. Bad code
IF and ELSE statements should be on separate lines.
IF Atom\[i+1\] = '\>' THEN HasLogicalOperator := TRUE ELSE BEGIN
Bad code
```al
IF Atom[i+1] = '>' THEN HasLogicalOperator := TRUE ELSE BEGIN
...
END;
END;
```
Good code
IF Atom\[i+1\] = '\>' THEN
```al
IF Atom[i+1] = '>' THEN
HasLogicalOperator := TRUE
ELSE BEGIN
ELSE BEGIN
...
END;
END;
```

View file

@ -3,36 +3,44 @@ title = "Spacing Binary Operators"
weight = 1120
+++
There must be exactly one space character on each side of a binary operator such as = + - AND OR =. The parameter comma operator however, should have no spaces.
Bad code
"Line Discount %" := "Line Discount Amount"/"Line Value"\*100
```al
"Line Discount %" := "Line Discount Amount"/"Line Value"*100
```
Good code
"Line Discount %" := "Line Discount Amount" / "Line Value" \* 100;
```al
"Line Discount %" := "Line Discount Amount" / "Line Value" * 100;
```
Bad code
StartDate := CALCDATE('<+'+FORMAT(Days + i)+'D\>', StartDate);
```al
StartDate := CALCDATE('<+'+FORMAT(Days + i)+'D>', StartDate);
```
Good code
StartDate := CALCDATE('<+' + FORMAT(Days + i) + 'D\>',StartDate);
```al
StartDate := CALCDATE('<+' + FORMAT(Days + i) + 'D>',StartDate);
```
Bad code
StartDate := 0D; // Initialize
```al
StartDate := 0D; // Initialize
```
Good code
StartDate := 0D; // Initialize
```al
StartDate := 0D; // Initialize
```

View file

@ -3,36 +3,44 @@ title = "Spacing Brackets and ::"
weight = 1130
+++
There must be no spaces characters before and after \[\] dimension brackets symbols or :: option symbols.
Bad code
A\[i\] \[j\] := Amt;
```al
A[i] [j] := Amt;
```
Good code
A\[i\]\[j\] := Amt;
```al
A[i][j] := Amt;
```
Bad code
"Currency Exchange Rate"."Fix Exchange Rate Amount" :: Currency:
```al
"Currency Exchange Rate"."Fix Exchange Rate Amount" :: Currency:
```
Good code
"Currency Exchange Rate"."Fix Exchange Rate Amount"::Currency:
```al
"Currency Exchange Rate"."Fix Exchange Rate Amount"::Currency:
```
Bad code
IF FIND (Which) THEN
```al
IF FIND (Which) THEN
```
Good code
IF FIND(Which) THEN
```al
IF FIND(Which) THEN
```

View file

@ -3,24 +3,30 @@ title = "Spacing Unary Operators"
weight = 1140
+++
There must be no space between a unary operator and its argument (except for the NOT keyword).
Bad code
IF NOT(Type = Type::Item) THEN
```al
IF NOT(Type = Type::Item) THEN
```
Good code
IF NOT (Type = Type::Item) THEN
```al
IF NOT (Type = Type::Item) THEN
```
Bad code
DiscAmt := - "Discount Amount";
```al
DiscAmt := - "Discount Amount";
```
Good code
DiscAmt := -"Discount Amount";
```al
DiscAmt := -"Discount Amount";
```

View file

@ -2,23 +2,30 @@
title = "Temporary Variable Naming"
weight = 1200
+++
The name of a temporary variable must be prefixed with the word Temp and not otherwise. Bad code
JobWIPBuffer@1002 : TEMPORARY Record 1018;
Good code
TempJobWIPBuffer@1002 : TEMPORARY Record 1018;
The name of a temporary variable must be prefixed with the word Temp and not otherwise.
Bad code
TempJobWIPBuffer@1002 : Record 1018;
```al
JobWIPBuffer@1002 : TEMPORARY Record 1018;
```
Good code
CopyOfJobWIPBuffer@1002 : Record 1018;
```al
TempJobWIPBuffer@1002 : TEMPORARY Record 1018;
```
Bad code
```al
TempJobWIPBuffer@1002 : Record 1018;
```
Good code
```al
CopyOfJobWIPBuffer@1002 : Record 1018;
```

View file

@ -3,88 +3,113 @@ title = "TextConst Suffixes"
weight = 1210
+++
TextConst variable names should have a suffix (an approved three-letter suffix: Msg, Tok, Err, Qst, Lbl, Txt) describing usage.
Bad code
CannotDeleteLine@1005 : TextConst 'ENU=You cannot delete this line because one or more rating values exists.';
...
ERROR(CannotDeleteLine,TABLECAPTION);
```al
CannotDeleteLine@1005 : TextConst 'ENU=You cannot delete this line because one or more rating values exists.';
...
ERROR(CannotDeleteLine,TABLECAPTION);
```
Good code
CannotDeleteLineErr@1005 : TextConst 'ENU=You cannot delete this line because one or more rating values exists.';
...
ERROR(CannotDeleteLineErr,TABLECAPTION);
```al
CannotDeleteLineErr@1005 : TextConst 'ENU=You cannot delete this line because one or more rating values exists.';
...
ERROR(CannotDeleteLineErr,TABLECAPTION);
```
Bad code
Text000@1011 : TextConst 'ENU="has been changed (initial a %1: %2= %3, %4= %5)"';
...
SalesLine.FIELDERROR(Type,STRSUBSTNO(Text000,...);
...
```al
Text000@1011 : TextConst 'ENU="has been changed (initial a %1: %2= %3, %4= %5)"';
...
SalesLine.FIELDERROR(Type,STRSUBSTNO(Text000,...);
...
```
Good code
TypeHasBeenChangedErr@1011 : TextConst 'ENU="has been changed (initial a %1: %2= %3, %4= %5)"';
...
SalesLine.FIELDERROR(Type,STRSUBSTNO(TypeHasBeenChangedErr,...);
...
```al
TypeHasBeenChangedErr@1011 : TextConst 'ENU="has been changed (initial a %1: %2= %3, %4= %5)"';
...
SalesLine.FIELDERROR(Type,STRSUBSTNO(TypeHasBeenChangedErr,...);
...
```
Bad code
Text004@1004 : TextConst 'ENU=Indenting the Job Tasks \#1\#\#\#\#\#\#\#\#\#\#.';
...
Window@1007 : Dialog;
...
```al
Text004@1004 : TextConst 'ENU=Indenting the Job Tasks \#1\#\#\#\#\#\#\#\#\#\#.';
...
Window@1007 : Dialog;
...
Window.OPEN(Text004);
```
Good code
IndentingMsg@1004 : TextConst 'ENU=Indenting the Job Tasks \#1\#\#\#\#\#\#\#\#\#\#.';
...
Window@1007 : Dialog;
...
```al
IndentingMsg@1004 : TextConst 'ENU=Indenting the Job Tasks \#1\#\#\#\#\#\#\#\#\#\#.';
...
Window@1007 : Dialog;
...
Window.OPEN(IndentingMsg);
```
Bad code
Text002@1005 : TextConst 'ENU=You cannot delete a %1 that is used in one or more setup windows.\\ Do you want to open the G/L Account No. Where-Used List Window?';
...
IF CONFIRM(Text002,TRUE,GLAcc.TABLECAPTION) THEN
```al
Text002@1005 : TextConst 'ENU=You cannot delete a %1 that is used in one or more setup windows.\\ Do you want to open the G/L Account No. Where-Used List Window?';
...
IF CONFIRM(Text002,TRUE,GLAcc.TABLECAPTION) THEN
```
Good code
OpenWhereUsedWindowQst@1005 : TextConst 'ENU=You cannot delete a %1 that is used in one or more setup windows.\\ Do you want to open the G/L Account No. Where-Used List Window?';
...
IF CONFIRM(OpenWhereUsedWindowQst,TRUE,GLAcc.TABLECAPTION) THEN
```al
OpenWhereUsedWindowQst@1005 : TextConst 'ENU=You cannot delete a %1 that is used in one or more setup windows.\\ Do you want to open the G/L Account No. Where-Used List Window?';
...
IF CONFIRM(OpenWhereUsedWindowQst,TRUE,GLAcc.TABLECAPTION) THEN
```
Bad code
Selection := STRMENU(Text003,2);
...
Text003@1002 : TextConst 'ENU=&Copy dimensions from BOM,&Retrieve dimensions from components';
```al
Selection := STRMENU(Text003,2);
...
Text003@1002 : TextConst 'ENU=&Copy dimensions from BOM,&Retrieve dimensions from components';
```
Good code
```al
Selection := STRMENU(CopyFromQst,2);
...
CopyFromQst@1002 : TextConst 'ENU=&Copy dimensions from BOM,&Retrieve dimensions from components';
```
Bad code
DATASET
{
...
{ 1 ;1 ;Column ;Chart\_of\_AccountsCaption;
SourceExpr=Chart\_of\_AccountsCaption }
...
Chart\_of\_AccountsCaption@9647 : TextConst 'ENU=Chart of Accounts';
```al
DATASET
{
...
{ 1 ;1 ;Column ;Chart_of_AccountsCaption;
SourceExpr=Chart_of_AccountsCaption }
...
Chart_of_AccountsCaption@9647 : TextConst 'ENU=Chart of Accounts';
```
Good code
DATASET
{
...
{ 1 ;1 ;Column ;Chart\_of\_AccountsCaption;
SourceExpr=ChartOfAccountsLbl }
...
ChartOfAccountsLbl@9647 : TextConst 'ENU=Chart of Accounts';
```al
DATASET
{
...
{ 1 ;1 ;Column ;Chart_of_AccountsCaption;
SourceExpr=ChartOfAccountsLbl }
...
ChartOfAccountsLbl@9647 : TextConst 'ENU=Chart of Accounts';
```

View file

@ -3,12 +3,17 @@ title = "Unary Operator Line End"
weight = 1250
+++
Do not end a line with unary operator.
Bad code
"Quantity Handled (Base)" := -
```al
"Quantity Handled (Base)" := -
"Quantity Handled (Base)");
```
Good code
"Quantity Handled (Base)" :=
```al
"Quantity Handled (Base)" :=
- "Quantity Handled (Base)");
```

View file

@ -3,26 +3,30 @@ title = "Unnecessary Compound Parenthesis"
weight = 1260
+++
Use parenthesis only to enclose compound expressions inside compound expressions.
Bad code
IF ("Costing Method" = "Costing Method"::Standard) THEN
```al
IF ("Costing Method" = "Costing Method"::Standard) THEN
```
Good code
IF "Costing Method" = "Costing Method"::Standard THEN
####
```al
IF "Costing Method" = "Costing Method"::Standard THEN
```
Bad code
ProfitPct = -(Profit) / CostAmt \* 100;
```al
ProfitPct = -(Profit) / CostAmt * 100;
```
Good code
ProfitPct = -Profit / CostAmt \* 100;
```al
ProfitPct = -Profit / CostAmt * 100;
```

View file

@ -2,15 +2,21 @@
title = "Unnecessary ELSE"
weight = 1270
+++
ELSE should not be used when the last action in the THEN part is an EXIT, BREAK, SKIP, QUIT, ERROR. Bad code
ELSE should not be used when the last action in the THEN part is an EXIT, BREAK, SKIP, QUIT, ERROR.
IF IsAdjmtBinCodeChanged THEN
Bad code
```al
IF IsAdjmtBinCodeChanged THEN
ERROR(AdjmtBinCodeChangeNotAllowedErr,...)
ELSE
ELSE
ERROR(BinCodeChangeNotAllowedErr,...);
```
Good code
IF IsAdjmtBinCodeChanged THEN
```al
IF IsAdjmtBinCodeChanged THEN
ERROR(AdjmtBinCodeChangeNotAllowedErr,...)
ERROR(BinCodeChangeNotAllowedErr,...);
ERROR(BinCodeChangeNotAllowedErr,...);
```

View file

@ -3,24 +3,30 @@ title = "Unnecessary Function Parenthesis"
weight = 1280
+++
Do not use parenthesis in a function call if the function does not have any parameters.
Bad code
IF ReservMgt.IsPositive() THEN
```al
IF ReservMgt.IsPositive() THEN
```
Good code
IF ReservMgt.IsPositive THEN
```al
IF ReservMgt.IsPositive THEN
```
Bad code
IF ChangeStatusForm.RUNMODAL() <\> ACTION::Yes THEN
```al
IF ChangeStatusForm.RUNMODAL() <> ACTION::Yes THEN
```
Good code
IF ChangeStatusForm.RUNMODAL <\> ACTION::Yes THEN
```al
IF ChangeStatusForm.RUNMODAL <> ACTION::Yes THEN
```

View file

@ -2,12 +2,17 @@
title = "Unnecessary Separators"
weight = 1290
+++
There should be no unnecessary separators. Bad code
There should be no unnecessary separators.
IF Customer.FINDFIRST THEN;;
Bad code
```al
IF Customer.FINDFIRST THEN;;
```
Good code
IF Customer.FINDFIRST THEN;
```al
IF Customer.FINDFIRST THEN;
```

View file

@ -3,24 +3,30 @@ title = "Unnecessary TRUE/FALSE"
weight = 1300
+++
Do not use TRUE or FALSE keywords unnecessarily if the expression is already an logical expression.
Bad code
IF IsPositive() = TRUE THEN
```al
IF IsPositive() = TRUE THEN
```
Good code
IF IsPositive THEN
```al
IF IsPositive THEN
```
Bad code
IF Complete <\> TRUE THEN
```
IF Complete <> TRUE THEN
```
Good code
IF NOT Complete THEN
```al
IF NOT Complete THEN
```

View file

@ -3,30 +3,37 @@ title = "Variable Already Scoped"
weight = 1400
+++
Do not use scope ''.'' qualifier unnecessarily when a variable is already implicitly or explicitly scoped. It keeps the code simpler.
Bad code
ReturnRcptHeader.SETRANGE(ReturnRcptHeader."Return Order No.","Document No.");
```al
ReturnRcptHeader.SETRANGE(ReturnRcptHeader."Return Order No.","Document No.");
```
Good code
ReturnRcptHeader.SETRANGE("Return Order No.","Document No.");
```al
ReturnRcptHeader.SETRANGE("Return Order No.","Document No.");
```
Bad code
WITH ChangeLogSetupTable DO BEGIN
```al
WITH ChangeLogSetupTable DO BEGIN
...
IF ChangeLogSetupTable.DELETE THEN
...
END;
...
END;
```
Good code
WITH ChangeLogSetupTable DO BEGIN
```al
WITH ChangeLogSetupTable DO BEGIN
...
IF DELETE THEN
...
END;
...
END;
```

View file

@ -9,48 +9,61 @@ A variable must begin with a capital letter.
Blanks, periods, and other characters (such as parentheses) that would make quotation marks around a variable necessary must be omitted.
If a variable is a compound of two or more words or abbreviations, each word or abbreviation should begin with a capital letter.
Bad code
...
```al
...
WIPBuffer@1002 : Record 1018
...
OBJECT Table Job WIP Buffer
...
OBJECT Table Job WIP Buffer
```
Good code
...
```al
...
JobWIPBuffer@1002 : Record 1018
...
OBJECT Table Job WIP Buffer
...
OBJECT Table Job WIP Buffer
```
Bad code
...
```al
...
Postline@1004 : Codeunit 12;
...
OBJECT Codeunit Gen. Jnl.-Post Line
...
OBJECT Codeunit Gen. Jnl.-Post Line
```
Good code
...
```al
...
GenJnlPostLine@1004 : Codeunit 12;
...
OBJECT Codeunit Gen. Jnl.-Post Line
...
OBJECT Codeunit Gen. Jnl.-Post Line
```
Bad code
LOCAL PROCEDURE HandleCustDebitCredit@17(...;"Amount (LCY)"@1001 : Decimal;...);
BEGIN
```al
LOCAL PROCEDURE HandleCustDebitCredit@17(...;"Amount (LCY)"@1001 : Decimal;...);
BEGIN
IF ((... ("Amount (LCY)" \> 0)) ...) OR
((... ("Amount (LCY)" < 0)) ...)
((... ("Amount (LCY)" < 0)) ...)
THEN BEGIN
...
```
Good code
LOCAL PROCEDURE HandleCustDebitCredit@17(...;AmountLCY@1001 : Decimal;...);
BEGIN
```al
LOCAL PROCEDURE HandleCustDebitCredit@17(...;AmountLCY@1001 : Decimal;...);
BEGIN
IF ((... (AmountLCY \> 0)) ...) OR
((... (AmountLCY < 0)) ...)
((... (AmountLCY < 0)) ...)
THEN BEGIN
...
```

View file

@ -2,12 +2,18 @@
title = "Variables Declarations Order"
weight = 1430
+++
Variables declarations should be ordered by type. In general, object and complex variable types are listed first followed by simple variables. The order should be the same as the object list in the object designer for C/AL objects. Afterwards come the complex variables like RecordRef, .NET, FieldRef etc. At the end come all the simple data types in no particular order. Bad code
Variables declarations should be ordered by type. In general, object and complex variable types are listed first followed by simple variables. The order should be the same as the object list in the object designer for C/AL objects. Afterwards come the complex variables like RecordRef, .NET, FieldRef etc. At the end come all the simple data types in no particular order.
StartingDateFilter@1002 : Text\[30\];
Vend@1003 : Record 23;
Bad code
```al
StartingDateFilter@1002 : Text[30];
Vend@1003 : Record 23;
```
Good code
Vend@1003 : Record 23;
StartingDateFilter@1002 : Text\[30\];
```al
Vend@1003 : Record 23;
StartingDateFilter@1002 : Text[30];
```