Implicit Evaluation with PHP

9 December 2005

C# 3.0 with LINQ

I was reading about new features due in C# 3.0 in the next few years. LINQ seems to be the biggest new feature, so I started looking at it. It is by no means simple, but it is similar to a slightly rearranged SQL query. Microsoft has made a number of examples available at http://msdn.microsoft.com/vcsharp/future/linqsamples/default.aspx. The learning curve for someone with SQL expierence seems fairly low. In short, LINQ allows you to filter an array of objects or scalars with control similar to what SQL extends.

While, as a developer, I absolutely love getting this functionality for free, it surprises me that it is part of the core language. Most application are designed around an algorithm to generate a specific answer to a question. Many Scheme programs, however, are designed around the idea of generating an enormous dataset and then filtering it to just the answer(s) applicable to a question. Functionally, LINQ seems quite similar to the Scheme model. Scheme, of course, is not derived from SQL, though Scheme is a functional language and SQL isn’t so far removed from one.

I have began wondering about the feasibility of a LINQ-type feature in PHP. The LINQ operators (select, from, in, etc.) are keywords in C#, and incorporating them into PHP would therefore require adding them to some layer below PHP (the language). I suspect, however, it would be entirely possible to build a simple LINQ-parser function and have similar functionality close-by. At minimum, select should only require implementing a few operators. Update and insert would be more useful still, but I imagine would require another magnitude of work.

However, my style of development uses many DataAdapters (I’ve also heard the term service object in Java circles, but they might not be identical concepts), which are essentially custom built LINQ statements that occupy entire classes, and Model objects, which are simply typed PHP representations of records or forms (both submited and HTML). A well implemented LINQ function would likely void the need for the explicit model, and cut a good deal of fat from a DataAdapter.

This is a concept I intend to investigate further over the next few weeks. Besides being useful in the real world, it would illustrate the implicit evaluation I treasure so in PHP, and the late binding that would make this many orders of magnitude harder is a more strongly-typed language.

One Comment currently posted.

Horace Finkle says:

Sweet. Good blog page. I’m bookmarking it.

If you want to have a really good laugh read www.horacefinkle.blogspot.com

Post a comment on this entry: