Why I don’t like Visual Basic.NET – Part #2

As I have mentioned some time ago – I’m not a fan of VB.NET. Here is another example why:
Let say we have such function:

    Function CalculateAmount(ByVal items As List(Of Item)) As Decimal
        Dim amount As Decimal = GetSum(items) ''returns 15

        Dim tax As Decimal = CalculateTax(amount, items) ''returns 5
        Dim serviceCharge As Decimal = CalculateSC(amount, items) ''returns 2

        Return amount + tax + serviceCharge ''returns 27
    End Function

at first look everything looks fine. But, why there 27 as result, and not 22?
Oh, that’s obvious. Someone declared CalculateTax as:

    Function CalculateTax(ByRef amount As Decimal, ByVal items As List(Of Item)) As Decimal
        Dim tax As Decimal
        ''some magic
        amount += tax
        Return tax
    End Function

In above example it might be easy to find issue. But in more complex code, where developers don’t always care about it…

C# made it easier, you can either use ref or out, and you have to add this modifier when function is called. So much easier to read.

Why I don't like Visual Basic.NET – Part #1

In my work, I have to work quite often with Visual Basic. This language have some advantages over C#, but most of the time, it is very annoying.

Let’s take Interfaces for example:

Public Interface IDoNothing
    Sub Method()
End Interface

And we can implement two classes:

Public Class FirstClass
    Implements IDoNothing

    Public Sub Method()
        Console.WriteLine("FirstClass.Method")
    End Sub

    Public Sub ThisIsMethod() Implements IDoNothing.Method
        Console.WriteLine("FirstClass.ThisIsMethod")
    End Sub
End Class

Public Class PrivatClass
    Implements IDoNothing

    Private Sub Method() Implements IDoNothing.Method
        Console.WriteLine("PrivatClass.Method")
    End Sub
End Class

Czytaj dalej Why I don't like Visual Basic.NET – Part #1