What are some conventions for naming a variable in cases where the name of the variable ought to be identical to the name of the function? I'm using VB.Net.
I often have this problem when writing functions that either perform some mathematical operation, or generate an object. The return variable is declared inside the function, and values in that variable are set throughout the function.
As an example:
Public Function Sum(arrayOfValues as double()) as double()
dim outputSum as double(arrayOfValues.GetUpperBound(0))
For i As Integer = 0 To arrayOfValues .GetUpperBound(0)
outputSum += v(i)
Next
Return outputSum
End Function
Here outputSum could not be simply called "sum". Since VB.Net is case insensitive, the name would conflict with the name of the method.
Here's another example:
Public Function IsValid(data As List(Of MyObj)) As Boolean
Dim retVal As Boolean = True
For Each d As MyObj In data
If d.SomeProperty > 42 Then
retVal = False
End If
Next
Return retVal
End Function
What name can I use that is clear, but does not add unnecessary noise? In the past I have used just "output", and sometimes "retVal" if the return type is of primitive type.
*I've also seen many coders use arbitrary abbreviations just to get around the compiler (such as "MaximumValue" and "maxVal"). This drives me crazy.