tags:

views:

49

answers:

2

Hi, today twitting with a colleague http://bit.ly/addZQx, he said me that Groovy is like C# but without LINQ.

I don't know much about LINQ, but I answered him that Groovy has similarities to LINQ http://bit.ly/bKNrlj, for example, Groovy's class DataSet.

Can you tell me more about similarities / differences between Groovy and LINQ (C#)?

Greetings from Chile.

+1  A: 

The only similarity between C# and Groovy is their syntax. In other words, Groovy code looks fairly similar to C#. However, the true nature of the languages is very different. Groovy is more like Ruby in that it is dynamically typed and supports meta-programming. C# on the other hand is mostly statically typed.

As for similarities between LINQ and Groovy there are none really. Groovy is a general purpose language, whereas LINQ is a DSL for writing queries. A further difference is that C# and LINQ run on .Net whereas Groovy runs on the JVM.

Don
C# dynamic code can be written simply by setting "option strict off" - however I don't believe that it is really widespread.
jhominal
@jhominal - That's VB.NET, not C#.
Andre Artus
@Don - With the advent of C#4 both languages have static and dynamic type (Groovy def/ C#4 dynamic). But you are right regarding Groovy not having LINQ. Groovy does have some language features that make it easier to use the JDBC/ SQL, but it's not anything like LINQ [to everything!].
Andre Artus
@Andre - Groovy doesn't have LINQ, because LINQ is exclusively a .Net technology. Also, Groovy doesn't have any **language features** that make it easier to use SQL, but it does have some libraries (e.g. GSQL) that make it easier to use SQL.
Don
+2  A: 

I wonder who told you that ;P

First, let me clarify my statement: Many of the things that I love about c# 4.0 are implemented on groovy, but groovy is already much more succinct.

There are other obvious differences like the dynamic/scripting nature of the groovy language and so forth.

now, linq is a step over closures, like a dsl inside c# to create closures in a query (sql) like sintax, with a pattern based on interfaces and a provider model behind to allow this closures to be translated to sql or to any kind of other representation.

In this respect, since groovy has closures and beautifully implemented, AND it has many dsl-building capabilities built in, it should be possible to make a linq-like feature.

David Lay
Indeed, I suspect someone already did the work on create a LINQ-like Builder in Groovy.
taichi
Are the same functionalities accomplished from both Groovy and LINQ in this respect? I believe this is true, but I don't know what are the differences in their implementations.
taichi
@taichi as far as I know there's no equivalent to linq in groovy: dsl to translate closures into other representations via a provider model) DataSet only provides translation to SQL. there's no way to translate, to say, to a hibernate criteria selection like link2nhibernate (AFAIK) or to query an array like link2objects.
David Lay