The Coding Monkey

Wednesday, June 08, 2005

I Hate VB.NET!

Those who know me know that I hate Visual Basic .NET. This is not a passing hatred mind you... it's a pretty strong one. Unfortunately my current client is a VB house, so I have to use it every day. There are oh so many things I dislike about it, which I'm not going to recount all at once here. However, there is one problem with it that I want to point out right now, only because it led me to needlessly debug new code of mine for about 30 minutes.

No Warnings! Specifically, it doesn't warn you if all your code execution paths don't return a value for a Function. This in my mind is a very basic warning that should be included (C# does). I'll provide an example:

Public Function GetValue() as Object
   Dim obj as Object
   ' Do a bunch of complicated things to assign obj here

   ' Should have Return obj here
End Function

Public Sub DoSomething()
   Dim obj as Object = GetValue()
   If ( obj Is Nothing ) Then
      ' Ooops... Will always get here!
   Else
      ' Will Never Get Here
   End If
End Sub

Now then... I understand it's a bit more complicated because you can also use the function name itself as a variable and it will create an implied Return call with it... but I don't know how many times this has screwed me up in the past. Add a warning if you don't ever assign to the Function name, or add a Return statement!

0 Comments:

Post a Comment

<< Home