BT

Facilitating the Spread of Knowledge and Innovation in Professional Software Development

Write for InfoQ

Topics

Choose your language

InfoQ Homepage News Visual Basic 16.9 in .NET 5

Visual Basic 16.9 in .NET 5

This item in japanese

Bookmarks

Since the The .NET Language Strategy was published in 2017, the general belief in the .NET community was that Visual Basic was effectively a dead language. There are numerous reasons for this, but that deserves its own article. For now we’re going to focus on where VB continues to supported by Microsoft.

Visual Basic 16.9 Language Features

The first VB 16.9 feature is support for Default Interface Methods. This highly controversial C# 8 feature allows new methods to be added to interfaces with an implementation. Effectively this makes the interface keyword act more like an abstract class than an abstract interface.

Visual Basic will not be able to create new Default Interface Methods at this time, but it can consume them. This change was seen as necessary in order to support interoperability scenarios with .NET Core/.NET 5+ libraries.

The next feature is support for Source Generators. This feature is described as a “compiler feature that lets C# developers inspect user code and generate new C# source files that can be added to a compilation.” The goal of being able to inject code into the C# and VB compilation process dates back to the early days of Roslyn.

Another feature of VB 16.9 is documented simply as “enables consumption of init-only properties”. Again, we see the focus on interoperability, rather than expanding the surface area of the language.

Windows Forms Support

A common complaint about Visual Basic in .NET Core was that the Windows Forms designer wasn’t very good. Klaus from Microsoft explained that a major part of the reason for this was that the VB event syntax is very different than C#.

In Visual Basic it is customary to use the declarative event handling syntax. The WithEvents keyword is used on a field to indicate that event handlers should be automatically attached and detached on assignment. The Handles keyword is then used to indicate which methods will be receiving the events. This style results in very different code patterns than the imperative style used by C#, necessitating additional work on the designer.

According to Klaus and Kathleen Dollard, the designer is now working correctly using VB’s declarative style.

Application Framework

A feature unique to VB is the Application Framework, part of the “My namespace” set of features. The Application Framework provides features for graphical applications such as managing user settings, preventing multiple instances of the application from running at the same time, and configuring the authentication mode.

For many developers, the Application Framework is the main reason they originally chose VB over C# for their Windows Forms project over a decade ago. So not having it available in .NET Core was seen as a major stumbling block in the migration path.

With VB 16.9, the Application Framework has been extended with an event to manage high DPI scenarios.

Rate this Article

Adoption
Style

BT