XLinq has me wanting to code in VB.NET?!?!

Ever since I started programming in .NET land I’ve been a C# bigot.  The syntax jives with my brain.  When I come across code samples presented in both VB.NET and C# I gloss over the VB.NET code in all it’s verbosity and jump directly to the real code (C#) .

Since the May CTP drop of Linq I’ve been working my way through the various technologies (Standard Query Operators, Lambda Expressions, Expression Trees, Linq to Sql, Linq to Xml, etc) in an attempt to get a feel for what’s available in Linq and what changes it might bring to my daily programming life when I’m able to use it in production applications.

I’ve semi-recently gotten to XLinq and it has me envying VB.NET programmers!  The Xml literal support within VB.NET is pretty sweet.  For those of you who don’t know what I’m talking about the next version of VB.NET has built in support for constructing Xml using literals.  As a quick (also known as “lame”) example imagine that you have a PurchaseOrder class that you need to represent as Xml.  Wtihin VB.NET you can build the Xml representation of the PO using a combination of Xml literals and embedded expressions. The result looks amazingly similar to ASP.NET due to the shared <%=expression%> syntax.

 Public Class PurchaseOrder
   Public PODate As
Date
  
Public Number As
String

  
Public Function AsXml() As XElement
      Return <purchaseOrder><poNumber date=<%= Me.PODate.ToString() %>><%= Me.Number
%></poNumber></purchaseOrder>
  
End
Function
End
Class

* Note: This is the first VB.NET code I’ve written since Beta 1 of .NET

To be fair it should be mentioned that the functional construction of Xml that is provided by XLinq makes creating Xml without xml literals pretty darn nice as well…especially when compared against what we’re used to with existing Xml API’s.

 

# re: XLinq has me wanting to code in VB.NET?!?!

Sunday, July 23, 2006 1:08 AM by Sam Gentile    
Take a shower. It will pass.

# re: XLinq has me wanting to code in VB.NET?!?!

Saturday, February 17, 2007 11:12 AM by Mike Champion    
Think of it this way: C# has had a kind of JSON literal support from the very beginning :-)

But seriously, what's wrong with using VB9 in parts of a project where literal XML would be useful, and C# in the parts where its many desirable features shine?

# re: XLinq has me wanting to code in VB.NET?!?!

Saturday, February 17, 2007 12:03 PM by Steve    
Nothing is wrong with that per se, however, the majority of projects I work on these days have a standard language that is used throughout. Perhaps if VB9's XML Literals and other features are compelling enough I'll start to use multiple language in my projects, with each silo using the language that is most appropriate. Honestly, I don't see that actually happening though. I'll use our standard language, C#, and make do with the features they have available and complain about how that stinkin' XML team at Microsoft wouldn't give me what I wanted! :)

# re: XLinq has me wanting to code in VB.NET?!?!

Thursday, March 01, 2007 6:05 PM by Stefan Wenig    
Why not use VB9 as a DSL for XML? We all knew VB would be good for something one day, didn't we? ;-)

(although i have to say that your sample looks a lot like inline ASP 3.0 code, so i'm not quite sure yet...)

# re: XLinq has me wanting to code in VB.NET?!?!

Saturday, March 03, 2007 6:34 PM by Srgjan Srepfler    
Darn, that's nice.
Well perhaps you could write the bulk of the class in C#, mark it partial and implement the AsXml method in VB9 :)

# re: XLinq has me wanting to code in VB.NET?!?!

Thursday, May 29, 2008 4:43 AM by am    
I AM A SPAMMER!! :D:D

Post a Comment

 
 
Prove you're not a spammer: 
5 + 5 =