BT

Facilitating the Spread of Knowledge and Innovation in Professional Software Development

Write for InfoQ

Topics

Choose your language

InfoQ Homepage News Future Plans for VB

Future Plans for VB

Lire ce contenu en français

Bookmarks

Lucian Wischik responded to Mads Torgersen’s talk with possible language changes for Visual Basic. These are just proposals, nothing is being promised yet. And they are mostly about reducing boilerplate code and don’t offer the kind of fundamental changes we saw in VB 10 or 11.

Read-Only Properties

Read-only auto properties are a natural fit for VB’s syntax. Simply prepend the ReadOnly keyword and it will ensure that only a setter is emitted while still allowing you to set the value in the constructor.

ReadOnly Property Name As String

Comments

Comments in VB currently don’t play well with implicit line continuations. So Lucian’s first VB-specific is to allow comments after an implicit line continuation.

Strings

Strings in Visual Basic currently don’t support multi-line. So the first proposed change is to simply allow that. It would work like C#’s verbatim strings, but without the need for a prefix.

A more interesting feature is String Interpolation. By using the $" prefix you eliminate the need for explicitly calling String.Format. This in turn eliminates errors caused by miscounting the number or position of the substitution variables. Here is an example:

Dim query = $"http://{ url }?name={ Escape(name) }&id={ Escape(id) }&o=xml"

About four years ago Miguel de Icaza proposed the string interpolation for C# and actually built a working prototype.

Literals

Date literals in Visual Basic are currently based on US common standards, which can be quite frustrating for non-US developers. So the proposed change is to simply allow ISO-formatted date literals as well.

Binary literals, already available in many other languages, is also being proposed. This would use the &B prefix and would be especially beneficial for bit-flag style enumerations.

Partial Interfaces and Modules

Not much to say here, the proposal is simple to allow for partial interfaces and modules. This would work the same way as for partial classes. As with partial classes this is mostly meant to be used with code generators.

Null Propagation

Like in C#, they are considering offering a null propagating operator. This would eliminate the need for a null check before invoking a method. Two options are currently on the table, the first being the same as we saw in C#. Note that in addition to ?. we also have ?().

Dim y As Integer = x?.y?(3)?.z

If there are any nulls to the left of a ?. or ?( operator, y gets the default value of z.

Function Parameters

As with C#, they would like to allow the params keyword to work with parameters of type IEnumerable instead of just arrays.

Also like C#, they would like to be able to declare local variables as part of out arguments.

If Integer.TryParse(s, Out x) Then

In this example the variable x would be created as if it were declared on the line above.

They are also thinking about declaring other variables inline,

If ( Dim x = GetValue()) > 15 Then Console .WriteLine(x)

Miscellaneous

Currently VB has a IsNot for reference comparisons, but not for type comparisons (i.e. TypeOf operator). This proposal would be simply closing that gap.

Rate this Article

Adoption
Style

BT