This is the mail archive of the
kawa@sourceware.org
mailing list for the Kawa project.
Groovy vs. Kawa smackdown ;-) (was Re: Java array class is not kawa Class?)
Per Bothner wrote:
Jim White wrote:
Groovy has very compact syntax for doing things with Java classes and
collections
Actually, Kawa's is pretty darn compact, too:
As you well know, I'm a long time Lisper and Kawa supporter, but
S-expression notation is just not gonna get most folks excited. But of
course there's no accounting for taste since many seem to love it when
you more than double up the amount of notation and use XML rather than
S-expressions. Although folks do seem to be getting tired of verbosity.
#|kawa:1|# (define v (vector 3 4 5 6))
#|kawa:2|# (set! (v 3) (v 2))
#|kawa:3|# v
#(3 4 5 5)
#|kawa:4|# v:size
4
|kawa:5|# v:class
class gnu.lists.FVector
#|kawa:9|# (set! a (integer[] 9 8 7 6))
#|kawa:10|# (set! (a 1) (a 0))
#|kawa:11|# a
[9 9 7 6]
#|kawa:14|# (java.lang.Math:cos 3.4)
-0.9667981925794611
The Groovy version of that:
groovy:000> v = [3, 4, 5, 6]
===> [3, 4, 5, 6]
groovy:000> v[3] = v[2]
===> 5
groovy:000> v
===> [3, 4, 5, 5]
groovy:000> v.size()
===> 4
groovy:000> v.class
===> class java.util.ArrayList
groovy:000> a = (9..6) as int[]
===> [I@c17f5a
groovy:000> a[1] = a[0]
===> 9
Notice in the construction of a I used the fact that ranges are lists,
and since we've been discussing arrays I showed it using a primitive
type for the components.
As you see the default display for arrays doesn't show them as lists
(they might be rather large after all and Groovy doesn't have much
support for pretty printing). But you can say:
groovy:000> a as List
===> [9, 9, 7, 6]
A sublist:
groovy:000> a[2..1]
===> [7, 9]
And what I don't show here is Groovy's notion of Truth and Iterable are
weakly typed and support many convenient default conversions. That can
make for very terse code. Plus there is autoproxying and adapters for
closures and other cool hacks to eliminate much of the fiddly glue code
folks have to write to overcome strong typing.
So for folks familiar with Java, Groovy syntax is a lot more
comprehensible, and most importantly, for language features that are in
common between Java and Groovy the syntax is the same (in fact most Java
source is acceptable Groovy). That isn't true for LISP family, Ruby,
Python, JavaFX, etc.
I would rather have a language with well-developed semantics like
Scheme, but as my preference for Groovy over Scala shows, for my current
applications it turns out yet again that worse is better.
Jim