Fluent Interfaces Allow a Higher Level of Abstraction

Jeff Atwood takes a stand against using embedded languages to express intent.I concur with Ayende's response for most of his points, however I wanted to chime in on the discussion.

Later on, Jeff argues that a better way (or as he puts it, the "ultimate solution") is to include the underlying features of other languages to leverage them natively.He specifically mentions LINQ.Take a look at this sample LINQ syntax:

var priorityCustomers = from customer in Customers
where customer.Status = 'Gold'
select customer;

This syntax is great, and I welcome it for VS 2008.But this is almost the same thing as the Criteria API in NHibernate, or the Querying API in SubSonic.The only difference is that we're not using parentheses and dots all over the place, but the end result is the same.

Having this code directly in our language also makes it more difficult to construct dynamic queries.By dynamic I don't mean make the 'Gold' text a parameter, I'm talking about building the where clause dynamically based on run-time decisions.Using a query builder API such as SubSonic's allows you to do this.

Another point that Atwood makes is that creating fluent interfaces over things like regexes and SQL allows you to NOT learn the underlying concepts, which is unacceptable for professional developers.I agree with him, but LINQ is also one of those!The syntax we wrote above will get translated into a real T-SQL query for us.We should still be cognizant of the SQL that is generated and make adjustments where necessary, but does that mean we always have to program at the lowest common denominator?As professional developers we have to be aware of many technical concepts that are being abstracted from us.A lot of us program in .NET, and most of us probably have a background in C++.I'm glad I learned C++ so that I understand what's going on "behind the curtain," but I'm programming at a higher level of abstraction now.Remember having to always null-terminate your strings (I mean char arrays)?.I'm glad I don't have to do that anymore.Working at a higher level of abstraction allows me to be more productive.

The languages that we see in the coming years will almost certainly bost higher layers of abstraction and specialty, so that we can more easily build data-driven business applications, or 3D-modeled geology simulations, or whatever your domain is.AT&T has just created a programming language called Hancock, specifically geared for mass surveylance.ERLang is designed specifically for mission-critical, always-on systems.  There are many that exist today and even more that we haven't seen yet.  Don't fear the abstractions!

#1 Jason Meridth avatar
Jason Meridth
11.01.2007
8:54 AM

I noticed you filed this under DSL.DSLs are another form of abstraction that have become quite popular lately.Aren't "abstractions" just easier and faster ways to code?They provide a more soluble means for maintenance also (most of the time). I do agree that a professional developer should understand the inner-workings (especially when something goes wrong).I haven't looked, but NHibernate offers logging through multiple avenues; does LINQ allow for the same (using log4net, for example)?How's the NHibernate DSL coming? :)


#2 Ben avatar
Ben
11.01.2007
8:59 AM

It's coming... :)I'd bet that LINQ offers Tracing level logging, but I doubt you could plug in log4net...that is unless you wrote a log4netTraceListener ha!


#3 Tim Rayburn avatar
Tim Rayburn
11.01.2007
5:52 PM

I understand where you're coming from, but in my opinion this is why LINQ is far less compelling than Extension Methods and Lambda Expressions which is where your LINQ statements will compile to anyway.For instance, if you wanted to make your statement above more dynamic you could simply:List<Customer> tempList;if (someCheck)tempList = Customers.Where(c => c.Status == "Gold");elsetempList = Customers.Where(c => c.PreviousStatus == "Gold");tempList.Select(s => s.Name);This is how you can do dynamic, get compile time checking, and work just as fast as LINQ because this is what LINQ really does.The rest is syntactic sugar.


#4 Mohammad Azam avatar
Mohammad Azam
11.02.2007
12:27 PM

Might be little off-topic but the only problem I find with DLINQ is layering. How do you layer your application using DLINQ (LINQ to SQL)? Is it only for RAD type applications?