Browse DevX
Sign up for e-mail newsletters from DevX


Visual Basic .NET: A Punch of a Tool : Page 3

The newest version of Visual Basic now has support for full object-oriented programming, provides access to the .NET Framework and uses the power and flexibility of the Common Language Runtime. Never have there been more reasons for VB developers to consider making the move to Visual Basic .NET. Yet, amidst the excitement surrounding the .NET platform, some major productivity features have been lost in the shuffle.




Building the Right Environment to Support AI, Machine Learning and Deep Learning

Source code is more than just a serial stream of characters. It has structure, hierarchies, dependencies and references as well as control flow, logic and meaning. It contains a wealth of information that, given the ability to navigate and utilize it, can contribute enormously to programmer productivity. VB.NET automatically gathers rich structural information from your source code and uses it to power IntelliSense. IntelliSense encompasses a number of convenient features, such as Quick Info, close-parentheses highlighting, Parameter Info and statement completion. The statement completion feature has productivity benefits familiar to everyone. VB has had this feature for some time now. The Quick Info, Parameter Info and close-parentheses features, however, are new to VB.NET and they make a big difference. Take, for example, the Quick Info feature. There's no longer a need to perform a text search through your whole project or whole solution to find a class member's type information. By hovering your mouse over an identifier, the IntelliSense engine looks up the definition of that identifier and displays its accessibility and type. This is especially useful for constants because the constant value is displayed as well (see Figure 1).

Figure 1: The IntelliSense text-tip information for a constant.
Method information is equally important and perhaps more difficult to find with a text search due to the possibility of multiple overloads. It's also important to know each overload's parameter names and types, as this can aid in understanding an unfamiliar component. For convenience, VB.NET's IntelliSense engine displays a scrollable method-tip with complete overloads and parameter information for every method, such as displayed in Figure 2. The time savings can be substantial. The cursor never needs to leave your current edit point because the essential information sits right at your fingertips. IntelliSense performs the navigation and searching for you.
Figure 2: IntelliSense method-tip information for a method with multiple overloads.
Lastly, it can be a real nuisance to match close-parentheses inside complicated logical expressions or deeply nested function calls. No one wants their time wasted dealing with these kinds of mundane issues. VB.NET does the counting for you by highlighting the matching open-parentheses, saving you time and aggravation. It's a nice feature that has finally made a debut in the VB development environment.

Background Compilation

The VB.NET compiler runs continuously in the background on a low priority thread, in effect performing a build every time you make an edit.
The process that gathers the data for use by the IntelliSense engine is called background compilation. That is, the VB.NET compiler runs continuously in the background on a low priority thread, in effect performing a build every time you make an edit. Not only does background compilation power IntelliSense, but it enables the "Pretty Lister" to automatically format your code (described below), populate the dropdowns (the navigation aides at the top of an editor window) and provide real-time compile errors. The last feature, unique to Visual Basic .NET, is perhaps the most significant advance from VB6. Whenever the compiler detects a change in source code, it re-runs the compilation and instantly presents any errors detected as a blue squiggle line underneath the offending text (the compiler also adds the errors into the Task List window). This direct and immediate feedback helps to not only reduce the time you spend detecting and fixing errors, but by association helps you avoid future errors. Immediate error reporting also works across projects, which can be a major productivity boost. Imagine the following scenario: you are developing a random number generating component called Rand with a class member GetNext, which returns the next random number. In the same solution you have another VB project that consumes this component called Engine. If you edit the Rand class, such as changing the accessibility of GetNext from Public to Private, you can observe the effects of this edit right away (which is an error at every use of GetNext because it has become inaccessible). Figure 3 shows this behavior.

Figure 3: Background compilation displays compile errors immediately, even across projects.
Also notice in Figure 3 that a few other simple mistakes have been made in the Engine component (which was clearly written by someone else). The variable accum has been misspelled acum and the variable index, which is type Decimal, is being implicitly used as an Integer. The syntax of the statement is correct, but because the background compiler performs an entire compilation, it makes all the necessary type checks to detect the errors. These kinds of simple errors are undetectable in conventional tools, such as VB6, without manually starting a new build. What does all of this mean? It means that for the first time the compiler is truly interactive. Building the solution is no longer a separate step of the development process. Just write the code and fix the errors you (accidentally) create when you create them. Then press F5 and your program will run. It's so simple and will save you a lot of time. (See Sidebar: Customizing your build with the Visual Basic .NET command line compiler)

Thanks for your registration, follow us on our social networks to keep up-to-date