VB 2006 And IQF
Paul Vick mentions a few new features in Visual Basic that enable query relational, object, and XML data in more natural ways than before:
- Query Comprehensions
- Object Initializers
- Anonymous Type
Paul also mentions that the CLR was introducing with the new Integrated Query Framework (IQF) a new or improved concept of “collections,” which, I take, to mean the concept of sequences that was lifted from the COmega project.
Another frequently mentioned point was that Visual Basic will become more of a dynamic typed language, placing the “script” back in Visual Basic Script and putting the squeeze on Perl, Python and Ruby as scripting languages, especially with the new and easier data querying capabilities.
Anonymous types appear to be a CLR feature in general as C# is also incorporating this concept. Object initializers has also been mentioned by Anders Hejlsberg as being considered for C# 3.0, a feature in which one could construct object trees in a similar, declarative way as with XML. This feature makes it trivially simple to include hierarchical data within code without the burden of manually creating hundreds of new variables. It makes sense as IQF likely allows querying recursively through objects just as well as with relational data or XML. (In my projects, I have code that automatically takes XML and generates both the types and the tree construction code for building data.)
The concept of query comprehensions is new in Visual Basic. The use of the term “comprehensions” immediately calls to mind a similar functional construct called list comprehensions in Haskell and Python.
In Python, one can write [3*x for x in vec if x < 2] for every element less than 2 in the collection, vec, return its value times 3.
In Haskell, one can write [x | x <- [1,5,12,3,23,11,7,2], x>10] to return every element in the list greater than 10.
Anyway, searching on Google for “Query Comprehensions” led me to this citeseer page with this paper “Comprehensions, a Query Notation for DBPLS” which discusses using list comprehensions for queries. List comprehensions produces lists from one or more selectors and filters. Although comprehensions appear to be concise syntactical sugar over procedural for loops, I see some subtle differences in that comprehensions are declarative expressions and include a looping construct. As such, they can (1) return lists, sets, bags, relations, or some other ringad types depending on the context, (2) be optimized in many ways such as through iterators instead of loops because order of evaluation is unimportant, and (3) be converted to query statements sent back to the database. The paper notes that comprehensions are more general than relational queries in that they can potentially support recursion.
It seems that the VB team are becoming envious of the outside world and opting for expressiveness and orthogonality now instead of syntactic sugar. A previous PDC session abstract referred to new extensions to the My namespace, leading me to think “They can’t be serious?” But I shouldn’t be surprised given VB’s historic lack of regard for inheritance, obliviousness to functional programming, and Paul’s admittance that generics was only a priority because it came for free in the framework. VB’s verbose syntax for function identifiers (with AddressOf) and for generic types with multiple (>= 2) types parameters imply a belief that these features are rarely used; VB’s designers don’t realize that, for some developers, it’s an entire style of programming.
I still remain suspicious of VB’s plans, though. The use of the term “query” in “Query Comprehensions” suggests that Visual Basic may diverge from C# and opt for domain-specific extensions to language. I could see VB follow Python’s syntax but substitute SQL keywords like SELECT and WHERE. It may be more appropriate for them, since the Mort persona tends to build custom business applications.
Regarding IQF, I suspect that WinFS and Microsoft Business Frameworks (MBF) were delayed a year, partly because of the unified data work going on in Orcas, which will ship after Longhorn? Both involve some object-relational mapping, and it would be better to ship those technologies when Microsoft figured out its data story with IQF. I have some questions I have about this new framework:
- Will queries on object be fast? Will the IQF rely on reflection, or will there be JIT optimizations and lightweight code generation involved?
- Will the Orcas framework have both an XPath/XQuery and SQL mechanism to search all three types of data? Or have they figured out a single unified method that does both, efficiently and concisely?