Saturday, 18 May 2013

Anonymous types and functions in Visual Basic.Net

A lot of people poo poo VB.NET and yet I think almost none of them know anything about it. It has essentially all the same functionality as C#. With the latest versions of VB.NET you can use anonymous functions really nicely. I think the syntax is very clear and it makes it more obvious to a beginner programmer what is happening ie, the lambda you are passing into the where is a function. I think that's a real commendable thing to do and the syntax is very true to the language.

I think you would find an awful lot of C# developers using expressions such as

results.Where(x => x.Success);

but many of them (certainly a lot of the devs I have met in the past) would not really understand what is happening here. It's arguably not important but that's not fair. Using lambdas just in Linq wastes so much potential of the language.

Anyway, there's an example below in VB.NET. This syntax is in some ways more similar to the way F# does lambdas! ie

let test = fun x x < 2

Now if we can only convince them to make a binding like "let" that's immutable, we would really be cooking on gas!

No comments:

Comments System

Disqus Shortname