Variable practices: scope, initialization and clear names
Declares temporary data and avoids implicit dependencies between calls.
Overview
Declare and initialize variables before use. An uninitialized numeric-intent Local holds Nil and cannot be added as though it were zero. In AdvPL, assigning an unknown name can implicitly create a Private: a typo may change logic without the expected error. Prefer Local for temporary data; reserve Static for state that must survive calls and document framework-required Private/Public dependencies. Names should express intent while expected types remain consistent throughout the flow. (TOTVS, n.d., refs. 1–2)
Return value
No single return value: this is a composite workflow.
Commented example
#Include "Protheus.ch"
User Function EdVars()
Local nQuantity := 3
Local nUnitPrice := 10
Local nTotal := 0
// Every operand is initialized.
nTotal := nQuantity * nUnitPrice
ConOut(cValToChar(nTotal))
Return NilExpected result: 30; no global state created. Under review: editorial example neither compiled nor run in Protheus. Check includes, release, RDD and context before testing.
- Review spelling and dynamic dependencies. Do not use Public to carry secrets or Static as a cache without an invalidation policy.
- Under review: editorial example neither compiled nor run in Protheus. Check includes, release, RDD and context before testing.

Comments
There are no approved comments yet.
Sign in with Google or Microsoft to comment.