Jamie Collins said:
But unless you go back and remove the extraneous ones, it makes the
code harder to maintain e.g. for the developer who inherits your code.
I don't know, Jamie; I don't think it does. If the rule is always to
explicitly set object variables to Nothing when you're done with them,
then if this rule is followed, it seems to me the "information content"
of the code is the same.
I've recently inherited a code base where implicit ByRef has been used
for all arguments passed to subs/functions e.g.
Public Sub MakeWorkTable(TableName As String, TemplateName As
String)
The original author probably knew which arguments *need* to be ByRef
but because their fallback 'lowest common denominator' position was to
always use ByRef, I must check each one.
Now see, I think I follow the opposite protocol from you. I override
the default only and always when it matters. So if an argument *must*
be ByRef, because I'm going to change its value for the calling
procedure, I use the ByRef keyword. If an argument *must* be ByVal,
either because I plan to change its value inside my procedure and don't
want the change to be reflected upward, or because I hope to get a
performance boost from it, then I'll use the ByVal keyword.
To me, this policy conveys *more* meaning to the developer who might
read my code than just always explicitly stating "ByRef" because that's
the VB default.
More important than either policy, though, is to have a policy and be
consistent about it. That way everybody knows what to think when they
pick up somebody else's code.
Then there was that other
developer who used implicit Variant data type for all variables...
Yuck!