Quote (Eep @ Sep 28 2014 09:49pm)
groovy sounds pretty cool then
coworker first showed me groovy in the context of json. in java, you need a back-end class for libraries like Gson to convert json to something usable. in groovy you don't.
Code
def slurper = new JsonSlurper()
def result = slurper.parseText('{"person":{"name":"Guillaume","age":33,"pets":["dog","cat"]}}')
assert result.person.name == "Guillaume"
assert result.person.age == 33
assert result.person.pets.size() == 2
assert result.person.pets[0] == "dog"
assert result.person.pets[1] == "cat"
a feature i actually like from php is using $variable-name inside strings, which most languages don't have, so you rely on something like String.format or printf or string concatenation. groovy has something similar:
Code
BigDecimal account = 10.0
BigDecimal minus = 4.0
text = "Your account shows currently a balance of ${account - minus}"
assert text == "Your account shows currently a balance of 6.0"
and you get closures, traits (interfaces with default implementation), duck typing, and other goodies