Comments on “Thirteen Ways to Loathe VB” by Verity Stob

In in her article “Thirteen Ways to Loathe VB (published on Dr. Dobb’s Portal, August 12, 2001) Verity Stob attempts to draw an image of Visual Basic being a programming language for non-professionals, whom she dispraisingly calls “babies”. The purpose of this article is to show factual errors in Stob’s article and to clarify some of the points she raises from a technical perspective. In some cases background information is provided and additional code samples are shown for illustration purposes.

1. The author claims that in case a function with the signature FuncName(Param1, Param2) gets called as FuncName(Param1, Param2) the objects passed to the two parameters are passed by value although they are implicitly declared as reference parameters, which can alternatively denoted using the ByRef keyword. This claim is invalid because the code sample it is based on does not compile. Specifically, the compiler detects and raises a syntax error on the function call FuncName(Param1, Param2).

However, the author is not completely wrong, it is just the sample that does not demonstrate what it is intended to do. The only case where the compiler will accept parentheses around the argument list is a call to a procedure that has only a single argument, like FuncName(Param1). In this case the parentheses are not considered to enclose the argument list. Instead they are considered surrounding the object passed as the argument value itself, thus enforcing it to be passed by value. The procedure call FuncName (Param1) (just notice the space character right after the function name) is semantically equivalent to the call Call FuncName((Param1)).

2. The behavior described by the author is specified behavior. It is even possible to write Dim i As Integer, o, j As Integer, which will cause i and j to be typed as Integer and o to be of type Variant. By omitting the type specification in a variable declaration the variable gets automatically typed as Variant.

3. This point is only of theoretical significance because in practice the names of array variables and functions are rarely the same.

4. Despite the fact that Option Base 1 is rarely used, Visual Basic even supports the use of arbitrary lower bounds for arrays, like Dim Items(10 To 20) As Item.

5. Collections are not the modern, object-oriented versions of arrays. A collection in Visual Basic is different from an array in terms of memory management, runtime characteristics, and supported operations.

6. No comment because no technical problem is raised.

7. It is not obvious which problem the author is seeing here. Visual Basic does not provide a short-hand way to specify the initial data for an array. However, arrays can be filled with data read from a file using the Get statement on a file opened in binary mode. Variant arrays can be filled using the Array function, like Fruits = Array("Apple", "Pear", "Banana").

8. The concept of Const in Visual Basic is different from const-correctness as known from C. Constants in Visual Basic are simply named values.

9. Integer is a 16-bit data type in Visual Basic because of Visual Basic’s history as a programming environment for a 16-bit hardware platform and operating system. This is different from C, where the width in bits of the type int is equivalent to the standard size of an integer on the machine. Although it is attracting to have types which adapt their width depending on the system, this design has some serious drawbacks too. For example, it makes detecting problems caused by different bit-widths on different machines harder.

Visual Basic provides a 32-bit signed integral numeric type named Long though. It is nowhere written that Integer is a fixed synonym for “32-bit signed integer”. Changing the width of the Integer data type to 32-bit in Visual Basic .NET caused a lot of confusion and made migration of source code from Visual Basic 6.0 to Visual Basic .NET unnecessarily complicated.

10. The point raised by the author is not a problem in practice. Moreover, providing a visual distinction between value and reference assignment can even be seen as an advantage too because it makes the difference between reference and value assignment more obvious for the reader.

11. Some of Visual Basic’s intrinsic controls provide a Value property which can be used to get or set the control’s value. Valid values for different types of controls such as command buttons, option buttons, and check boxes are specified in the documentation on the Value property. Possible values for the check box’ Value property are grouped in the CheckBoxConstants enumeration, namely vbChecked, vbUnchecked, and vbGrayed. If the Value property was intended to return a Boolean value then its type would be Boolean.

12. No comment because no technical problem is raised.

12.5 The behavior of the development environment can be easily changed in “Tools” → “Options...” → “General” → “Error Trapping” by selecting the option “Break on Unhandled Errors”.

12.7 In order to make sure a missing End If gets detected when running the project from within the development environment, the project must be run using “Run” → “Start, Full Compile”, which is accessible via the Ctrl+F5 keyboard shortcut too.

12.8 First, Static is not an access modifier like Private and Public. Although there are very rare cases where using static procedures makes sense, they are used in some great code samples, like a pure Visual Basic implementation of a fast Replace function. By the way, the author is missing that functions can be marked with the Friend access modifier.

13. No comment because no technical problem is raised.