Gimme Those VB9 XML Features

April 10, 2008

one comment

I’ve been to Tech-Ed Israel in Eilat this week and it was awesome. Tons of interesting lectures, food, parties and smart people to talk with.

The first lecture I attended was "A Lap Around Visual Studio 2008 IDE and VB 9.0" by Lisa Feigenbaum of Microsoft. Now, I’m not much of a Visual Basic user (in fact, I rather dislike the syntax) but I’ve heard of some new support of VB for XML and I wanted to hear what it was about.

Lisa started by showing some of the great Visual Studio support for Visual Basic 9.0, that includes intellisense features that seem trivial to anyone who’s using C#/ReSharper (‘filter as you type’ is really new in VB? weirdness), and also the Refactoring support for VB in Visual Studio 2008. It seems a lot better than the C# support, as the VB team seemed to have teamed up with DevExpress to incorporate their Refactor! tool into the IDE. The tool is not freely provided for C# users, but again, as I use ReSharper, I didn’t care that much.

But when Lisa got to the XML support for VB I was stunned. This is some really awesome stuff they have there. It allows you to write this:

  Public Sub CreateBookXml(ByVal books As IList(Of Book), ByVal file As String)

        Dim bookElements = From book In books _

                           Select <Book author=<%= book.Author %>> _

                                      <%= book.Title %> _

                                  </Book>

        Dim document = <?xml version="1.0" encoding="utf-8"?>

                       <Books>

                           <%= bookElements %>

                       </Books>

        document.Save(file)

 

    End Sub

I won’t go into all the details, but you can read more about these features right here. In short, this is an extremely neat (and useful!) native support for XML,  that makes me a bit jealous of VB programmers. The same code in C# would look a lot uglier as it will be littered with XDocument and XElement stuff. Now, I know the C# team had some vague reasons for not including this, but I really don’t get it.

They’re saying "What if XML won’t be that useful in the future? What then, ha?". My answer is that it is a big ‘what if’ right there. In Israel we say "What if my grandma had wheels?" to this kind of remarks. XML has been very prominent for the last decade or so, and it probably won’t be going away any time soon. And when it does, well, we’ll stop using these features and do something else. And if SQL becomes obsolete as well, we might stop using Linq, but that’s no reason to not let it into the language in the first place. XML is the de-facto standard to represent data in a textual manner nowadays, and if VB can admit to that, why can’t C# as well?

Add comment
facebook linkedin twitter email

Leave a Reply

Your email address will not be published.

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

*

one comment

  1. Miky SchreiberApril 18, 2008 ב 0:42

    There’s one thing I don’t understand:
    VB & C# are languages which came from the same company. Don’t they suppose to agree on such basic stuff such as the future of XML and the support of XML in these languages?

    Reply