
Groovy, the Python of Java - memracom
http://www.pixelmonkey.org/2011/04/09/groovy-the-python-of-java
======
zmmmmm
Although I understand the point, I think it's more accurate to describe Groovy
as the "Ruby" of Java rather than Python. Groovy's philosophy and syntax are
all very Ruby-like, while many things about it are completely orthogonal to
the same in Python.

Where Python is usually trying to have just "one way" to do things, Groovy
offers you a million. Python actually share's much of Java's annoying desire
to keep the default namespace clean and hence make you import modules to do
just about anything useful. While Python puts simplicity and cleanliness on a
pedestal, Groovy is unashamedly pragmatic, letting you do any dirty thing you
feel like or need to do to get your job done.

In complete contradiction to Python's direction of eliminating it (eg: forcing
brackets on print() statements) Groovy gives you incredible amounts of
optional syntax - add semicolons? if you want ... or not ... except sometimes
the syntax gets ambiguous they are required. Use brackets on your function
calls? If you want ... or not ... except sometimes the syntax gets ambiguous,
so they are required. The author didn't even mention optional static typing
which not only enforces type correctness on parts of the code you apply it
too, but dramatically speeds them up. So much freedom makes it easy for Groovy
code to end up messy and unstructured compared to Python.

I'm currently in a situation where I switch between Groovy and Python coding
on alternate days. I definitely prefer different things about each. Groovy
definitely seems more powerful when I just need to get a simple job done. It
is incredible what you can cram into a single line.

I hope Groovy continues to prosper, but I worry it's getting lost among the
hype around more "sexy" languages. I think it's by far the best language for
many jobs.

~~~
bonemachine
I don't think it's about sexiness -- Python has brought many associations to
mind over the years, but _sexy_ has never been one of them -- just that there
are only so many languages that can compete in the same ecological feeding
space that (Python,Perl,Ruby,Groovy) are all pretty much butting heads against
each other over.

If anything, Python seems to be dominating in large part because of its
unabashed _lack_ of sexiness (or what passes for it in modern programming
circles: cleverness, and cuteness).

------
taude
Didn't James Strachan, the creator of Groovy, basically say that if he could
do it over again, he'd create Scala?

(a little Googling later...)

"Though my tip though for the long term replacement of javac is Scala. I'm
very impressed with it! 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." [1]

[1] [http://macstrac.blogspot.com/2009/04/scala-as-long-term-
repl...](http://macstrac.blogspot.com/2009/04/scala-as-long-term-replacement-
for.html)

