mirror of
https://github.com/microsoft/BCQuality.git
synced 2026-10-05 22:56:55 +01:00
Add 18 community AL/BC patterns across style, data-modeling, web-services, appsource, breaking-changes, performance, and testing
Contributed by CURABIS ApS, generalized from patterns observed across real AppSource/PTE development. Each article follows the knowledge file format (frontmatter, Description/Best Practice/Anti Pattern, sibling .good.al/.bad.al samples).
This commit is contained in:
parent
07e324ddbc
commit
057e17c202
52 changed files with 1109 additions and 0 deletions
|
|
@ -0,0 +1,28 @@
|
|||
---
|
||||
bc-version: [all]
|
||||
domain: style
|
||||
keywords: [var-parameter, by-reference, pass-by-reference, literal, constant, compile-error, procedure-call]
|
||||
technologies: [al]
|
||||
countries: [w1]
|
||||
application-area: [all]
|
||||
---
|
||||
|
||||
# A `var` parameter must be called with a variable, never a literal or expression
|
||||
|
||||
> Contributions welcome — open a PR to refine or extend this article.
|
||||
|
||||
## Description
|
||||
|
||||
When a procedure declares a parameter with `var`, that parameter is passed by reference: the callee writes back into the caller's own memory location. This means the argument at the call site must be an actual variable, something with an address. A string literal, a numeric constant, or a computed expression has no address to write back to, so passing one to a `var` parameter fails to compile. Before writing a call, check the callee's signature for `var` on each parameter position being supplied a literal or expression — if present, a variable declared in the caller's own scope must be used instead.
|
||||
|
||||
## Best Practice
|
||||
|
||||
Declare a variable in the caller's scope and pass it to the `var` parameter.
|
||||
|
||||
See sample: `var-parameters-require-an-addressable-variable.good.al`.
|
||||
|
||||
## Anti Pattern
|
||||
|
||||
Passing a literal or a computed expression to a `var` parameter position fails to compile, because neither has an address the callee can write back to.
|
||||
|
||||
See sample: `var-parameters-require-an-addressable-variable.bad.al`.
|
||||
Loading…
Add table
Add a link
Reference in a new issue