This is our response to
Anonymous generic methods making things “just work”
using Scala instead of C#. Others had coded
solutions in Java or Groovy.
Here’s our code in
Scala. Have a look, how simple things can be:
object FindPersonsDemo with Application
{
case class Person(firstName: String,
lastName: String,
age: Int);
val persons = List(
Person(“Cathi”, “Gero”, 35),
Person(“Ted”, “Neward”, 35),
Person(“Stephanie”, “Gero”, 12),
Person(“Michael”, “Neward”, 12));
val newards = for (val p <- persons;
p.lastName == “Neward”) yield p;
Console.println(newards);
}
The
solution in groovy is also very short and nice to read. I was impressed. We had a look at Groovy for some time, because it seems to be a very cool scripting language, with Java roots which makes it very interesting. So we tried to start using it for tests. We tried. With little success. After asking some questions in the user mailing list we got an solution, which did not satisfy us.
Many groovy examples I have read were confusing. There are so much tricks and things you have to know to understand them. A nice example is the map creation syntax, which starts a great discussion in the mailing list. It seems to be very nice:
def map = [name:“Wallace”, likes:“cheese”]
But you can only use Strings as identifier. I had not seen this until some one points this out on the mailing list. This is very ugly, I think.
Let’s get back to the example. I think Scala is much faster and in contrast to a scripting language and it is type save. Yes, it’s really type save, even if you don’t see some type informations in this short piece of code.
I think we will have a look at Groovy again in the future, but Scala seems to be the language of choice at the moment. (beside the standard languages like Java, C#, ...) There’s nother
Nice one, but it does not seem to be stable enough for use in real projects.
The first real post in our new blog, by the way.