Datasheet
Self-Documenting
Visual Basic’s syntax makes it much more self-documenting than other languages. Its keywords are
spelled out and easy to read. Statements that close blocks such as
End Do and Next employee explicitly
tell you what block is ending — in this case a
Do loop and a loop involving a variable named employee.
This makes the code much easier to read than code that ends blocks with braces.
The
Next statement that ends a For loop allows you to explicitly give the variable controlling the loop,
specifying exactly which loop is ending. Although you are not required to include this variable, you
should because it makes the code more self-documenting. The following code shows a small example:
For i As Integer = 0 To 100
...
Next i
Unfortunately, you cannot similarly attach the name of the variable controlling an If Then block, Do
loop, or other structure. That makes some sense, because these statements are often controlled by
Boolean expressions rather than simple variables. You can, however, include the controlling expressions
in a comment after the closing statement. The following code shows how you might add comments to a
Do loop and an If Then Else block:
Do Until all_done
...
Loop ‘ Until all_done
If num_employees <= 100 Then
...
ElseIf num_employees <= 500 Then ‘ If num_employees <= 100 Then...
...
Else ‘ If num_employees <= 100 Then ... ElseIf <= 500 ...
...
End If ‘ If num_employees <= 100 Then ... ElseIf <= 500 ... Else ...
As is shown in the last two comments, you don’t need to include every detail of the block; you just need
to include enough so that someone remembers the block to which the statement belongs.
The .NET Framework also uses nice, long, descriptive class, property, and method names, making it self-
documenting as well. That makes using the Framework easier, and provides a good example to encour-
age Visual Basic developers to use similarly descriptive names.
Prototyping and Simple Applications
It is extremely easy to build user interface prototypes with Visual Basic. For many applications, you can
put together a simple application in a few hours and get feedback from the customer before starting any
really difficult development. Providing a prototype quickly is far more effective than making users visu-
alize what an application will look like through drawings or textual descriptions.
Visual Basic is also extremely effective for building very simple applications. In a matter of minutes, you
can build a basic database application that lets you add, query, update, and delete records in a database.
Though you would need to spend some extra effort to make such an application bulletproof, adding val-
idations, and so forth, you can quickly build prototypes or throwaway programs for your own use.
10
Part I: Design
05_053416 ch01.qxd 1/2/07 6:28 PM Page 10