Why I like Groovy – Part 1

Over the years I have worked with many programming languages.

For me, it is important that the language be ‘simple’ enough for me to keep thinking about the problem that I am trying to solve.

Note that I did not say solution! If one has to think too much on the mechanics of trying to get the proposed solution to work, we often lose sight of identifying what the real problem is.

However, the language also has to be able to be handle the difficult tasks. To quote Larry Wall, Tom Christiansen and Randal L. Schwartz about Perl:

Perl is designed to make the easy jobs easy, without making the hard jobs impossible.

This is where Groovy is for me. It can be used to do one off scripts and basic data munging to coding in full stack frameworks such as Grails or to an Enterprise build automation system like Gradle.

When trying to solve a problem, I want to be thinking close to the problem domain.

For example, reading a file in groovy is as simple as the following:

  def fileText = new File('path_to_file').text

Variable fileText now has the content that I am interested in.

Another example if we want to find all the h4 headings on web page, one quick texty way could be to use

  new URL('http://www.radionz.co.nz/about').text.eachLine {
    if (it.contains('h4')) {
      println  it
    }
  }

The following provide useful information on learning about the Groovy Language: