Login | Register   
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


advertisement
 

The Living Language—Visual Basic 2005

Improved syntax, new keywords, and a host of new features keep Visual Basic changing and growing. But just because languages can withstand change doesn't mean you can misuse words.


advertisement
ea, I know. English is a living language, but there have to be some rules. You can't just make up words. You can't make up ways to use those words. (Yes, the folks at Microsoft do this regularly. Is "disambiguate" really a word? Does "deprecate" really mean "to take a feature out of current use?" Yes, Microsoft can make up words.) But recently, I've heard a spate of people using the same expression incorrectly, and it's driving me nuts. Like many other things in life, once you run across the abomination, it jumps out at you every time you hear or see it. Here's my latest pet peeve: I have heard, over the past few weeks, no less then four different people use the adverb, "anymore", as if it meant "these days." Let's be clear: "anymore" has only one meaning: it implies something that occurred in the past that no longer occurs. It must have a negative connotation (as in, "x used to happen, but no longer"). My favorite was on a radio talk show recently—and I know, my blood pressure was already high from listening to Bill O'Reilly; I should never do that to myself—in which the caller said, referring to a public political figure: "These political people are like cartoon characters anymore." Of course, being that "anymore" implies a change from a positive to a negative state, it's hard to figure out how things have changed in this regard, but in any case, the caller definitely meant "these days" in the sentence. I screamed at the caller louder than I screamed at Bill, that day.

Look at it this way: Imagine that you notice that you've been eating a lot of chicken lately. For you to say "I'm eating a lot of chicken anymore" (another phrase I overheard recently) is wrong. Really wrong. If you had gone vegetarian, you could, however, say: "I'm not eating chicken anymore"—the "anymore" implies that at one time, you did eat chicken, but now you're not. I know what you're thinking: "That Ken, he's a real pain in the a** anymore." But then you'd just be part of the problem, not part of the solution. It's a living language, but you've got to follow the rules. Think about it. If you find yourself doing this, stop. Don't take it upon yourself to make up new phrases, or to use old ones any old way you like. On the other hand, programming languages do need to grow, to add new functionality, in order to survive. (Of course, they've got compilers that verify the syntax of the language—with English, we're on our own.) Which brings us to Visual Basic 2005, of course.

Not just to keep up with other languages, Visual Basic 2005 adds a bunch of new features aimed at both making VB developers more productive, and making some things possible that were a pain in previous versions. I can't list them all here, but will point out some of my favorite new little features. (You'll find much written about the new features in Visual Studio 2005 and in the .NET Framework—start here for more info.) That's not my point here. My intent is to point out the little things that may seem inconsequential on their own, but that make the whole experience better. The new Continue statement makes it easy to break out of a loop, and start back at the top of the loop on the next iteration. (The Exit statement does the same thing, but takes you out of the loop totally.) You can use Continue Do, Continue For, and Continue While within each type of loop.



You can finally retire the If Not x Is Nothing Then syntax—they finally added an IsNot operator. Although it may not seem like much, the ability to type If x IsNot Nothing will save a lot of developers a lot of thinking. I always have to stop and convert my thoughts into the double negative when I use the old syntax. Disposing of instances of objects has been tricky in Visual Basic—generally, you put the call to the Dispose method in a Finally block, and you must check to ensure that the object isn't Nothing before performing the method call. C# developers have always had a simple solution—the using statement allows you to use an instance, and when the block completes, the runtime calls the Dispose method for you. Finally, Visual Basic developers get the same convenience with the addition of the Using statement.

Although you still can't specify a non-zero lower bound on an array, at least you can now explicitly indicate the lower bound of any array (as long as it's zero). This change makes the array declaration more explicit, and also makes it easier to move existing VB6 code into VB 2005. Think about it—isn't declaring x(0 To 15) clearer than declaring x(15). At least the new syntax makes it clear that the array contains 16 elements. In previous versions of Visual Basic, a property's Get and Set procedures had to have the same access level—either they were both Private or Public—in any case, they had to match. In Visual Basic 2005, you can create getters and setters with different access levels. You might make the Property Get procedure public so anyone can retrieve the property value, but make the Property Set procedure private, so only code within the class can set the value.

Visual Basic 2005 finally adds unsigned integer types. It's hard to get terribly excited about this one, but it does bring Visual Basic more in line with other languages. In previous versions of Visual Basic .NET, you could neither consume nor create overloaded operators. In some situations, that meant that you either couldn't perform some operations, or you had to peruse the documentation to find the methods the overloaded operators call, and call those directly from Visual Basic. Visual Basic 2005 adds the capability of consuming overloaded operators, so you can use existing overloaded functionality (adding together a Point and a Size, for example, which you couldn't do previously). You can also create your own operator overloads, giving your own classes the ability to be operated on using standard mathematical and logical operators.

There's lots more, as well—bigger features, that can't be summarized in a single paragraph. You'll find generics, partial classes, custom events, and more. For detailed information, visit Microsoft's site devoted to Visual Basic. You'll find that Visual Basic 2005 is a cool language anymore. (I couldn't resist.)



   
Ken Getz is a senior consultant with MCW Technologies and splits his time between programming, writing, and training. He specializes in tools and applications written in Visual Studio .NET and Visual Basic. Ken is the author of the highly rated .Finalize() column in CoDe Magazine. He is also the co-author of several best-selling books, including Access 2002 Developer's Handbooks with Paul Litwin and Mike Gunderloy, Visual Basic Language Developer's Handbook with Mike Gilbert, and VBA Developer's Handbook with Mike Gilbert (Sybex). He co-wrote several training courses for Application Developer's Training Company, including VB.NET, ASP.NET, Access 2000 and 97, Visual Basic 6, and Visual Basic 5 seminars. He has also recorded video training for AppDev covering VB.NET, ASP.NET, VB6, Access 2000, and Access 97. Ken is a frequent speaker at technical conferences and has spoken often at Microsoft's Tech-Ed conference. Ken's also a technical editor for Access-VB-SQL Advisor magazine and a columnist for Informant Publications' asp.netPRO magazine..
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap