Myth-Busting Busting

The Classic VB petitioners have posted a FAQ page explaining their goals and the motivations behind them. (Hint: Contrary to what you may have read elsewhere, the impending end of mainstream support for VB6 is not the primary issue!) On the lower portion of that page is a section titled, “Myth Busting” which includes a myth of its own:

To take a trivial example, there is no defensible reason why a QuickSort algorithm should need to be rewritten because you have a new compiler for a language targeting a new platform.

Is it true that a VB6 QuickSort algorithm must be rewritten in order to recompile it for .NET? Let’s see…

Here’s a VB6 QuickSort implementation I found on the Web:

Public Sub Quicksort(ByRef list() As Integer, ByVal min As Long, _ 
    ByVal max As Long)

    Dim med_value As Long
    Dim hi As Long
    Dim lo As Long
    Dim I As Long

    ' If min >= max, the list contains 0 or 1 items so it is sorted
    If min >= max Then Exit Sub

    ' Pick the dividing value
    I = Int((max - min + 1) * Rnd() + min)
    med_value = list(I)

    ' Swap it to the front
    list(I) = list(min)

    lo = min
    hi = max
    Do
        ' Look down from hi for a value < med_value
        do while list(hi) >= med_value
            hi = hi - 1
            If hi <="" lo then exit do
        loop
        if hi <="" lo then
            list(lo) ="" med_value
            exit do
        end if

        ' swap the lo and hi values
        list(lo) ="" list(hi)

        ' look up from lo for a value >= med_value
        lo = lo + 1
        Do While list(lo) < med_value
            lo ="" lo + 1
            if lo >= hi Then Exit Do
        Loop
        If lo >= hi Then
            lo = hi
            list(hi) = med_value
            Exit Do
        End If

        ' Swap the lo and hi values
        list(hi) = list(lo)
    Loop

    ' Sort the two sublists
    Call Quicksort(list, min, lo - 1)
    Call Quicksort(list, lo + 1, max)

End Sub

And here’s the same implementation in VB.NET:

Public Sub Quicksort(ByRef list() As Integer, ByVal min As Long, _ 
    ByVal max As Long)

    Dim med_value As Long
    Dim hi As Long
    Dim lo As Long
    Dim i As Long

    ' If min >= max, the list contains 0 or 1 items so it is sorted
    If min >= max Then Exit Sub

    ' Pick the dividing value
    i = Int((max - min + 1) * Rnd() + min)
    med_value = list(i)

    ' Swap it to the front
    list(i) = list(min)

    lo = min
    hi = max
    Do
        ' Look down from hi for a value < med_value
        do while list(hi) >= med_value
            hi = hi - 1
            If hi <="" lo then exit do
        loop
        if hi <="" lo then
            list(lo) ="" med_value
            exit do
        end if

        ' swap the lo and hi values
        list(lo) ="" list(hi)

        ' look up from lo for a value >= med_value
        lo = lo + 1
        Do While list(lo) < med_value
            lo ="" lo + 1
            if lo >= hi Then Exit Do
        Loop
        If lo >= hi Then
            lo = hi
            list(hi) = med_value
            Exit Do
        End If

        ' Swap the lo and hi values
        list(hi) = list(lo)
    Loop

    ' Sort the two sublists
    Call Quicksort(list, min, lo - 1)
    Call Quicksort(list, lo + 1, max)

End Sub

Can you spot the difference? (If you intend to point out that Integers and Longs are different sizes in VB6 and VB.NET, please include an example demonstrating how that difference affects the algorithm’s behavior.)

Here’s another:

Why not leave functioning code in VB6, and write new code in VB.NET?
That's a fine solution for the problems it fits. Many developers can indeed let existing applications linger in VB6 forever (assuming future OS changes don't break them), and concentrate all their efforts on developing new VB.NET-based applications. For the great majority of VB developers, however, there is continuing need to revisit and revise legacy applications. While Microsoft may no longer want to support VB6, great numbers of VB6 developers still intend to support their customers with ongoing bug fixes and application enhancements.

Ahem. What prevents VB6 developers from supporting their customers with bug fixes and application enhancements in VB6? Nothing. That’s exactly how my employer is supporting its customers’ VB6 code.

permalink 17 Mar 05 2:09 AM · Comments (5) · Tags: .NET, VB
My Thoughts on the Classic VB Petition

Much has been written over the past week regarding a petition asking Microsoft to continue development of “Classic VB.” I have chosen not to sign the petition; here’s why:

First of all, let me emphasize that I am not unsympathetic to the difficult choices faced by those with a large investment in pre-.NET VB code. Some people have built entire companies around products written in VB; the future of that code is quite literally the future of their livelihood. Microsoft has put them in the unenviable position of having to choose whether to leave their code in VB6 and hope that it remains viable, or to rewrite it some other language, which will cost time and money.

If I had been in charge when VB.NET was being designed several years ago, I would certainly have kept those developers in mind, and not broken compatibility with VB6 unless it were absolutely necessary. But wait: Microsoft is full of brilliant people; don’t you think the VB team thought of this? It’s the height of arrogance to believe that we’re aware of considerations that have never occurred to them.

VB.NET is a product of conflicting goals: On one hand, the VB team sought to maintain backward compatibility with VB6. On the other hand, they needed to make VB.NET a first-class .NET citizen, or risk further accusations that it’s a “toy language.” On a third hand, they needed to ship .NET and its key languages as quickly as possible in order to compete with Java and other tools which were nipping at Microsoft’s heels. While there were undoubtedly features the VB.NET team would like to have delivered in version 1.0 (such as edit-and-continue and closer compatibility with VB6), the tight schedule simply didn’t allow it.

How should Microsoft have handled cases in which “the .NET way” and “the VB6 way” were at odds (such as the size of the default integer data type)? The “correct” answer depends upon your point of view; the VB team was damned either way. I’m sure there were many spirited discussions on issues like this one. We may not agree with the final decision, but that doesn’t mean Microsoft didn’t seriously weigh both sides of the issue.

This is one problem I have with the Classic VB petitioners: They focus solely on the goal of VB6 compatibility, while ignoring the perhaps equally important goal of parity with other .NET languages. Any proposal which Microsoft is to take seriously must consider VB’s future, as well as its past.

Another issue: Microsoft doesn’t create development tools out of the goodness of its heart. The business case for tools like Visual Basic and Visual Studio is to drive adoption of Microsoft’s platform du jour. (Remember Steve Ballmer’s “developers, developers, developers” chant?) In the last decade, that platform was Win32, and versions 4 through 6 of VB helped a lot of people create a lot of software for that platform.

Today, the target platform is .NET. Company representatives have stated that Microsoft has “bet the company” on it. But here’s the problem: Some of the Classic VB petitioners — in fact, many of the driving forces behind the petition — have made no secret of the fact that they have little interest in learning or using .NET. They would have Microsoft keep cranking out new versions of COM-based VB for as long as it’s willing to do so. What’s the incentive for Microsoft to spend millions of its dollars and years of its developers’ time, if it won’t help drive adoption of its current platform?

Now, if the petition had said, ‘We want Microsoft to help us migrate our VB6 applications to .NET as easily as we were able to move our code from, say, VB3 to VB4,’ I would have signed in a heartbeat. Classic VB developers could preserve their code assets, and Microsoft would get potentially millions of additional developers creating .NET applications. Everybody wins.

Of course, nothing prevents the Classic VB petitioners from working on their own compiler/conversion tool/compatibility library to ease migration of VB6 code to .NET. This would be an ideal project for the 2,000+ signers of the petition, and I have repeatedly suggested and offered to contribute to such a project. I have also pointed out that the source code for two “nearly-VB” .NET compilers is readily available. If you’re interested in contributing to such a project, please post a comment below.

permalink 17 Mar 05 12:19 AM · Comments (2) · Tags: VB