VB.NET 10 Too
At Thycotic we typically work with C#. In fact, 90% of the code that we write is written in C#. However, it’s no secret that I am a VB.NET Fanatic. Generally, C# developers don’t look kindly on VB.NET developers because they consider VB.Net an inferior language. But I particularly like how it’s implemented in Visual Studio.
One of the criticisms of VB.NET is that is that some of its features are not up to par with C#. That’s an indisputable fact, I’ll admit. But a lot has been done to the upcoming VB.NET 10 for the .NET Framework 4.0, to bring VB.NET closer to C# for syntactic sugar.
.NET Framework 4.0 에 개선된 VB.NET 10 을 사용하게 되면 많은 기능을 아래와 같이 제공을 해준다고 합니다. 점점 C# 3.0 에서 지원되던 편리한 기능들이 VB.NET 에서도 반영이 되어 가는 모습을 보여주네요.
Auto Properties (자동화 속성 생성)
C# 3.0 introduced a really cool feature called automatic properties. Essentially, the C# compiler emits a backing field for you so you don’t have to do it yourself. This feature will be available in VB.NET 10. Its syntax looks like this:
Public Property MyAutoProperty As Object
That’s it! It’s just that one line; even simpler than C#. Of course you can decorate it with ReadOnly or WriteOnly so that it only has a getter or setter. The one thing it can do that C# 3.0 or 4.0 doesn’t let you do, however, is auto-initialize it.
Public Property MyAutoInteger As Integer = 10
MyAutoInteger will default to 10. The VB.NET compiler will secretly put this in the constructor or static constructor if the property is static, similar to the way fields can be auto-initialized.
Subs as Lambdas (람다식 표현 지원)
C# 3.0 introduced a rich syntax for Lambda expressions, and VB.NET followed suit to support LINQ. One limitation is that the passed in delegate must be a function that returns a value, and not a sub. Consider the following:
Sub Main()
DoWork(Sub(x) Console.WriteLine(x))
End Sub
Public Sub DoWork(ByVal work As Action(Of String))
work("Some String Maybe")
End Sub
This simply wouldn’t compile in VB.NET 9 with Visual Studio 2008 because DoWork expects an Action delegate, which does not return anything thus making it a Sub, not a Function. I’m happy to say this will compile in Visual Studio 2010.
Collection Initializers (배열 초기화)
If you’ve ever had a List or Dictionary you wanted to quickly initialize with data for something simple like a unit test, C# made this easy with collection initializers. VB.NET 10 introduces a similar syntax to allow initializing a collection.
Dim helloWorld As New List(Of String) From {"Hello", "World"}
This will create a list with “Hello” and “World” in the list. Likewise
for a dictionary:
Dim helloWorld As New Dictionary(Of Integer, String)
From {{1, "Hello"}, {2, "World"}}
Good stuff!
Line Continuations (지속적인 라인 유지)
VB.NET was criticized for its reliance on line feeds to decide where the next statement block would start. Previously, to continue the statement to the next line you had to use an underscore to indicate that the next line was part of the current one. In VB.NET 10, that remains true. But VB.NET 10 allows flexibility while implicitly
understanding where the underscore is. For Example:
다음 문장에 엔터를 치고 작성해도 이를 지속적인 코드로 인식해 준다는 의미입니다.
Dim someNumber As String = "Hello" &
"World"
or
Dim someNumber As Integer = 10 +
40
Better COM Support & Indexed Properties (나은 COM 지원 & 인덱스된 속성들)
C# 4.0 introduced better handling for “missing” arguments in COM. VB.NET has had that for a while.
C# 4.0 has partial support for indexed properties to complete their COM enhancements. Sadly, C# only lets you consume them from COM, not declare them, which VB.NET has been able to do since its inception.
And let’s not forget that VB.NET has plenty of other language tools that C# lacks such as the “With” construct:
Dim builder = New StringBuilder()
With builder
.Append("The ")
.Append("Quick ")
.Append("Brown ")
.Append("Fox ")
.Append("Jumped ")
.Append("Over ")
.Append("The ")
.Append("Lazy ")
.Append("Dog.")
End With
A contrived example, sure, but you get the idea of its usefulness. The “Handles” as a way of handling events is one of my favorite features. Of course C# developers will quickly to tell you that it’s a horrible syntax.
Conclusion
Both languages definitely have their advantages and disadvantages. Clearly though, VB.NET 10 has a lot of polish on it that cannot be ignored.