Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

I haven't used Python since 2004, and never became an expert. But isn't is possible to achieve most of what LINQ does in Python? I know in Ruby it's possible to call sort with a block (http://snippets.dzone.com/posts/show/2120). IMHO, that code resembles the spirit of LINQ. That's without even touching on the ActiveRecord portion of Rails which achieves a lot of what LINQ does too. There's got to be a way to do this sort of thing in Python too, even if it requires a third-party library.

UPDATE: Here's a better example for Ruby syntax compared to LINQ.

http://intertwingly.net/blog/2005/09/29/Ruby-1-8-vs-LINQ



Python's generator expressions let you get the common 90% of what you would do with Linq. Generator expressions, however, quickly become awkward when nested and don't really support joining or grouping data. Python has a groupby method and similar helpers, but they simply aren't as natural as the SQL-style syntax. Also, Linq puts the object being queried first to make it toolable (IntelliSense can offer completion for members in where and select clauses, etc).

I don't know much Ruby, but I'd suspect that blocks can simulate Linq far better than Python can. However, the Lambda-inspired syntax is a bit cluttered when compared to the SQL-inspired syntax.

Linq is a feature about 3 things:

1) Correctness via static typing checks

2) Interoperability of various data backends (Microsoft provides backends for XML, SQL, and .NET objects)

3) Clean and beautiful code

Neither Python nor Ruby can provide #1 (at compile time, anyway). SqlAlchemy and other projects attempt #2, but I don't have enough experience with them to comment on their success. And while Python as a whole (and I presume Ruby) has lots of #3, complex data querying is not the most beautiful experience.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: