We are using Groovy on Grails for an incubator project, which is incredibly refreshing! Groovy as a dynamic language with optional type annotations doesn’t quite rock my boat though. With static type checking the types you define are an essential element of design. I like to point out that Groovy’s creator wrote:
“I can honestly say if someone had shown me the Programming in Scala book by by Martin Odersky, Lex Spoon & Bill Venners back in 2003 I’d probably have never created Groovy.” >> more…
One of the biggest advantages of Groovy over Java are those nice little collection helpers. For people who first encountered them in functional languages the names are confusing. Here’s a short comparison:
| Functional Language |
Groovy |
|
| map (list, function) |
list.collect (closure) |
Applies the function to each element of the list and returns the results as a new list |
| filter (list, function) |
list.findAll (closure) |
Returns a list of all elements in the input list for which the function returns true |
| fold (list, initial element, function) |
list.inject (initial element, closure) |
Applies the function to the initial element and the first element of the list. Then applies the function to this result and the second element of the list. Get the idea? |
>> more…
I’m currently looking into another one of your bowling games, this time written in F#. Again a language I’ve never heard of, but it seems to be pretty nice. Very similar to SML (yes, I also know some languages nobody else knows!), which I learned at university. I really like functional languages, especially when it comes to list operations, with all the folding, mapping and filtering. And I really miss them in Java!
Instead of a plain
-
result = List.map function inputList
you need that clumsy and not at all explicit
-
List<OtherType> result = new ArrayList<OtherType>;
-
for (Type each : inputList) {
-
result.add(function(each));
-
}
>> more…