Pros and Cons of VB & VBA? Pros and Cons of VB & VBA? vba vba

Pros and Cons of VB & VBA?


VB6, VBScript, and VBA have the reputation because they just aren't industrial strength languages. Notably:

  • No OOP. Sure, you have classes and modules, but no inheritance. VB isn't a low-level language, it needs real objects.
  • No first-class functions, so you can't even simulate OOP or polymorphism.
  • Lack of a well-developed class library. VB6 has a small library of built-in functions, and almost all other functionality is delegated to Windows calls or (usually pricey) third-party components.
  • Lousy error-handling. ON ERROR RESUME NEXT is a pox on the planet.
  • Although its not the fault of the language, VBA earned a bad reputation by association with MSAccess.

Of course, VB wasn't really intended to be an industrial strength language, so maybe nothing mentioned above is really proper criticism of the language at all. Fortunately VB.NET and the latest versions of VBA fix everything above, so VB.NET is on par with any other "serious" language in the marketplace.


[anecdote]

In defense of VB, I find most people criticize the language just to go along with the status quo, not because they've actually used it.

A few years ago, in a chatroom, I ran across young neophyte railing against a VB6 developer for using such a crappy language. I innocently asked "what's wrong with VB".

The first thing he said was "Because its a WINDOWS language!" So I pointed out that Borland Delphi is a Windows only language*, but I've never heard anyone malign it for that reason. (* There was a product called Kylix which cross-compiles to Linux, but its expensive, buggy, and discontinued. Its been a while since I've used Delphi, but last I'd heard, its still not ready for Linux.)

So, he said "It has a HORRIBLE SYNTAX!" Is that really the reason people hate this language? I'd say Perl, Lisp, and C++ are worse on the eyes than VB.

Next, he says "Its too easy to learn!" Well, I'd consider that a point in favor of the language. I'll never write a GUI by hand if I have a drag-and-drop designer at my disposal. What else you got?

So finally, grasping at straws, he comments "It has... no string manipulation functions". Left, Right, Mid, Replace, InStr and Trim. QED noob.

Interestingly, VB has features found some "hacker" languages, namely variant datatypes and duck typing. Compiled code performed reasonably well, interop between COM and native windows DLLs was easy, and the GUI editor basically set the bar for all future RAD development.

[/anecdote]


Read some of Joel Spolsky's articles and you'll feel better about yourself. From his article Working on CityDesk, Part Three:

Visual Basic is an extremely productive way to write code, especially GUI code. Want bold text on a dialog box? It's one click in VB. Now try doing it in MFC. You have to create a subclassed control, it's a big mess, you have to know all about LOGFONTS and Windows window subclassing and a bunch of other things and you need about three lines of code once you have the magic class.

But many VB programs are spaghetti, either because they're done as quick and dirty one-offs, or because they're written by hack programmers without training in object oriented programming, or even structured programming.

What I wondered was, what happens if you take top-notch C++ programmers who dream in pointers, and let them code in VB. What I discovered at Fog Creek was that they become super-efficient coding machines. The code looks pretty good, it's object-oriented and robust, but you don't waste time using tools that are at a level lower than you need. I've spent years writing code for C++/MFC and years writing code in Visual Basic, and let me tell you, VB is just much, much more productive.

This simplicity attracts a lot of new programmers. Saying there are a lot of bad programmers using Visual Basic does not mean Visual Basic is a bad language; it simply means that Visual Basic is accessible to bad programmers (AKA new programmers).


I work in a place where all the code is C#, not VB .NET. One developer wrote most of the code. You know how he achieved this feat? Easy: He copied-and-pasted all over the place. A given method might have anywhere from a few to hundreds of copies throughout the system.

Good developers can be good in any language. Crappy developers can be crappy in any language.