InfoQ

InfoQ

News

My Bookmarks

Login or Register to enable bookmarks for unlimited time.

The content has been bookmarked!

There was an error bookmarking this content! Please retry.

Visual Basic 10: Rounding the Edges

Posted by Jonathan Allen on Nov 04, 2008

Sections
Development,
Architecture & Design
Topics
Language Design ,
.NET
Tags
Visual Basic.NET

Like C# 4, VB 10 isn't going to see a lot of ground breaking features. Everything so far was already available, just not in a convenient form.

The most anticipated feature is probably the near elimination of line continuation characters. While there are a few ambiguous cases, the vast majority of the time an underscore will not be necessary.

Next up is implicit array initialization. VB 9 added array initialization; unfortunately the syntax is rather verbose. Even with type inference, redundant type information is needed.

Dim vectorA As Integer() = New Integer() {1, 2, 3, 4, 5}
Dim vectorB = New Integer() {1, 2, 3, 4, 5}

Visual Basic 10 adds type inference for initialization arrays.

Dim vectorC = {1, 2, 3, 4, 5} 

This syntax works by determining the most specific type common to each argument. If that is System.Object, then a compiler warning is issued. In addition to vectors, matrix and jagged arrays are supported.

Dim matrix = {{1, 2, 3}, {4, 5, 6}}
Dim jagged = { ({1,2,3}), ({4,5}), ({6})}

Matched with this feature is collection initialization. Using the From keyword, each item in the initialization list is added to newly created object.

Dim list As New List(Of Integer) From {1,2,3,4}
Dim dictionary As New Dictionary(Of String, Integer) From {{ "Tom",80},{ "Frank",85}}

Initialization can be done with any number of arguments so long as the collection has a method called Add with the right parameters. If such a method doesn't exist, it can be added as an extension method.

Dim customers As New List(Of Customer) From {
    {"Tom", "T", "Jones"},
    {"Frank", "M", "Burns"}}

<Extension()> Sub Add( ByVal list As List(Of Customer),
                       ByVal firstName As String,
                       ByVal middleInitial As String,
                       ByVal lastName As String)
    list.Add(New Customer(firstName, middleInitial, lastName))
End Sub

Both single line and multi-line lambdas will be supported in VB 10 for functions and subroutines. The syntax for multiline delegates is show below.

listA.ForEach(Sub(id)
                  Dim c = GetCustomer(id)
                  If c.UnpaidBill > 0 Then c.Send(Invoice)
              End Sub)

Automatic properties were added using the existing syntax. As it also looks a lot like the syntax for public member variables, it should discourage use of the latter. An optional initializer is shown below.

Public Property Score As Integer = 5

C# is not the only language adding support for optional parameters. While VB had it all along, there was an supported use case. Specifically, any type defined as Nullable(Of T) wasn't allowed to be optional. This will be fixed with VB 10, finally allowing stored procedure calls to be mapped one to one with VB wrapper functions.

Up last is support for Co- and Contra-Variance. We covered this in the article C# Feature Focus: Co- and Contra-variance.

No comments

Watch Thread Reply

Educational Content

Jesper Boeg on Priming Kanban

In this interview, Jesper Boeg, author of the new InfoQ book – Priming Kanban, discusses the keys to using Kanban effectively, and how to get started if you are currently using other approaches.

New-age Transactional Systems - Not Your Grandpa's OLTP

John Hugg discusses high volume transaction processing applications with high and low frequency profiles, and how VoltDB can be used for that purpose.

Cool Code

Kevlin Henney examines code samples to see what can be learned from them starting from the premise that one won’t write great code unless he knows how to read it.

Collaboration: At the Extremities of Extreme

Jason Ayers share the observations he made watching a team of developers collaborating in real time on the same code base, pushing XP, pair programming and continuous integration to their extremes.

Yesod Web Framework

Michael Snoyman presents Yesod, a web framework written in Haskell and containing a web server, templating, ORM, libraries (templating, gravatar, etc.).

Transactions without Transactions

Richard Kreuter and Kyle Banker on how to avoid classical RDBMS transactional systems by using compensation mechanisms, transactional messaging or transactional procedures.

Attila Szegedi on JVM and GC Performance Tuning at Twitter

Attila Szegedi talks about performance tuning Java and Scala programs at Twitter: how to approach GC problems, the importance of asynchronous I/O, when to use MySQL/Cassandra/Redis, and much more.

10 tips on how to prevent business value risk

One category of risk that project teams need to ensure they address is business value failure – delivering a product that fails to provide value for the business investor.