Visual Studio 2017 has finally been released and, oh, what a joy! With each release of Visual Studio, Microsoft raises the bar and technology that exists at the time gets a boost. I remember a time when Web Applications were the next ‘big thing’! Now, with Visual Studio 2017, it is AI and Bots that are the new ‘next big things’. It makes you wonder how the technology landscape will change in the next few years. With the new release of Visual Studio 2017, let’s look at what’s here today!
Visual Basic’s Future: The Elephant in the Room
It seems as if Microsoft has no plans of forgetting about Visual Basic completely. On the contrary, Microsoft plans for Visual Basic to become a more distinguished language. In the past, Microsoft has spent a lot of time giving Visual Basic the same features as C#, and vice versa. Now, C# and Visual Basic are set to diverge. Going forward, Microsoft wants to quicken the pace of C# feature releases instead of holding off until a complete feature set in Visual Basic is also ready.
New in Visual Studio 2017
The focus of this article is Visual Basic 15, so I will mention just a few of the important improvements to Visual Studio 2017.
Visual Studio 2017 Installer
The big improvement in Visual Studio 2017 is the improved installer. The Visual Studio 2017 Installer is now a stand-alone app that you can always run again if you want to remove or add features. In the past, Visual Studio was mainly used to develop apps for a Windows platform. Times have changed and technology has changed. As you may be aware, with Visual Studio you can develop apps not only for Windows, but also for Android, iOS, the Web, and even Mac. The reason Visual Studio’s installer has finally changed is because the install got too big, and, if you wanted to develop for other platforms, you would have had to install much more and the install process would have taken much longer.
The other problem was that people ended up installing a lot of unnecessary stuff that they didn’t need and had no initial option of choosing their desired options properly.
Project Load time in Visual Studio 2017
Project and Solution load time has improved significantly in Visual Studio 2017, as well. Projects can be loaded in the background asynchronously, thus improving productivity time.
New Language Features in Visual Basic 15
Sadly, there aren’t many new features in Visual Basic 15. This is likely due to the fact that C# 7 and Visual Basic 15 are going on separate paths. Here is a quick breakdown of the very few new language features in Visual Basic 15:
Visual Basic Value Tuples
A tuple is a data structure that has a specific number and sequence of values. In other words, tuples are a temporary grouping of values. Tuples are commonly used in different ways:
- To represent a single set of data. For example, a tuple can represent a record in a database, and its inner components can represent that record’s fields.
- To provide easy access to, and manipulation of, a data set.
- To return multiple values from a method without the use of parameters.
- To pass multiple values to a method through a single parameter.
Here is a small example:
Public Sub Main() Dim Ages() As Tuple(Of String, Nullable(Of Integer)) = { New Tuple(Of String, Nullable(Of Integer))("Hannes", 38), New Tuple(Of String, Nullable(Of Integer))("Ellie", 38), New Tuple(Of String, Nullable(Of Integer))("Kayla", 17)} Dim Age As Integer Dim AvgAge As Integer = ComputeAge(Ages, Age) Console.WriteLine("Average Age: {0:N2} (n={1})", AvgAge, Age) End Sub Private Function ComputeAge(Ages() As Tuple(Of String, _ Nullable(Of Integer)), ByRef n As Integer) As Integer n = 0 Dim sum As Integer For Each Age In Ages If Age.Item2.HasValue Then n += 1 sum += Age.Item2.Value End If Next If n > 0 Then Return sum / n Else Return 0 End If End Function ' The example displays Average Age: 31'
Visual Basic ByRef Return Consumption
ByRef return consumption supports consumption of functions and properties from libraries that have ByRef returns.
Visual Basic Binary Literals and Group Separators
Binary literals and digit group separators allow native representation of binary numbers.
Language Features that Were Left Out of Visual Basic 15
There are a couple of language features that were given to C# 7 that Visual Basic 15 did not get. These are worth mentioning here.
is-expressions
An is-expression checks whether an object is compatible with a given type in C#. For example, the following code can determine if an object is an instance of the TestObject type, or a type that derives from TestObject:
if (obj is TestObject) { }
out-variables
In previous versions of C#, before you can call a method with “out” parameters you first have to declare variables to pass to it. Because you weren’t initializing the out variables, you also couldn’t use var to declare them, but needed to specify the full type, as shown in the following example:
public void CheckSomething() { int x; p.GetHorizontalLocation(out x); WriteLine($"({x})"); }
In C# 7.0, out variables are added with the ability to declare a variable right at the point where it is passed as an out argument, as in the following:
public void CheckSomething() { p.GetHorizontalLocation(out int x); WriteLine($"({x})"); }
Local Functions
Local functions enable you to define a function inside the scope of another function. Local functions can be created in the body of any method, or any constructor or property’s getter, and setter. This function then gets transformed to a regular private static method.
Conclusion
With each new release of Visual Studio, more and features get added to the languages we love. Although Visual Basic 15 didn’t get as many new features as C# 7 this time around, next time might be different. With C# and Visual Basic going in different directions, who knows what Visual Basic is going to get and eventually evolve into?