I hate VB, there, I said it

Visual Basic was a good thing back in the day.  But it is seriously ugly.  AndAlso?  OrElse?  So much extra for so little gain.

VB:

If (String.IsNullOrEmpty(item.ImageUrl) _
    AndAlso ((item.Variants.Length = 0) OrElse Not HasFiles(item.Variants))) Then
        FileNotFound.Visible = True

c#:

if (string.IsNullOrEmpty(item.ImageUrl) && 
    (item.Variants.Length == 0 || !HasFiles(item.Variants)))
        FileNotFound.Visible = true;

AndAlso? OrElse? So much extra for so little gain.  Yes, I know if I gave it to my mom, she could read the top line but not the bottom.  With 1 minute of talking, she could understand ! is not, || is or, and && is and.

And don't even get me started on the white space.

chris Jul 9, 2009 @ 5:31 AM

# re: I hate VB, there, I said it - VB should be purged from the sphere of human creation
Check out this bit of manky VB cod:

Public Function IsIn(ByRef oCollection As Collection, ByRef stName As String) As Boolean
Dim o
On Error GoTo errorPig
o = oCollection(stName)
IsIn = True
Exit Function
errorPig:
IsIn = False
End Function

Public Function IsObIn(ByRef oCollection As Collection, ByRef stName As String) As Boolean
Dim o As Object
On Error GoTo errorPig
Set o = oCollection(stName)
IsIn = True
Exit Function
errorPig:
IsIn = False
End Function

Clint Jul 20, 2009 @ 3:13 AM

# re: I hate VB, there, I said it
Don't you need to declare what the type of Collection you have is in VB? in c#, you'd have to say public bool IsIn(Collection<string> oCollection, string stName)
{
// code
}

I'd also just do oCollection.Contains(stName);

Post a Comment

Please add 2 and 1 and type the answer here: