Thursday, April 19, 2007

Visual Basic, the story

Today on the Haskell mailing list, someone confused VBScript and VBA. Its not really surprising, the "Visual Basic" or "VB" name has been attached to at least 3 entirely different programming languages! This is an attempt to clear up the confusion. My first programming language (after .bat) was Visual Basic, and I loved it. I've worked on Excel/Word programs using VB, written applications for money in VB, and lots more besides - its a great language. Often people criticize VB for being "under powered" or a "beginners language" - those people are wrong - but that's not something I'm going to cover here :-) [Technical note: I may have got some of this wrong, I was a user of the language - not an implementer]

Visual Basic 3

We'll start the story at Visual Basic 3, because that's the first version I ever used. My Sixth Form would copy it to floppy disk if you bought in 3, which is basically school sponsored piracy. Anyway, this language was an imperative language, with build in support for graphical interfaces.

You can spot a VB 3 program a mile away, they look clunky and alas VB made it really easy to change the background colour of a form. The ability to easily change the colours made it a hotbed for garish colours - does you inhouse application have pastel shades of red? If so its either a C programmer who went to a lot of work, or more likely, a VB programmer without any sense of style. I've seen these apps running on point-of-sale terminals in some shops.

Visual Basic 5/6

I'm going to lump these two versions into one, there were some changes, but not many. Continuing the same trend as VB 3, but moving towards being an object orientated language. This language had a very strong COM interoperation - all VB objects were COM objects, all COM objects could be used in VB. The COM ability made it ideal for many things, and opened up lots of easy to use libraries. All windows become objects, and some of the clunky bits in VB 3 got depreciated in favour of the newer methods, but most programs still worked exactly as before.

Alas VB 6 still allows the background colours of a form to be set, but if you don't (please don't!) the program looks very Windows native - much more than Java or even C#.

Visual Basic for Applications (VBA)

At the time of VB 5, Microsoft moved over to using VB as the language of scripting in Office, replacing WordScript etc. The VBA language is VB, but rather than have the VB libraries, it has the Office libraries. The languages are identical in general use.

VBScript

Microsoft also decided they needed a JavaScript (or JScript as they call it, or ECMAScript as dull people call it) competitor. They decided to repurpose VB, changing it slightly to give it a more scripting feel. If you use IE, you can run VBScripts in the browser. If you like email viruses you can run the .vbs files you can your inbox. If you have active scripting installed, you can run .vbs files at the command line.

But please, don't use VBScript. JavaScript is a much nicer language, and works everywhere VBScript does and in more places besides. The language VBScript should quietly go away and die. There is one exception: ASP only provides one method (uploading a binary file) for VBScript but not JavaScript. As a result, I do have a website written in VBScript which I have to maintain.

VB.NET

And finally we get to the newest edition, or ¬VB.NET as I will refer to it. When changing to C# with .NET, Microsoft decided that shunning all the VB developers would be a bad idea, so instead they shunned them and wrote a syntax wrapper round C#. The ¬VB.NET language is a perfectly fine language, but its not VB. Things like late binding have been removed, the syntax has been made more regular, the object facilities have totally changed etc. If you have a VB project of any mild complexity, then you'll not get very far with the automatic converter.

If you are a VB developer looking to move towards the new .NET framework, I'd look at both ¬VB.NET and C#, before deciding which one to pick. The differences aren't that major, but at the time I was learning (.NET 1.0 beta) the ¬VB.NET was clearly the unloved younger brother of C# - the examples were all C#, and it was clearly the favoured language. Now both languages have evolved so they are not as similar, but neither is worthy of the VB name.

Me and VB

VB was my first language, and my "first choice" language for years. After learning C I initially poured scorn on VB for not being a "real language", then I realised I was an idiot and that VB is a lot better for most application programming than C, and you can always interface to a C .dll if you must. Now Haskell and C# (for GUI's) have become my standard languages - I haven't started up VB 6 for quite a while. I've got a few programs written in VB 6 around that I technically maintain, but none that I've had any reports on in ages, and none that I can imagine working on. I've got at least 50 programs in my VB directory, but I've forgotten quite where I put my VB directory - its certainly not been opened in a while.

Even though I may not use stand alone VB 6 anymore, I still maintain and actively work on some VBA solutions for accountants in Excel, and a couple of website templating systems using VBA in Word. I also develop and maintain a corporate website using VBScript, which requires new features adding at least once a year. VB is not yet dead, but its definitely going that way.

8 comments:

Creighton Hogg said...

I've been having to play a bit with VB6 for my job, and I've come to the conclusion it's not a bad language. It's not my favorite, and I think it has some odd restrictions, but for the most part it's not half bad. I actually like the way it handles events.

Unknown said...

VB.Net is not a "syntax wrapper" for C#, it has its own compiler.

It has always supported more of the .NET CTS than C#, and does have late-binding.

It gained LINQ and Expression-tree support before C#, as most of the compiler group guys doing "compiler innovation" were in the VB team (and were first to work directly with MSR teams).

It lagged behind C# in support for "anonymous delegate functions as closures" until the latest release.

I don't like the syntax of VB.Net, nor many of the limitations imposed by the CLR, but I would say that comparing VB (<= 6) with VB.Net is a silly exercise at best - they're completely different languages.

Neil Mitchell said...

David: I didn't mean it was literally a syntax wrapper, I just meant that at the first version, C# and VB.NET had very little differences, other than syntax. I did also say that now the differences are more pronounced - I know the LINQ stuff has hit both languages at different types, as has the generics.

Having done a quick search, VB.NET does have late binding. I'm pretty sure it didn't when I looked (VB.NET 1.0 beta 2), or it was not usable for some reason.

The reason for including ¬VB.NET in this comparison isn't because its similar to VB, but precisely because its _not_, and yet shares the same name.

Paul Moore said...

One advantage of VBScript over JScript is that it supports some COM features that JScript doesn't - notably output parameters and named parameters. As a result, there are certain COM objects which aren't accessible in JScript, but which are in VBScript.

Having said that, I do still prefer JScript where possible. Shame neither language is likely to be developed further - I'd like to see JScript support some of the newer JavaScript features...

Anonymous said...

I am just looking into haskell and my main language is C#. How do you combine the two when doing GUI stuff in c# and other in Haskell?

Neil Mitchell said...

Anon: I never combine C# and Haskell in one project - pick one or the other, otherwise the integration problems become larger than the advantages.

vipul said...

I have a dll written in Haskell and I would like to know that how could I use that dll in C# and also use intellisense,is that possible?

Neil Mitchell said...

vipul: I don't know - ask your question on the mailing lists instead and you are likely to get a better response. http://www.haskell.org/haskellwiki/Mailing_lists