Page 3 of 3
Keep code hidden until needed
Another big improvement, this time also shared with C#, is the ability to keep generated and manually written code separate using partial types - often called partial classes.
One of the initially off-putting features of .NET is that it uses a code generator to implement interactive form editing. VB 6 did something similar but it keeps all of the generated form code completely hidden. This made it seem much simpler for the beginner. With partial types VB 2010 also keeps its generated code away from the programmer by isolating it in a separate file. What this means is that now the definition of a class could span two or more files but this is no problem as the compiler automatically gathers the fragmented definitions to create a complete class. The big advantage of this approach over VB 6 is that you don’t have to look if you don’t want to but if you do the generated code is available for inspection and perhaps even modification.
Perhaps the most important change that effects the use of the language isn’t even strictly speaking part of the language. The key to RAD in an object-oriented world is having the right objects to hand and this is exactly what the My object library is all about.
Notice that these are objects not classes and they are ready to use without the need to instantiate or initialise. You can simply start writing statements that access information about the environment or perform common tasks.
There are some powerful facilities such as the TextFieldParser which allows you to read in files containing fixed field structured data but this would be to miss the point of the My objects. They provide easy access to the simple things that you use all the time. For example, the My.Computer.Clock object gives you the UTC time and the millisecond counter, the My.Forms object gives access to the collection of forms, their properties methods and controls that the application has created and so on.
You might think that the problem with this approach to RAD is that the object hierarchy would make it difficult to find out how to achieve some objective without having to spend time doing research. However the My objects are supported by IntelliSense and given the fairly logical and obvious naming you can usually discover what you need while working. There is also a resource designer which can be used to manage resources such as strings, images, icon, files etc, that the application uses and make them available via the My.Resources object.
There are many other features which in isolation don’t seem particularly important:
and so on. But they all fit together to create a more productive environment
- edit and continue debugging
- IntelliSense filtering and color highlighting
- statement completions that will not work in the security zone specified
- the compiler will suggest and apply corrections to faulty code
Visual Basic isn't just C# using slightly different syntax, it is a language suitable for RAD use in the long tradition of Basic.
One of the problems is that today VB .NET is often treated as if it was C# with some funny syntax and its unique features tend to be overlooked. For example, how often do you see something like:
Dim Form As new Form1
when there is no other instance of Form1 in use (you can just use Form1 as if it was an object). Perhaps we need to start a repository of VB idioms.
Some of its features might make purists unhappy, but they are effective in getting an application off the ground. However, given the careful design within an object-oriented environment Visual Basic 2010 provides a safe approach to RAD that promises not to run out in the later stages of the project.