views:

367

answers:

8

After reading "What is the Java equivalent of LINQ?", I'd like to know, is (lowercase) language-integrated query - in other words the ability to use a concise syntax for performing queries over object collections or external stores - going to be the path of the future for most general purpose languages? Or is LINQ an interesting piece of technology that will remain confined to Microsoft languages? Something in between?

EDIT: I don't know other languages, but as I am learning it seems like LINQ is neither unprecedented nor unique. The ideas in LINQ - lambdas and queries - are present in other languages, and the ideas seem to be spreading.

+2  A: 

I would say that integrated query technology in any language will become foundational in time, especially given the recent rise in interest of Functional programming languages.

LINQ is certainly one of the biggest reasons I personally am sticking with .NET, anyway - it's become foundational for me personally, and I'd wager a lot of devs feel this way as well.

Erik Forbes
+1  A: 

Disclaimer: I've never used LINQ. Please correct me if I'm wrong.

Many languages have constructs which allow to the same things as LINQ with the language data types. Apparently the most interesting feature is that LINQ constructs can be converted to SQL, but it's not specific to LINQ: http://www.aminus.org/blogs/index.php/2008/04/22/linq-in-python?blog=2.

Bastien Léonard
Just as a clarification, LINQ-to-SQL and LINQ-to-entities (the technologies you're referring to that can translate a LINQ expression into a database query) are built on top of LINQ. At its core, LINQ is just a language-specific way of chaining up calls to extension methods on particular interfaces.
Adam Robinson
many languages have select statements, where clauses? I don't know of that many. database-oriented languages, yes. But general purpose ones? Perl? Python? Java, I guess from the question I referenced, doesn't. Can you give some examples?
Cheeso
Python doesn't have `select` statements or `where` clauses, but list and generator comprehensions do the same thing. List comprehensions are very common in functional languages.
Bastien Léonard
I thought list and generator comprehensions were for creating lists and enumerables, not consuming them. Although I suppose LINQ is really sort of both consuming and creating them...
Erik Forbes
First I heard of the term list comprehensions. I looked on http://en.wikipedia.org/wiki/List_comprehension and it looks like list comprehensions ARE select+where clauses.
Cheeso
Based on my reading of that wikipedia article, it sure seems like LINQ is a different take on capabilities that have been realized in different languages since the 70's. So the next question is, in python (and other langs) can I use a list comprehension to define a set of instances of an anonymous type? The basic example I saw was selecting a function of x where x is in the set of natural numbers. using the same language structures, can I select an arbitrarily complex anonymous type?
Cheeso
Whether or not other languages CAN support something like LINQ isn't very interesting until they actually DO. MS made it real for .NET, which is a big difference from "it can be done" :-)
nos
@Cheeso: you can write something like this, for example: `[(p.last_name, p.first_name) for p in persons]`. This will yield a list of tuples `(last name, first name)`. Is this what you want?
Bastien Léonard
@nos: did you read the link in my message? I agree on the fact that LINQ is step further, though: it's directly integrated into C#/.NET.
Bastien Léonard
A: 

I don't think that you can really classify it (or many things) as either. While I would hardly say that LINQ is a niche tool -- it has many applications to many people -- it's not "foundational" IMO. However, I also wouldn't say that having LINQ (or an equivalent) language-specific querying language can be truly foundational at this stage of the game. In the future, perhaps, but right now you can construct a query in many different ways that yield SIGNIFICANTLY varying levels of performance.

Adam Robinson
A: 

It sounds a lot to me like Ruby's Active Record, but I've never used LINQ. Anyone used both? (I would have posted this as a comment, but I'd really like to be updated on the answer--I'm probably wrong so it'll get downvoted :) )

(Actually I should say that AR is like LINQ to SQL, they haven't implemented AR for other targets as far as I know)

Bill K
See, this is the problem. I know LINQ but not AR. You know AR but not LINQ. Trying to figure out where they are similar, where they are different, is not so easy. Ach.
Cheeso
AR and LINQ are really orthogonal and may even be used together. LINQ lets you write SQLesque statements directly in your source language, with type safety and everything. These statements are then interpreted by some provider. ActiveRecord just means that there is a 1-1 mapping between objects and rows and each object is responsible for saving itself. A LINQ query might return a collection of such objects.
Jørgen Fogh
Active Record has a query system built in that automatically translates between its native language and SQL. AR also auto-creates classes based on database tables. So with no code at all you can pretty much say "user.find(name="Bill")" and get a collection of user objects with the field name equal to Bill (The syntax is almost certainly wrong since I haven't used Ruby for a couple years now). Much more advanced queries are possible as well. Type safety is not relevant in Ruby.
Bill K
LINQ is more like Ambition than ActiveRecord. Ambition is a query DSL for Ruby. You write your queries in a standardized language, and Ambition has adapters that translate the queries for SQL, LDAP, XQuery, Flickr, you name it. The difference between LINQ and Ambition is that due to Ruby's expressive power there is no need to wait until Microsoft brings LINQ from the mountaintop: Ambition is just a Ruby library like any other. It just extends the already existing filter methods on Enumerable/Array/Hash (select, detect, reject, find, find_all, any?, all?) to arbitrary collection-like things.
Jörg W Mittag
+4  A: 

After spending years

  • Handcrafting database access(in oh so many languages)
  • Going throgh the Entity framework
  • Fetching and storing data through the fashioned ORM of the month

It was about time somone made an easy to access and language integrated way to talk to a database. LINQ to SQL should have been made years ago. I applaud the team that come up with it - finally a database access framework that makes sense.

It's not perfect, yet, and my main headache at the moment is there's no real support for LINQ2SQL for other common databases, nor are there anything like it for Java.

(LINQ in general is nice too btw, not just LINQ to SQL :-)

Leeeroy
What about Entity Framework ? It can support any type of database, you just need the adequate provider
Thomas Levesque
"adequate provider" is a problem for a few databases. They don't exist, or arn't production ready yet.
Leeeroy
+2  A: 

I think the functional concepts which are the under pinnings of LINQ will become popular in many languages. Passing a sequence of objects through a set of functions to get the desired set of objects. Essentially, using the lambda syntax over the query syntax.

This is a very powerful and expressive way of coding.

This is not because I feel it's a fundamentally better way to do things (i.e. lambda over query syntax). Comparatively speaking, it's much easier to add the underlying library support for query expressions to a language than it is to add the query syntax. All that is required the lambda syntax for queries is

  • Lambdas
  • Underlying query methods

Most new languages support lambdas (even C++ is finally getting them!). Adding the library support is fairly cheap and can usually be done by a motivated individual.

Getting the query syntax into the language though requires a lot more work.

JaredPar
+1  A: 

I don't think linq will be confined to the microsoft languages, check it out, there is already something for the php, check it out http://phplinq.codeplex.com/

I think Linq is great tool in development process and personally would be really glad if it will be transferred to other languages(like in my example of php)

Dmitris
+6  A: 

Before LinQ, Python had Generator Expressions which are specific syntax for performing queries over collections. Python's syntax is more reduced than Linq's, but let you basically perform the same queries as easy as in linq. Months ago, I wrote a blog post comparing queries in C# and Python, here is a small example:

C# Linq:

var orders = from c in customers
             where c.Region == "WA"
             from o in c.Orders
             where o.OrderDate >= cutoffDate
             select new {c.CustomerID, o.OrderID};

Python Generator Expressions:

orders = ( (c.customer_id, o.order_id)
           for c in customers if c.region == 'WA'
           for o in c.orders if o.date >= cutoff_date)

Syntax for queries in programming languages are an extremely useful tool. I believe every language should include something like that.

Manuel Ceron
To list a few other similar features: Haskell has list comprehensions (and any Python programmer would likely immediately recognize them as generators); Scala has similar stuff, too.
Pavel Minaev
Linq can also do much more complicated stuff than this
Casebash