In Praise of VB
Written by Mike James   
Wednesday, 09 June 2010
Article Index
In Praise of VB
VB enhancements
Objects - the key to RAD

 

New VB

There have been a number of important additions to the language since it was first introduced - most are concerned with adding advanced features that bring VB level with C#.

These new features may not add much to the RAD aspects of VB but it would be a poorer language without them and omitting them would mean that VB couldn't make full use of the Framework classes. For example, take Generics. This allows you to write classes that work with any data type you care to specify. You can think of it as passing the class parameters that specify the types that the class will operate on. Generics allow other facilities to be made simpler within VB such as framework classes that manipulate almost any data type you care to think of and they certainly aren’t beginners or even advanced programmers are going to use directly in their everyday programming. Still their presence will be felt by all one way or another.

There are some technical features that have been added which do add to the RAD. 

For example, the Continue statement causes any loop to skip to the start of the next iteration. You can create customised events and specify exactly how event handlers are processed. There are some new data types – nullable types are really structures that have fields to accommodate out of range values i.e. nulls. There are also some additional simple types in the form of unsigned integers of various lengths. . 

More recent additions, VB 2010, have also added to the RAD nature of VB. For example, auto-implemented properties make object oriented programming faster. Collection initalizers allow you to set up collections in the style of an old fashioned Basic Data statement - perhaps this is stretching the analogy too far. Even the esoteric sounding multi-line lambda expressions and subroutines can be seen as a way of providing the ease of ad-hoc method and subroutine creation that was once the norm in non-object oriented basic. You can think of a lambda as a disembodied method not really belonging to any object if you want to.

It's either an error or a new line

However it has to be admitted that all of these features are also "new" in C# as well. One improvement unique to VB 2010 is the introduction of  implicit line continuations. Arguably one of the most irriating features of the "old" VB syntax is the need to end lines that continue on the next line with an underscore. Now you can forget the underscore as long as the puntuation makes it obvious that you haven't finished the statement.

For example if you start a new line after a comma clearly more is to follow. Start a new line without closing an opening bracket and you care clearly going to carry on writing - or you have just forgotten to close the bracket. Similarly if you start a new line after any binary operator you either are about to continue the expression or you have made a mistake.

You should be getting the idea by now. This approach to line continuation is in the real spirt of VB. It's a great help to RAD if the compiler tries to understand what the programmer is typing rather than the oh so typical -

"missing semicolon at line 14" 

error message which always makes me think -

"well if you have noticed that -
           add the semicolon for me".

All of these, and many other changes are handy extras but there are one or two changes that seem to be in the same category but really they effect the usability of the language far more than you might expect.

They are also special to the VB language whereas some of the “big” changes, such as generics, are shared with C#.

VB's instant objects

Beginners often find it confusing that they have to create  say a Form class and then an instance of the class. It's perfectly logical but it can be messy with lots of extra confusing names and it's certainly not the way VB 6 did it!

Now you can create and work with a form without the need for the me keyword or instantiation.

For example, if you have created a new class called Form1 you can refer to it using statements like

Form1.Show

Similarly you can refer to any of the methods or properties defined in the Form1 class as if the class was an object. Of course if you want a second instance of the form you have to create an instance and an instance variable for it using the new keyword e.g.

Dim MyForm As new Form1

Notice that begin able to use a class as if it was an object isn't the same thing as a static class - this is auto instantiation. What happens of course is that the compiler automatically generates the instance and substitutes a reference to the instance everywhere the class name occurs. This approach is also very similar to the idea of prototype inheritance where the first object of a type you create acts as a template or prototype for any subsequent objects you need. If you think about it for a while you start to wonder why we ever invented the class at all - when all we need are objects.

To a C# programmer this sounds messy but to a RAD programmer it's perfectly logical in its own way – why proliferate names when you only want a single instance of the class.

It's to the point and concise.

<ASIN:0470532874>

<ASIN:0521721113>

<ASIN:0073517259>

<ASIN:0132152134>

<ASIN:0672331136>

<ASIN:0470502223>

 



Last Updated ( Wednesday, 09 June 2010 )
 
 

   
RSS feed of all content
I Programmer - full contents
Copyright © 2014 i-programmer.info. All Rights Reserved.
Joomla! is Free Software released under the GNU/GPL License.