One aspect of Groovy ( and Ruby, Python , etc ) I really like is the combination of closures and support for them in the Groovy DK .
As an example, consider iterating through every line in a text file :
Very elegant and easy on the old eyes.
Java with some help
and the supporting code :
Apologies for my C#, I have not been writing it for very long...
No need to escape path string is nice
C# 2.0 with some help
With C# 2.0 and the 2.0 .NET framework the addition of anonymous delegates we can produce a very concise and readable solution
similar in elegance to the Groovy one.
This depends on the following utility class
You will notice that I have started implementing the Groovy DK set of collection iterators (each, findAll, find , etc ) for C# 2.0.
I do wish Microsoft and Sun would have built this kind of simplicity in....
There are 2 possible approaches to the Collections :
- Subclass and add the grooviness
- Add the grooviness as a set statci methods you plass the collection to
Here is some perlimenary code and tests of both types.
This subclasses List<T> and adds the groovination, and offers the same support ina static class