Thursday, April 26, 2007

More Issues with VB 9.0 Samples in the Updated LINQ to SQL Documentation

It's evident that no one tech-edited or double-checked the VB 9.0 code examples in the "LINQ to SQL: .NET Language-Integrated Query for Relational Data" whitepaper Dinesh Kulkarni, Luca Bolognese, Matt Warren, Anders Hejlsberg, Kit George that was updated in March 2007.

I encountered the most egregious example of the authors' disdain for VB in the following code snippet from the "Stored Procedures Invocation" topic:

<StoredProcedure(Name:= "VariableResultShapes")> _
  <ResultType(typeof(Customer))> _
  <ResultType(typeof(Order))> _
public VariableResultShapes(shape As Integer?) As IMultipleResults
  Dim result As IExecuteResult = ExecuteMethodCallWithMultipleResults(Me, _
    CType(MethodInfo.GetCurrentMethod(), MethodInfo), shape)
    return CType(result.ReturnValue, IMultipleResults)
End Function
The example uses C#'s typeof() instead of VB's GetType() function in lines 2 and 3, is missing the Function keyword on line 4, and uses the unsupported ? symbol for Nullable(Of T) on line 4. There are obvious errors on 50% of the lines of the example. Further, the following required Imports statements are not to found anywhere in the document:
Imports System.Data.Linq
Imports System.Data.Linq.Provider
Imports System.Reflection
It would behoove authors of whitepapers with a penchant for C# to at least check to see if their VB sample code compiles.

By the way, Kit George is a program manager on the VB team and presented the LINQ Overview Webcast on April 25, 2007.

Updated 4/27/2007: Dropped initial (off-topic) paragraphs.

2 comments:

Kit George said...

Roger, thanks for the note. We'll be double-checking that document to ensure it's a-ok. We did actually go over it fairly closely, ensuring that items ran, but we might have missed the odd element piece of code in translation. Certainly, what we put in the document at time of publication was what was capable at the time (with a few errors it seems), not necessarilly what we would do now. We'll have to revisit that document and ensure it's got the best syntax, thanks for the note

--rj said...

Kit,

Thanks for the comment.

The issue I'm raising in my posts on LINQ is that Visual Basic has become a second-class citizen in .NET programming languages. The problem is most evident with LINQ, where VB in Orcas Beta 1 is missing many C# extensions.

This VB snippet is compelling evidence in support of my contention.

--rj