Edit: I should add that I'm considering using Groovy with a micro-framework
called Ratpack ([http://www.ratpack.io/](http://www.ratpack.io/)), so I'm only
bringing this up as a part of the conversation if someone's trying to figure
out what they want to learn next.

------
mattdeboard
Clojure is the thing that fills the flexible, expressive language niche on the
JVM for me. This is to say nothing about Groovy, I've never touched or looked
at it.

~~~
pixelmonkey
I think Clojure is great. I even wrote -- a year or so after writing this post
-- that it might be a great language as a mind expander[1].

But Clojure is so dramatically different from both Java (the language) and
dynamic languages more broadly (e.g. Python/Ruby), that it's a bit of a leap
for workaday programmers; it's certainly no clean-up man.

[1]
[http://www.pixelmonkey.org/2012/06/13/clojure](http://www.pixelmonkey.org/2012/06/13/clojure)

~~~
SeanLuke
> and dynamic languages more broadly (e.g. Python/Ruby)

[sigh]

It's a sign of the times when HN posters say "dynamic languages" and manage to
ignore the Elder Language, the language from whence all dynamic languages
sprung. And that language is...

~~~
whyenot
The Land of Lisp
[http://www.youtube.com/watch?feature=player_detailpage&v=HM1...](http://www.youtube.com/watch?feature=player_detailpage&v=HM1Zb3xmvMc#t=62)

(but I'd argue it wasn't until InterLISP and Smalltalk that all the pieces
were there)

------
netforay
As I was pointing in some other post, I am always looking for some thing
better than Java. My problem is Very Very Good IDE. Without that I won't work
with any language no matter how much great it is. (Because my programmers not
not smart). They live and think in Java and Eclipse. Can someone let me know
where does Groovy Stand with when compared to Java + Eclipse?

~~~
mbell
Groovy works extremely well with Intellij Idea. I often mix Java and Groovy in
projects and for the most part it's seamless. I'll start something in Java and
as soon as I run into something that should be done with a closure or
functional idioms that would require 100 lines of java instead of 2 lines of
groovy, I just change the file extension from .java to .groovy, write it as it
should be and move on.

~~~
seniorsassycat
This is Groovy's biggest advantage, but it is often left out of discussions.

------
nnq
How about JRuby?

...why do we have both a Ruby-like language and a Ruby implementation running
atop the JVM? Sounds like a lot of fragmentation and wasted resources.

~~~
msgilligan
They are two totally different use cases.

Edit: I guess I should explain this a little:

Groovy: A superset* of the Java language, you can (generally) rename a .java
file to get a valid .groovy file. Groovy uses the Java libraries -- a Groovy
string is a Java string. A Groovy object can subclass a Java object and vice
versa.

Groovy is perfect for Java developers who want a gentle learning curve for new
language features and want fine-grained interaction with other existing Java
(and JVM) libraries and components.

JRuby: A full* implementation of JRuby and libraries that runs on the JVM. A
Ruby string is not a Java string. JRuby can call Java and vice versa, but
there's some impedance mismatch because of differences in the object
libraries.

JRuby is great for Ruby developers and/or people who need to run Ruby-based
technologies in the JVM environment (e.g. Rails, Asciidoctor, etc.)

Most people knowledgable of both technologies would not view this as
(unnecessary) fragmentation. There has also been some work on the JVM that has
benefitted both languages -- most notable the InvokeDynamic byte code
additions to better support dynamic languages (benefiting Groovy, JRuby,
JavaScript, and others.)

* There are some corner-cases where valid Java is not valid Groovy. Similarly, there are some C-language extensions in Ruby that aren't' available in JRuby. But in both cases the exceptions are rare enough to be relegated to a footnote.

~~~
vorg
Java 8 will make Groovy completely irrelevant: the lambdas will make Groovy
closures redundant, and the bundled Nashorn Javascript will take away Groovy's
use case for quick & dirty testing scripts.

~~~
mcv
I think it'll make them more efficient, and therefore more relevant. Groovy
has many, many other improvements over Java than just closures.

------
mcv
> It is also the world’s first programming language that was written to target
> an existing community of programmers.

That is not true. Java was written to target C++ programmers.

------
lmm
There was a time when I would have wanted this - I was a python guy for years.
But I've found I can be just as dynamic in scala (perhaps even more so, given
implicits), without having to give up type safety. E.g. his example looks
almost identical in scala:

    
    
        List("Rob", "Christopher", "Joe", "John").filter{ 
          _.size <= 4 
        }.foreach {
          println _
        }

~~~
cryptos
Or even more concise:

    
    
        List("Rob", "Christopher", "Joe", "John").filter(_.size < 5).foreach(println)

------
Gonzih
I always though that Groovy was inspired by Ruby.

~~~
adamors
It was, and it looks/behaves almost like Ruby as well. It also shares
Ruby's/Perl's TMTOWTDI, sort of the antithesis of Python.

Not to mention the name is a homophone.

------
Rockdtben
I thought Jython was the Python of Java?

~~~
woof
Jython is Python _on_ Java, _in_ Java.

------
slashdotaccount
uh groovy is a clusterfuck for cats who learn about closures on the corner,
hanging out with brendan eich or somesuch. gradle does seem like a nice buold
system. regardless, java is some sort of cosmonaut condom, worth using mostly
for the big software written in it behind a firewall of jvm free physical
hardware.

