This article may contain URLs that were valid when originally published , but now link to sites or pages that no longer exist. To maintain the flow of the article, we've left these URLs in the text, but disabled the links.
The Future of Visual Basic: Web Forms, Web Services, and Language Enhancements Slated for Next Generation |
||||||||||||||||||
Joshua Trupin | ||||||||||||||||||
|
||||||||||||||||||
isual Basic® has undergone a decade of evolution and adaptation. One of the things I've liked about the language since its earliest incarnation is that, at its core, you can still write programs just the same way as you could in 1991. There have been many improvements to the package since then, but they have usually complemented rather than obscured the original purpose of the development tool itself—making it simple to rapidly design, develop, and deploy outstanding object-oriented applications. Visual Studio Web FormsThe next release of Visual Basic, as part of Visual Studio, will likely introduce a new concept, the Web Form, for Web developers. The purpose of Web Forms will be to extend the RAD capabilities of Visual Basic to encompass the broad reach of a Web application. Developers using any of the languages in Visual Studio will be able to use these shared Visual Studio Web Forms.A Web Forms page exists in two parts: an HTML file representing the visual representation of the page, and a source file that handles the page's events. Since almost a third of Visual Basic-based development today is targeted at the Web, Microsoft plans to enhance these capabilities further. With the next version of Visual Basic, you'll be able to design a Web Form much as you would create a form in Visual Basic today. You'll have a palette of Web controls you can drag to the HTML designer, then set properties on them and write appropriate code (see Figure 1). In short, you'll be able to do exactly what you've always done in Visual Basic to create a form. You'll have full IntelliSense®, WYSIWYG form design, and compiled code. So if you know how to write an application in Visual Basic, Web Forms will make you into a Web developer without changing the way you work.
Web Forms run on the server and pass only the HTML-based form down to the client. Just as an Active Server Page (ASP) page isn't browser-specific, neither is a Web Form-based application; the processing is performed on the server. In effect, you're running a program that generates a remote user interface with HTML 3.2. Unlike an ASP page, the code is compiled instead of interpreted, so speed is much improved. Web ServicesWeb services represent the second major improvement slated for the Visual Studio development system. In a nutshell, a Web service is a middle-tier business function that's exposed via standard Web protocols. They can communicate through firewalls since they use HTTP as a transport mechanism (see Figure 2). You'll be able to build multiple Web services into a Web app simply by pointing to the appropriate URL. At runtime, all the intercomponent calls will automatically be packaged and handled through an XML interface. Developers can create and use Web services on any platform, in any language. If you need security, you'll be able to use Secure Socket Layer (SSL) or standard authentication techniques.
If this is already starting to sound a bit familiar, it's with good cause. The mechanism used to pass data from one component to the next is SOAP—the Simple Object Access Protocol. Don Box covered SOAP extensively in the March 2000 issue of MSDN™ Magazine (https://msdn.microsoft.com/msdnmag/issues/0300/soap/soap.asp).
When you build the project containing this function, Visual Basic will automatically create an XML description of this function and publish it to the Web:
The XML file will be used to describe the Seahawks function. If you're using Visual Studio, you'll be able to drag any exposed Web service right into your application, creating a new class file. If you want to call a Web service anywhere on the Internet, all you'll need to do is create a new instance of the Web service class and call its exposed methods.
To facilitate the creation of Web services, Visual Basic is expected to introduce a new type of project, cleverly called a Web Service. You'll be able to design and deploy your Web Service to a remote server as easily as you would create a local DLL today. Language ImprovementsFor what seems like forever, there's been a natural tension between developers who are partial to Visual Basic and those who prefer a more "comprehensive" language like C++ or Java. More than once, I've had to defend my favorite programming language from charges that it was somehow a toy language because it lacked certain OOP features.Well, guess what? The next version of Visual Basic should finally put those complaints to rest. Microsoft plans to introduce the big three of object-oriented programming: inheritance, polymorphism, and overloading. And that's not all! Other new constructs, including structured error handling and freethreading, will be introduced to the language. Inherited functions save time and improve reusability by allowing you to design a base class, then write classes that inherit the functionality of the original. For instance, you might write a base class called BaseClass with a single function like this:
Now you want to write a second class that uses this GetCustomerName function as well as implementing new functions of its own. What was the old way to do this? Well, there was no old way. The new way, however, is to insert a simple line at the top of the new class like so:
Overloading is the process of creating two or more functions with the same name, but with different function signatures. In a way, Visual Basic already does this for you when it performs implicit type conversions on function calls and property settings. Consider these two lines of valid Visual Basic code:
In each of these calls, the text in Text1 will be set to the string "7". This is an overloaded call because it knows how to handle various data types thrown at it, treating them as variants and automatically converting them. Visual Basic also converts arguments when you pass them to an explicitly typed function. These two function calls
both work properly with this function:
So if Visual Basic already lets you pass multiple variable types to a function, why the need for overloaded functions? While a single function can handle multiple data types today, it can't react differently depending on the data type that's passed in. Instead, consider these two functions:
With overloading, you'll be able to implement functions that react differently based on input type. This will be important because of another planned feature of Visual Basic—default type safety. While auto-conversion of variables is often a handy feature, it can conceivably get you into trouble. In the previous SetVal example, what if you meant to pass in character code 7, not the string "7"? The next version of Visual Basic will catch this and throw an error by default. (This feature can be disabled if you have code that relies on previous typeless behavior in Visual Basic.)
More Language FeaturesThe next version of Visual Basic will likely provide several language features beyond the object-oriented improvements I just described. With an eye towards scalability and reuse, there will be new options for thread creation, error handling, and various long-needed language enhancements. Visual Basic currently supports an apartment-threaded model. While this model provides some real efficiency to deployed apps, it stops short of ideal. The next version of Visual Basic is expected to improve on this, offering a freethreaded model that will really make a difference when you're writing scalable Web applications. Visual Basic will include language constructs that let you spawn multiple threads. A typical thread-spawning operation might look like this:
As you can see from this example, the next version of Visual Basic is slated to have an AddressOf construct that will return the address of a function. No longer will you be forced to ignore API functions that need a function pointer! If you need to provide a callback, you'll be able to do it.
There are a few other miscellaneous improvements that should quickly become natural to existing users of Visual Basic. The next version will allow you to initialize variables on the same line on which they're declared:
You'll be able to create and initialize new objects all in a single expression. You'll also be able to share variables across classes. Last, but not least, the inheritance concept will be extended to the user interface elements of a project. One repeated comment about Visual Basic has been that it's hard to create multiple forms with identical elements on them. (This is a frequent requirement in a corporate environment.) With the next version of Visual Basic, you should be able to do just this with template forms. Preparing for the FutureWhere does this preview leave you today? That's a good question, but there is an answer. Over the past year, there's been a visible shift away from early ASP development efforts, which frequently consisted of humungous ASP scripts running an entire program. Since ASP interprets script code, people started to discover the inherent limitations of a technology that was designed to tie components together. I've heard from more and more developers who have migrated their business functionality out of script code completely, putting it in faster, compiled modules that are written in C++ or Visual Basic and tied together through COM interfaces.This is definitely the way to go, for just about every reason you can imagine. Using Visual Basic to design a component is really no harder than using VBScript or JScript®. You'll create faster code, it'll be easier to scale with your needs, and when the next version of Visual Basic is released, you'll be able to use it to create Web-based objects that are glued together with ASP. In general, going the components-and-glue route should be considered a best practice for now and the future. As I mentioned earlier, there's a significant installed base that uses Visual Basic (and WebClasses) to create Internet-ready applications today. The problem is, most WebClass-based applications are not well-architected. They don't separate the different tiers of the application well, mixing middle-tier processing with DHTML-based user interface. The changes scheduled for the next version of Visual Basic will probably supplant WebClasses as the Web development method of choice, since they're more scalable, more powerful, and are actually language-agnostic—they'll work across the spectrum of Visual Studio tools. The transition will be a lot easier if you pay attention to the basic rules of multitier development. Specifically, keep middle-tier processing separate from the display layer. It is strongly recommended that you do this by following the Windows® DNA 2000 architecture. Core business functionality should end up in a middle-tier component that's authored in your favorite compiled language. These components, in turn, can be tied together in an ASP file with just enough script to allow the various elements to work together. If you keep most of your logic in the business objects and not in script, you'll be better off. It's not just a good idea for a future transition to Web services, it's a good practice to follow in general. |
||||||||||||||||||
For related articles see: https://msdn.microsoft.com/vstudio/nextgen https://msdn.microsoft.com/msdnmag/issues/0300/soap/soap.asp Background information: https://msdn.microsoft.com/vbasic https://www.microsoft.com/dna https://msdn.microsoft.com/xml/default.asp Joshua Trupin is a technical editor for MSDN Magazine. He has written numerous articles for MSJ and MIND, the predecessors to MSDN Magazine, as well as a book, Hoop Stats: The Basketball Abstract. He lives on Long Island with his wife, two children, two dogs, and four pet CHUDs that followed him home one night. From the April 2000 issue of MSDN Magazine. |