Description
Prerequisites
- This rule has not already been suggested.
- This should be a new rule, not an improvement to an existing rule.
- This rule would be generally useful, not specific to my code or setup.
Suggested rule title
VarArgumentsShouldBeInitialized
Rule description
In #127, there was a discussion on whether var
argument should be considered as initializing a variable. Although out
arguments should be preferred for that, a confusion in the Delphi compiler (out
and var
are processed similarly) has lead some teams to accept initialization through var
. So, this was suggested as a new rule rather than an improvement or the rule that "variables should be initialized before being used".
This rule states that a variable is "used" when passed as a var
argument to a function call, so doing so without the variable being initialized should be warned against.
Rationale
If you do not accept in your code base that initialization could be done via a var
argument, then the rationale is the same as stating that a variable should be initialized before being used.
It is especially important for record variables, for which the Delphi compiler does not enforce this basic rule!