BT

A Short History of Dynamic Typing in Visual Basic

by Jonathan Allen on Jan 15, 2010 |

Visual Basic has always been on the fence between static and dynamic typing. In the beginning VB supported late binding, which is known today as “duck typing”. Explicitly declaring variable types, or even local variables at all, was considered optional. But if you did declare the variable types, it would operate in early binding mode with runtime type checking and better performance.

With the introduction of COM in Visual Basic 4, VB got some interesting features not seen in most languages. When declaring variable types, the compiler would implicitly refer to interfaces rather than concrete classes. This wasn’t always obvious, as every class implicitly defined an interface with the same name. The net effect was that under this scheme any class could explicitly implement any other class’s interface, though no class could directly inherit from another. While VB developers generally hated the lack of inheritance, Google’s recently announced Go programming language has a similar design.

With Visual Basic 7, also known as VB.NET, the language dropped its unlimited interface style polymorphism. In its place we find the combination of implementation inheritance and explicitly defined interfaces that Java made popular. VB also gained the Option Strict directive which causes the compiler to require explicit type declarations and casts.

While VB was marching towards a more statically typed paradigm, the rest of the world was increasing turning to dynamically typed languages such as Python and Ruby. It would take two more versions for Visual Basic to take notice and start swinging back the other way.

VB 9 proposed several interesting features in the realm of dynamic typing. The first is the incredibly successful XML Literals and XML Comprehension. This syntax was proposed for the Haskell programming language and prototyped in a variant of C#, Visual Basic is the second language to see this syntax make it to production use. The first appears to be ECMAScript for XML, first standardized in 2004.

On a side note, XML Comprehension isn’t the first time VB added special syntax for a narrow set of types. VB also has the bang operator (!) which was used in versions 3 thru 6 for database access. Though still supported for any dictionary style lookup, it has fallen out of favor. An example follows.

firstName = recordset!FirstName
lastName = recordset!LastName

Some Visual Basic 9 features didn’t make the final cut. These features would have allowed developers to create objects and access properties by name at runtime without explicitly using the reflection API. For example:

className = “Customer”
memberName = “FirstName”
x = New (className)
x.(memberName) = “Fred”

VB 10 marks the first time the language can be truly be said to be dynamically typed. Up until now the features have been limited to consuming types. Actually creating new types, or altering existing ones, was not available until VB integrated support for the Dynamic Language Runtime. Currently in beta, Visual Basic 10 allows developers create their own object models including the prototype style found in languages like JavaScript.

Looking to the future, Lucian Wischik of Microsoft, has mentioned that they are looking into making the XML Comprehension syntax extensible. Currently they are considering support for XAML and, when inside Silverlight, the HTML DOM. However, it can also be applicable to any other tree-style data structure.

It should be noted that Visual Basic’s younger sibling VBScript has its own features. Like most interpreted languages VBScript has functions for executing arbitrary code stored in strings. These functions, Eval and Execute, were often leveraged by VB 6 applications when additional dynamic capabilities such as end-user scripting is needed. In the future we expect IronPython or IronRuby to serve that role.

Hello stranger!

You need to Register an InfoQ account or to post comments. But there's so much more behind being registered.

Get the most out of the InfoQ experience.

Tell us what you think

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread

static/dynamic reality by Dan Tines

...the rest of the world was increasing turning to dynamically typed languages such as Python and Ruby.


Just in the blogosphere, not in reality.

Late Binding is not Duck Typing by Shi Kafune


VB supported late binding, which is known today as “duck typing”.


Late Binding is for static and dynamic languages, duck typing is for dymanic languages.

For example:
Java has late binding but it is not dynamic.
Ruby has late binding and duck typing.

Re: Late Binding is not Duck Typing by Andrea Del Bene

I agree, late binding and duck typing are two different concepts...

Re: static/dynamic reality by Sake .

Just in the blogosphere, not in reality.


Whose reality ?

Re: static/dynamic reality by Dan Tines

The reality of hard, real numbers of developers. The "rest of the world" was not turning to dynamic languages like Python and Ruby.

Re: Late Binding is not Duck Typing by Jonathan Allen

Java doesn't support late binding, except indirectly via the reflection API. Unforuntately many Java bloggers confuse late binding with dispatching on virtual methods. In COM and .NET, this is still considered to be early binding. They make a similar mistake when they say Java is pass-by-reference when in fact it is pass-by-value, or more specifically "pass a reference by value".

Visual Basic, and C# 4+, supports true late binding where in only the method's name is known as compile time and the variable is untyped. I think you will agree that this matches your definition of duck typing.

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread

6 Discuss

Educational Content

General Feedback
Bugs
Advertising
Editorial
InfoQ.com and all content copyright © 2006-2013 C4Media Inc. InfoQ.com hosted at Contegix, the best ISP we've ever worked with.
Privacy policy
BT