Prevent pitfall with direct calls to Methods with no parameters

Why is there an issue?
Changing a functions signature might not result in problems during compilation while resulting in a crash lateron. As calling a function which doesn’t have parameters doen’t need paranthesis, so paranthesis after that function call might be interpreted as Array Index Operation.
VB Pitfall
So changing a function with signature Function functionname(x As Integer) As String to Function functionname() As String dramatically changes behavior for calls like this: Dim text As String = functionname(5).

What could be its impact?
You not only retrieve an unexpected result, in case of the string beeing to short it will fail with ArrayOutOfBounds.

How to prevent this pitfall?

Always use parenthesis for function calls to functions without parameter.
And add another parenthesis afterwards in case of wanted array usage.

Non-Compliant
Function test() As String
Return "Test"
End Function

...
Dim text As String = test(5)
Dim text2 As String = test

Compliant
Function test() As String
Return "Test"
End Function

...
// Use additional parenthesis
Dim text As String = test()
// In Case of wanted Array Index
Dim text2 As String = test()(5)

Type

In my opinion this is a Code-Smell which could result in serious crashes and problems.

Thanks and best regards

Thiemo Hoffmann