I Just Called to Say You Shouldn’t Have

To Call or not to Call?  That is the question.  Well it is fairly simple really but something that even to this day I still see used prolifically.  I have not used the Call keyword in a VERY long time.  In fact even in VB3, yes that long ago.  I never used it unless I needed to. 

You use the Call keyword when the called expression does not start with an identifier).  What does this mean?

Sub WhenToCall()
		Call (Sub() Console.WriteLine("This is starting without an identifier, so use the Call statement."))

		Dim myClass As ClassWithMethod = New ClassWithMethod
		myClass.NoCallRequired(False)
		
		Call New ClassWithMethod().NoCallRequired(True)
End Sub

Class ClassWithMethod
	Public Sub NoCallRequired(ifNeeded as Boolean)
		If ifNeeded Then
			Console.WriteLine("No identifier is used, a Call statment is required.)
		Else
			Console.WriteLine("Calling this is not needed since we are using the identifier.")
		End If
	End Sub
End Class

The above code shows a method and a class with a method.  It shows two places where Call is needed (no identifier) and one where Call is not needed, using the identifier.  It is clear to see the difference between the two.

Both of the mechanism are not often standard ways of calling procedures or methods, but the mechanism is there.  But it is Recommended that when calling a procedure that uses an identifier, which I would say is most of the time.  DO NOT USE CALL. 

Sure, that is putting it strongly put, but it isn’t needed, it is an extra word you are typing and to give an indication.  The current application I am updating, from someone else, uses call 1,498 times.  Might not seem like much out of the entire solution but there was more in there as since I have started updating the application any time I see it, I remove it.  But that 1,498 is almost 2% of the entire code are calls,

So, please, VB programmers, I know it might be a difficult to do, like using strongly typed variables (then objects), explicitly declaring our variables before use and using true object oriented programming techniques, but if we have conquered those then removing 4 letters before our procedure calls, might be easy. 

So please, think of the future let us band together to get Call depreciated and eliminated from the language, like Variant data type. 

Advertisements

Posted on November 25, 2013, in Article, Development and tagged , . Bookmark the permalink. Leave a comment.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: