Removed Discussion Links. Using new Theme solution.

Some additional MDLint cleanup as well
This commit is contained in:
Henrik Helgesen 2022-02-24 15:36:06 -08:00
parent cd3497d542
commit fb17dc9640
27 changed files with 90 additions and 206 deletions

View file

@ -25,11 +25,3 @@ Therefore it's good practice to always check if the table is empty when performi
if not EmptyTableWLD.IsEmpty() then
EmptyTableWLD.DeleteAll(true);
```
## Discussions
You can discuss the guideline [here](https://github.com/microsoft/alguidelines/discussions/107)
You can find discussions on all "Best Practices" [here](https://github.com/microsoft/alguidelines/discussions/categories/bc-best-practices).
If you don't find the discussion of this guideline, please feel free to create a new one with the same title as this article.

View file

@ -18,15 +18,18 @@ In general, subscribers have to be put in codeunits. There are a few performanc
Let's discuss all points
## Keep the codeunit as small as possible
Every time a subscriber gets called, a new instance of the codeunit is being loaded in memory, which takes memory and processing power. The smaller the codeunit, the less memory, and the faster it is.
Therefore, it's suggested to split the subscribers by functionality and avoid putting business logic in the actual codeunit. Tip: put all business logic in an "[Method Codeunit](https://alguidelines.dev/bcpatterns/generic-method-pattern/)".
Examples:
- if you app does things on Sales and Purchase, create a Sales-subs codeunit, and a Purchase-subs.
- if you have multiple functionalities in your app (let's call'm modules), create a subs-codeunit per module, and only add the subscribers in there that are necessary for that module.
### Bad code
```AL
codeunit 2037325 "Setup Subs"
{
@ -73,6 +76,7 @@ codeunit 2037325 "Setup Subs"
end;
}
```
### Good code
Split into 2 codeunits, and move the business logic out.
@ -112,6 +116,7 @@ codeunit 2037324 "RHE Setup Subs"
To avoid the extra "loading of the content" while a subscriber is being executed, use Single Instance codeunit for subscribers. Do take into account, of course, that it would share the state across the entire session.
### Bad code
```AL
codeunit 2037324 "RHE Setup Subs"
{
@ -124,7 +129,9 @@ codeunit 2037324 "RHE Setup Subs"
end;
}
```
### Good code
```AL
codeunit 2037324 "RHE Setup Subs"
{
@ -145,6 +152,7 @@ codeunit 2037324 "RHE Setup Subs"
If possible, only execute the subscriber when really necessary by using Manual Binding.
### Bad code
```AL
//subscriber - code should actually only run when Color=Red.
[EventSubscriber(ObjectType::Table, Database::"Just Some Table WLD", 'OnAfterValidateEvent', 'Message 2', false, false)]
@ -162,7 +170,9 @@ If possible, only execute the subscriber when really necessary by using Manual B
JustSomeTable.Validate("Message 2", format(Random(1000)));
until JustSomeTable.Next() < 1;
```
### Good code
```AL
if JustSomeTable.FindSet() then
repeat
@ -177,21 +187,15 @@ If possible, only execute the subscriber when really necessary by using Manual B
```
## Avoid OnInsert/OnModify/OnDelete
The reason for this is, that it breaks the batch-calls:
- Any "OnInsert" subscriber breaks the bulk inserts, simply because it needs to perform an operation after every record that was inserted
- Any "OnModify" subscriber slows down the "ModifyAll", simply because it needs to perform an operation after every record that was modified. I fact: 1 SQL call is turned into a loop of SQL calls.
- Any "OnDelete" subscriber slows down the "DeleteAll", simply because it needs to perform an operation after every record that was deleted. I fact: 1 SQL call is turned into a loop of SQL calls.
Avoid subscribers to these events.
## [Discussions](https://github.com/microsoft/alguidelines/discussions/92)
You can discuss this guidelines [here](https://github.com/microsoft/alguidelines/discussions/92).
You can find discussions on all "Best Practices" [here](https://github.com/microsoft/alguidelines/discussions/categories/bc-best-practices).
If you don't find the discussion of this guideline, please feel free to create a new one with the same title as this article.
## References
The [Generic Method Pattern](https://alguidelines.dev/bcpatterns/generic-method-pattern/)

View file

@ -5,8 +5,6 @@ description: >
AL Code Best Practices
---
# Business Central Best Practices
This section will be cover things that aren't as simple as Design Patterns, but will help make sure your development is:
- high-performance

View file

@ -26,9 +26,3 @@ When `begin` follows `then`, `else`, `do`, it should be on the same line, preced
...
end;
```
## [Discussions](https://github.com/microsoft/alguidelines/discussions/categories/bc-best-practices?discussions_q=begin+as+an+After+Word+category%3A%22BC+Best+Practices%22)
You can find discussions on all "Best Practices" [here](https://github.com/microsoft/alguidelines/discussions/categories/bc-best-practices).
If you don't find the discussion of this guideline, please feel free to create a new one with the same title as this article.

View file

@ -53,8 +53,3 @@ end else
(not X)
```
## [Discussions](https://github.com/microsoft/alguidelines/discussions/categories/bc-best-practices?discussions_q=begin+end+compound+only+category%3A%22BC+Best+Practices%22)
You can find discussions on all "Best Practices" [here](https://github.com/microsoft/alguidelines/discussions/categories/bc-best-practices).
If you don't find the discussion of this guideline, please feel free to create a new one with the same title as this article.

View file

@ -25,9 +25,3 @@ Quantity
Quantity -
"Quantity Shipped"
```
## [Discussions](https://github.com/microsoft/alguidelines/discussions/categories/bc-best-practices?discussions_q=binary+operator+to+start+line+category%3A%22BC+Best+Practices%22)
You can find discussions on all "Best Practices" [here](https://github.com/microsoft/alguidelines/discussions/categories/bc-best-practices).
If you don't find the discussion of this guideline, please feel free to create a new one with the same title as this article.

View file

@ -8,7 +8,7 @@ _Created by Microsoft, Described by waldo_
## Description
A CASE action should start on a line after the possibility.
A CASE action should start on a line after the possibility.
## Bad code
@ -29,9 +29,3 @@ A CASE action should start on a line after the possibility.
Letter2 := '11';
end;
```
## [Discussions](https://github.com/microsoft/alguidelines/discussions/categories/bc-best-practices?discussions_q=case+action+on+next+line+category%3A%22BC+Best+Practices%22)
You can find discussions on all "Best Practices" [here](https://github.com/microsoft/alguidelines/discussions/categories/bc-best-practices).
If you don't find the discussion of this guideline, please feel free to create a new one with the same title as this article.

View file

@ -7,6 +7,7 @@ categories: ["Best Practice"]
_Created by Microsoft, Described by waldo_
## Description
Always start comments with // followed by one space character.
## Bad code
@ -14,16 +15,9 @@ Always start comments with // followed by one space character.
```al
RowNo += 1000; //Move way below the budget
```
## Good code
```al
RowNo += 1000; // Move way below the budget
```
## [Discussions](https://github.com/microsoft/alguidelines/discussions/categories/bc-best-practices?discussions_q=comment+spacing+category%3A%22BC+Best+Practices%22)
You can find discussions on all "Best Practices" [here](https://github.com/microsoft/alguidelines/discussions/categories/bc-best-practices).
If you don't find the discussion of this guideline, please feel free to create a new one with the same title as this article.

View file

@ -33,9 +33,3 @@ The `end else` pair should always appear on the same line.
...
end;
```
## [Discussions](https://github.com/microsoft/alguidelines/discussions/categories/bc-best-practices?discussions_q=end+else/pair+category%3A%22BC+Best+Practices%22)
You can find discussions on all "Best Practices" [here](https://github.com/microsoft/alguidelines/discussions/categories/bc-best-practices).
If you don't find the discussion of this guideline, please feel free to create a new one with the same title as this article.

View file

@ -7,6 +7,7 @@ categories: ["Best Practice"]
_Created by Microsoft, Described by waldo_
## Description
The `if..then` pair, `while..do` pair, and `for..do` pair must appear on the same line or the same level of indentation. If possible, you can align the lines it is even much more readable.
## Bad code
@ -23,9 +24,3 @@ The `if..then` pair, `while..do` pair, and `for..do` pair must appear on the sam
(a = b)
then
```
## [Discussions](https://github.com/microsoft/alguidelines/discussions/categories/bc-best-practices?discussions_q=keyword+pair+indentation+category%3A%22BC+Best+Practices%22)
You can find discussions on all "Best Practices" [here](https://github.com/microsoft/alguidelines/discussions/categories/bc-best-practices).
If you don't find the discussion of this guideline, please feel free to create a new one with the same title as this article.

View file

@ -6,6 +6,7 @@ categories: ["Best Practice"]
_Created by Microsoft, Described by waldo_
## Description
The `end`, `if`, `repeat`, `for`, `while`, `else` and `case` statement should always start a line.
## Bad code
@ -28,10 +29,3 @@ The `end`, `if`, `repeat`, `for`, `while`, `else` and `case` statement should al
if IsSalesCycleCode then
ValidatSalesCycleCode();
```
## [Discussions](https://github.com/microsoft/alguidelines/discussions/categories/bc-best-practices?discussions_q=line+start+keyword+category%3A%22BC+Best+Practices%22)
You can find discussions on all "Best Practices" [here](https://github.com/microsoft/alguidelines/discussions/categories/bc-best-practices).
If you don't find the discussion of this guideline, please feel free to create a new one with the same title as this article.

View file

@ -7,6 +7,7 @@ categories: ["Best Practice"]
_Created by Microsoft, Described by waldo_
## Description
The `repeat` statement should always be alone on a line.
## Bad code
@ -14,16 +15,10 @@ The `repeat` statement should always be alone on a line.
```al
if ReservEntry.FindSet() then repeat
```
## Good code
```al
if ReservEntry.FindSet() then
repeat
```
## [Discussions](https://github.com/microsoft/alguidelines/discussions/categories/bc-best-practices?discussions_q=lonely+repeat+category%3A%22BC+Best+Practices%22)
You can find discussions on all "Best Practices" [here](https://github.com/microsoft/alguidelines/discussions/categories/bc-best-practices).
If you don't find the discussion of this guideline, please feel free to create a new one with the same title as this article.

View file

@ -7,6 +7,7 @@ categories: ["Best Practice"]
_Created by Microsoft, Described by waldo_
## Description
When calling an object statically use the Object Name, not the Object Id.
## Bad code
@ -20,9 +21,3 @@ When calling an object statically use the Object Name, not the Object Id.
```al
Page.RunModal(Page::"Posted Sales Shipment Lines", SalesShptLine);
```
## [Discussions](https://github.com/microsoft/alguidelines/discussions/categories/bc-best-practices?discussions_q=named+invocations+category%3A%22BC+Best+Practices%22)
You can find discussions on all "Best Practices" [here](https://github.com/microsoft/alguidelines/discussions/categories/bc-best-practices).
If you don't find the discussion of this guideline, please feel free to create a new one with the same title as this article.

View file

@ -7,28 +7,27 @@ categories: ["Best Practice"]
_Created by Microsoft, Described by waldo_
## Description
A line of code should not have more than one statement.
## Bad code
```al
if OppEntry.Find('-') then exit;
```
```
## Good code
```al
if OppEntry.Find('-') then
exit;
```
```
## Bad code
```al
TotalCost += Cost; TotalAmt += Amt;
```
```
## Good code
@ -36,9 +35,3 @@ A line of code should not have more than one statement.
TotalCost += Cost;
TotalAmt += Amt;
```
## [Discussions](https://github.com/microsoft/alguidelines/discussions/categories/bc-best-practices?discussions_q=one+statement+per+line+category%3A%22BC+Best+Practices%22)
You can find discussions on all "Best Practices" [here](https://github.com/microsoft/alguidelines/discussions/categories/bc-best-practices).
If you don't find the discussion of this guideline, please feel free to create a new one with the same title as this article.

View file

@ -7,6 +7,7 @@ categories: ["Best Practice"]
_Created by Microsoft, Described by waldo_
## Description
`if` and `else` statements should be on separate lines.
## Bad code
@ -26,10 +27,3 @@ _Created by Microsoft, Described by waldo_
...
end;
```
## [Discussions](https://github.com/microsoft/alguidelines/discussions/categories/bc-best-practices?discussions_q=separate+if+and+else+category%3A%22BC+Best+Practices%22)
You can find discussions on all "Best Practices" [here](https://github.com/microsoft/alguidelines/discussions/categories/bc-best-practices).
If you don't find the discussion of this guideline, please feel free to create a new one with the same title as this article.

View file

@ -7,40 +7,41 @@ categories: ["Best Practice"]
_Created by Microsoft, Described by waldo_
## Description
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 a space after the comma.
## Bad code
```al
"Line Discount %" := "Line Discount Amount"/"Line Value"*100;
```
```
## Good code
```al
"Line Discount %" := "Line Discount Amount" / "Line Value" * 100;
```
```
## Bad code
```al
StartDate := CalcDate('<+'+Format(Days+i)+'D\>',StartDate);
```
```
## Good code
```al
StartDate := CalcDate('<+' + Format(Days + i) + 'D\>', StartDate);
```
```
## Bad code
```al
StartDate:=0D; // Initialize
```
## Good code
```al
StartDate := 0D; // Initialize
```
```

View file

@ -359,9 +359,3 @@ If there is no other choice, then use the suggestions below.
| % | Pct |
| 3-tier | Three-Tier |
| Outlook Synch | Osynch |
## [Discussions](https://github.com/microsoft/alguidelines/discussions/categories/bc-best-practices?discussions_q=abbreviations+category%3A%22BC+Best+Practices%22)
You can find discussions on all "Best Practices" [here](https://github.com/microsoft/alguidelines/discussions/categories/bc-best-practices).
If you don't find the discussion of this guideline, please feel free to create a new one with the same title as this article.

View file

@ -32,9 +32,3 @@ _Created by Microsoft, Described by waldo_
Error(BinCodeChangeNotAllowedErr, ...);
end;
```
## [Discussions](https://github.com/microsoft/alguidelines/discussions/categories/bc-best-practices?discussions_q=unnecessary+else+category%3A%22BC+Best+Practices%22)
You can find discussions on all "Best Practices" [here](https://github.com/microsoft/alguidelines/discussions/categories/bc-best-practices).
If you don't find the discussion of this guideline, please feel free to create a new one with the same title as this article.

View file

@ -13,29 +13,22 @@ Do not use `true` or `false` keywords unnecessarily if the expression is already
```al
if IsPositive() = true then
```
```
## Good code
```al
if IsPositive() then
```
```
## Bad code
```al
if Complete <> true then
```
```
## Good code
```al
if not Complete then
```
## [Discussions](https://github.com/microsoft/alguidelines/discussions/categories/bc-best-practices?discussions_q=unnecessary+true+false+category%3A%22BC+Best+Practices%22)
You can find discussions on all "Best Practices" [here](https://github.com/microsoft/alguidelines/discussions/categories/bc-best-practices).
If you don't find the discussion of this guideline, please feel free to create a new one with the same title as this article.

View file

@ -7,6 +7,7 @@ categories: ["Best Practice"]
_Created by Microsoft, Described by waldo_
## Description
Variables that refer to a AL object must contain the objects name, abbreviated where necessary.
A variable must begin with a capital letter.
@ -20,29 +21,33 @@ If a variable is a compound of two or more words or abbreviations, each word or
```al
WIPBuffer: Record "Job WIP Buffer"
```
## Good code
```al
JobWIPBuffer: Record "Job WIP Buffer"
```
## Bad code
```al
Postline: Codeunit "Gen. Jnl.-Post Line";
```
## Good code
```al
GenJnlPostLine: Codeunit "Gen. Jnl.-Post Line";
```
## Bad code
```al
"Amount (LCY)": Decimal;
```
## Good code
```al
AmountLCY: Decimal;
```
## [Discussions](https://github.com/microsoft/alguidelines/discussions/categories/bc-best-practices?discussions_q=one+variable+naming+category%3A%22BC+Best+Practices%22)
You can find discussions on all "Best Practices" [here](https://github.com/microsoft/alguidelines/discussions/categories/bc-best-practices).
If you don't find the discussion of this guideline, please feel free to create a new one with the same title as this article.

View file

@ -7,6 +7,7 @@ categories: ["Best Practice"]
_Created by Microsoft, Described by waldo_
## Description
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:
- Record
@ -25,7 +26,6 @@ Variables declarations should be ordered by type. In general, object and complex
(Ref: [Microsoft Docs](https://docs.microsoft.com/en-us/dynamics365/business-central/dev-itpro/developer/analyzers/codecop-aa0021))
## Bad code
```al
@ -39,9 +39,3 @@ Variables declarations should be ordered by type. In general, object and complex
Vendor: Record Vendor;
StartingDateFilter: Text;
```
## [Discussions](https://github.com/microsoft/alguidelines/discussions/categories/bc-best-practices?discussions_q=one+variables+declarations+order+category%3A%22BC+Best+Practices%22)
You can find discussions on all "Best Practices" [here](https://github.com/microsoft/alguidelines/discussions/categories/bc-best-practices).
If you don't find the discussion of this guideline, please feel free to create a new one with the same title as this article.