|
Thursday, January 8, 2004 |
There's some discussion on why Groovy exists and why we didn't just use JRuby. Its a good question. Here's my attempt at an answer...
FWIW I really like Ruby. Before I started working on Groovy I was
leaning a bit more towards Python, as the Perliness of Ruby put me off
a little bit. Though the more I worked on Groovy the more I liked the
Ruby way of doing things and the less I liked Python (I think its
something so trivial as all those underscores & self parameters, it
just doesn't really feel OO). I also found you could kinda
pretend the Perliness wasn't there in Ruby :)
So apart from a few fairly minor syntax changes (to make Groovy easier
to learn & more familiar for Java developers) Groovy syntax today
is fairly similar to Ruby (though without the global variable perliness
of Ruby :).
So why did we do Groovy? I think the main reasons are
- I've been a Java developer for many years now and I didn't want
to throw away all the code & tools & platform and use a
completely new language & platform & tools. Java sits on a JVM
so I wanted to bring the neat Ruby/Python stuff into the JVM.
- I didn't wanna move to a new API (Ruby and Python have their own
equivalents of the JDK which Jython and JRuby have to implement, since
they are a Java port of the original languages). I wanted to keep the
JDK but just make it more groovy.
- I wanted to use a language which created normal Java classes that
Java developers could use, but still gain from all the neat Ruby/Python
goodness without requiring Java developers throw away the whole JDK and
start to learn another one. i.e. code written in Groovy is immediately
available to Java developers as normal Java classes and vice versa
- It seemed like a fun thing to do :)
So the main difference between JRuby and Groovy is that Groovy is
specificially designed to sit on the JVM, to work seamlessly with
existing Java code and for all the JDK & J2EE APIs to 'poke
through'. JRuby is a port of Ruby and so tries to be Ruby implemented
in Java.
i.e. Groovy is the smallest possible addition to make Java development
Ruby-ish - while also still supporting working in a statically typed
environment as well. Groovy supports both static and dynamic typing so
Java objects are seamlessly available in Groovy and vice versa. I can
derive/overload Java classes in Groovy that are available to Java
developers. i.e. Groovy is Java really; just using a Ruby-ish
syntax. So we're using the JVM's method dispatching rules
(overload methods based on the types of the parameters), support Java
interfaces and if you want to restrict some public APIs (method
signatures) to certain types to implement Java interfaces & work
nicely with Java objects you can.
To make Groovy more Ruby-ish, we've added some Ruby-esque APIs to the
JDK / J2EE APIs themselves. So for any String, Collection, Map, Array,
File, Regex Matcher you can use closures to iterate and so forth
[1, 2, 3].each { println(it) }
Some comments on the above article talked about things going belly-up -
well I don't see Ruby, Python or Groovy going away any time soon. Its
just a question of using the right tool for the job.
If you're a Java developer or working on a Java / J2EE project and need
a more concise, easier & fun language to get things done, try
Groovy (or JRuby or Jython). Even if you just use it for writing JUnit
test cases or glue code you might like it. The neat thing about Groovy
is that everything your Java-developer colleagues do is available to
you in Groovy and vice versa since both languages just create Java
classes & bytecode. So there's no need to 'switch' platforms or
wholesale convince everyone you work with to switch languages.
If you're not working with Java and (say) just need some simple unix
scripts to do neat things well you'll probably find Ruby/Python a good
choice. Use whichever you prefer - its about choice.
9:28:24 AM
|
|
The Groovy logo contest is hotting up. Are you a budding artist / graphic designer kinda person? Come on, have a go, you'll have fun :)
8:56:34 AM
|
|
© Copyright 2007 James Strachan.
|
|
|
|
|
|
January 2004 |
Sun |
Mon |
Tue |
Wed |
Thu |
Fri |
Sat |
|
|
|
|
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
Dec Feb |
|
|
|
|
|
|