Alex headshot

AlBlue’s Blog

Macs, Modularity and More

Groovy has an interpreter

2007

My prior post raised a few heckles from the Groovy community as I dared to imply that Groovy was an interpreted langauge. This just goes to show that any post that is critical of Groovy is rarely read properly; and secondly, that advocates of Groovy don't understand languages in general.

There is no such thing as an interpreted language. A programming language has a syntax and semantics that govern its behaviour (or, in the case of Groovy, a few tests). Ultimately programs written in a textual format go through many individual steps before getting down to execute instructions on a processor (and for that matter, most modern processors treat the instruction sets such as x86 as something that gets further refined into microcode before executing on silicon anyway). Trying to argue what those distinct steps are (and whether something is 'interpreted' or 'compiled') makes about as much sense as arguing whether something is a unit test, integration test or system test. The point is that there are tests, not what you call them.

On the other hand, it's possible to say whether there exists a specific implementation that allows you to execute a program written in a language immediately or whether additional steps (such as an intermediate translation into a lower-layer format such as byte-code) are necessary before a program can be executed.

Groovy has an interpreter, and it is called Groovy Console (which is Swing-hosted) or indeed the command-line Groovy Shell (even described on the Installing Groovy page. These tools provide the ability to interpret Groovy code. It's even spelled out on the wikipedia page on interpreting that an interpreter is:

An interpreter is a computer program that essentially compiles and executes (interprets) another computer program "on-the-fly" at runtime

Note that there's nothing specific about a language which makes it interpreted or compiled. There's even a C interpter, and for that matter, a Java interpreter. All an interpreter does is allow you to execute statements in a language without the need for separate steps first. Languages which have interpeters can also be compiled, too; there's a VB compiler as well as a REXX compiler (and for NetREXX too).

Whether this interpreter uses tools like Lex and Yacc, or whether it's custom parser; whether there's an intermediate ADT step or direct translation to byte-code or machine instructions, it's somewhat irrelivant. The point is that an interpreter is an all-in-one tool that allows you to run programs without requiring an intermediate step; everything else is implementation. Mind you, given that Groovy users can't even get closures right, it's not surprising that they don't understand interpreters either.

Oh, and for the record, Scala does get closures right; it too, has an interpreter (called 'scala') that can be used to interpret Scala programs or run Unix shell scripts, as well as scalac which compiles those same Scala programs to .class files which are then directly executable on any JVM. It works in exactly the same way as does Groovy; the scala code is converted on-the-fly to byte-code, which is then executed. For that matter, Haskell programs can be interpreted (e.g. with Hugs), compiled (with YHC) or indeed interpreted or compiled (with GHC/GHCi).

Groovy has an interpreter, and it's called Groovy Shell or Groovy Console.