Groovy

Groovy, a scripting language targeted for JVM, was mentioned in Slashdot
today.

http://groovy.codehaus.org/

Any comments? It seems to borrow some stuffs from Ruby, like closure
(which is very much like Ruby’s block), the =~ regex matching operator,
and even the “Principle of Least Surprise”. But syntax-wise it’s
basically a mixture of Python, Ruby, and Java. It has some stuffs that
Ruby doesn’t currently have like keyword arguments, easier embedding,
and native threads, but it’s still not Ruby :slight_smile:

···


dave

Groovy, a scripting language targeted for JVM, was mentioned in Slashdot
today.

http://groovy.codehaus.org/

Any comments?

yes, It seem many rubyist are even groovytes. If you look in the
groovy wiki you may find even matz’ quotes :slight_smile:

It seems to borrow some stuffs from Ruby, like closure
(which is very much like Ruby’s block),
actually they get the whole block/yield syntax :slight_smile:

the =~ regex matching operator,
and even the “Principle of Least Surprise”. But syntax-wise it’s
basically a mixture of Python, Ruby, and Java. It has some stuffs that
Ruby doesn’t currently have like keyword arguments, easier embedding,
and native threads, but it’s still not Ruby :slight_smile:

even GPath is cool. But mostly I love the key: value syntax for
hashes. Luckily we’ll see it in ruby soon :slight_smile:

I think is interesting that groovy received a much better acceptance
from java people than, say, jruby or jython. I believe that somehow
relates to the number of { and } :slight_smile:

···

il Wed, 17 Mar 2004 15:07:16 +0900, David Garamond lists@zara.6.isreserved.com ha scritto::

David Garamond wrote:

Groovy, a scripting language targeted for JVM, was mentioned in Slashdot
today.

http://groovy.codehaus.org/

Any comments? It seems to borrow some stuffs from Ruby, like closure
(which is very much like Ruby’s block), the =~ regex matching operator,
and even the “Principle of Least Surprise”. But syntax-wise it’s
basically a mixture of Python, Ruby, and Java. It has some stuffs that
Ruby doesn’t currently have like keyword arguments, easier embedding,
and native threads, but it’s still not Ruby :slight_smile:

it looks cool. and it might improve the productivity for java programmers.

I like java a lot but everytime I port one of my Java programs to Python or
Ruby I am annoyed about how much I have to type in Java (System.out.println
vs. puts/print, or opening and printing a file).

so this might be a great addition to the java developer’s toolbox.

only future will tell if this will be a huge success or not.

markus

David Garamond wrote:

Groovy, a scripting language targeted for JVM, was mentioned in
Slashdot today.

http://groovy.codehaus.org/

Any comments? It seems to borrow some stuffs from Ruby, like closure
(which is very much like Ruby’s block), the =~ regex matching
operator, and even the “Principle of Least Surprise”. But syntax-wise
it’s basically a mixture of Python, Ruby, and Java. It has some stuffs
that Ruby doesn’t currently have like keyword arguments, easier
embedding, and native threads, but it’s still not Ruby :slight_smile:

borrow some stuff<<- seemed to me it borrowed a lot, i was
surprised at how much.

gabriele renzi wrote >>number of { and }<< and semi colons too - i
really miss those :slight_smile:

markusjais@yahoo.de wrote: >>only future will tell if this will be a
huge success or not<< my guess is that it will be a big success as
scripting languages supplant compiled ones as biz decision makers begin
to see that you can get real work done with them in less time. this is a
good thing for ruby, me thinks, as there are so many java shops who
could benefit from groovy immidiately and get them thinking of script
languages for real work. if i were a java guy(or mgr) i’d be all over it.

Paul Vudmaska wrote:

markusjais@yahoo.de wrote: >>only future will tell if this will be a
huge success or not<< my guess is that it will be a big success as
scripting languages supplant compiled ones as biz decision makers begin
to see that you can get real work done with them in less time. this is a
good thing for ruby, me thinks, as there are so many java shops who
could benefit from groovy immidiately and get them thinking of script
languages for real work. if i were a java guy(or mgr) i’d be all over it.

It is certainly easier to use than Java (I write Java code for a living,
and I’ve played with Groovy), but the already-resource-hungry Java
environment becomes even more so when using Groovy. Groovy does not use
any of Java’s primitive types–everything is an object, which means
ints, etc. all get boxed into Integer objects. This means iteration
over a range is MUCH slower in Groovy than in Java. I was, frankly,
very disappointed when I discovered that, since I would otherwise have
started using Groovy in a heartbeat, and told my supervisors about it
after I’d already snuck Groovy apps into production. :slight_smile:

It is a step in the right direction, though.

···


Jamis Buck
jgb3@email.byu.edu
http://www.jamisbuck.org/jamis

ruby -h | ruby -e
‘a=;readlines.join.scan(/-(.)[e|Kk(\S*)|le.l(…)e|#!(\S*)/) {|r| a <<
r.compact.first };puts “\n>#{a.join(%q/ /)}<\n\n”’

markusjais@yahoo.de wrote:

Any comments? It seems to borrow some stuffs from Ruby, like closure
(which is very much like Ruby’s block), the =~ regex matching operator,
and even the “Principle of Least Surprise”. But syntax-wise it’s
basically a mixture of Python, Ruby, and Java. It has some stuffs that
Ruby doesn’t currently have like keyword arguments, easier embedding,
and native threads, but it’s still not Ruby :slight_smile:

it looks cool. and it might improve the productivity for java programmers.

I like java a lot but everytime I port one of my Java programs to Python or
Ruby I am annoyed about how much I have to type in Java (System.out.println
vs. puts/print, or opening and printing a file).

so this might be a great addition to the java developer’s toolbox.

only future will tell if this will be a huge success or not.

One interesting thing about Groovy is the GString class, which exposes
the process of string interpolation to the programmer. We can extend
this class to modify the behaviour of interpolation. This probably will
be more interesting if implemented in Ruby because we can modify the
existing builtin class, so for example we can change String so that all
interpolation is HTML-escaped. This will become a very good protection
for cross-site scripting.

All of the web tools/template processor I’ve worked with, including PHP,
Perl’s HTML::Mason, Embperl, etc. unfortunately it seems that only
Embperl puts an emphasis on escaping. By default, all strings output
will be HTML-escaped or URL-escaped, depending on the context.

If more tools were like this, then the occurence of SQL injection,
cookie theft, and all that silly website deface could be reduced
dramatically. Currently many many applications are vulnerable to XSS,
the big offender being PHP and Perl/CGI scripts, but big apps like
Oracle Suite are once vulnerable too.

···


dave

It’s more a matter of focus. JRuby and Jython are focused on porting an
entire language Java platform, each with their own standard libraries.
They talk to the Java libraries, but they feel more comfortable with
‘their own kind’. Groovy doesn’t have the baggage of its own standard
library, and thus feels more natural for a Java programmer who wants to
use a more dynamic language to interact with existing Java libs.

Charles

···

On 17/03/2004, at 7:09 PM, gabriele renzi wrote:

I think is interesting that groovy received a much better acceptance
from java people than, say, jruby or jython. I believe that somehow
relates to the number of { and } :slight_smile:


Charles Miller charles@atlassian.com

Confluence: Thought-Sharing For Your Team

In article 405C2AEA.9000605@zara.6.isreserved.com,
David Garamond lists@zara.6.isreserved.com writes:

One interesting thing about Groovy is the GString class, which exposes
the process of string interpolation to the programmer. We can extend
this class to modify the behaviour of interpolation. This probably will
be more interesting if implemented in Ruby because we can modify the
existing builtin class, so for example we can change String so that all
interpolation is HTML-escaped. This will become a very good protection
for cross-site scripting.

All of the web tools/template processor I’ve worked with, including PHP,
Perl’s HTML::Mason, Embperl, etc. unfortunately it seems that only
Embperl puts an emphasis on escaping. By default, all strings output
will be HTML-escaped or URL-escaped, depending on the context.

If more tools were like this, then the occurence of SQL injection,
cookie theft, and all that silly website deface could be reduced
dramatically. Currently many many applications are vulnerable to XSS,
the big offender being PHP and Perl/CGI scripts, but big apps like
Oracle Suite are once vulnerable too.

I considered similar idea for similar needs. However I found that it
can be used for various purposes other than sanitizing.

For example, gettext can know literal part of “…#{…}…”. This
makes possible to use only literal part as a key for i18n message
dictionaly. This eases i18n application development.

Another example is confusing String#gsub’s 2nd argument. gsub can
interpret “…#{1}…” as ‘…\1…’. This avoids confusing escape
mechanism.

I’d like to see it in Ruby. RCR?

···


Tanaka Akira

[snip]

Another example is confusing String#gsub’s 2nd argument. gsub can
interpret “…#{1}…” as ‘…\1…’. This avoids confusing escape
mechanism.

I’d like to see it in Ruby. RCR?

With oniguruma (Rubys new regexp engine) you can use named backreferences.
But that is not what you ask for.

Another possibility would be to pass a block to gsub

str.gsub!(/(\s\w)(\w+)(\w\s)/) do |m|
$3 + $2 + $1
end

And then use $1…$9, but it seems more complex.

BTW: Why is ‘m’ of class String. It would be nice if it were
an instance of MatchData. If it had been a MatchData object,
then the following piece would have worked.

str.gsub!(/(\s\w)(\w+)(\w\s)/) do |m|
m[3] + m[2] + m[1]
end

···

On Wed, 24 Mar 2004 20:50:17 +0900, Tanaka Akira wrote:


Simon Strandgaard

In article pan.2004.03.24.13.22.04.276639@adslhome.dk,
Simon Strandgaard neoneye@adslhome.dk writes:

With oniguruma (Rubys new regexp engine) you can use named backreferences.

For named capture, “…#{:foo}…” can be used as
gsub(/…(?…)…/, “…#{:foo}…”). Anyway it avoids
backslash escape in the argument.

But that is not what you ask for.

Yes. This is another issue. However I considered it too.

Another possibility would be to pass a block to gsub

str.gsub!(/(\s\w)(\w+)(\w\s)/) do |m|
$3 + $2 + $1
end

And then use $1…$9, but it seems more complex.

Yes. gsub’s block avoids the confusion.
However, people tends to gsub without block because it seems simpler.

BTW: Why is ‘m’ of class String. It would be nice if it were
an instance of MatchData. If it had been a MatchData object,
then the following piece would have worked.

str.gsub!(/(\s\w)(\w+)(\w\s)/) do |m|
m[3] + m[2] + m[1]
end

I think a regexp with named capture should binds local variables.
It makes possible to describe your example as follows.

str.gsub!(/(?\s\w)(?\w+)(?\w\s)/) { a + b + c }

Note that embedded regexp by #{} shouldn’t bind local variables.

···


Tanaka Akira

following suggestion from flgr on #ruby-lang it would be nice to have
gsub yielding a MatchData with to_str defined to still allow stuff
like

str.gsub(rgx) do |m|
‘str’+m
end

···

il Wed, 24 Mar 2004 22:48:29 +0900, Tanaka Akira akr@m17n.org ha scritto::

BTW: Why is ‘m’ of class String. It would be nice if it were
an instance of MatchData. If it had been a MatchData object,
then the following piece would have worked.

str.gsub!(/(\s\w)(\w+)(\w\s)/) do |m|
m[3] + m[2] + m[1]
end

In article 87hdweuzit.fsf@serein.a02.aist.go.jp,
Tanaka Akira akr@m17n.org writes:

str.gsub!(/(\s\w)(\w+)(\w\s)/) do |m|
m[3] + m[2] + m[1]
end

I think a regexp with named capture should binds local variables.
It makes possible to describe your example as follows.

str.gsub!(/(?\s\w)(?\w+)(?\w\s)/) { a + b + c }

Oops. It should be:

str.gsub!(/(?\s\w)(?\w+)(?\w\s)/) { c + b + a }

···


Tanaka Akira

Never thought of using named-captures 2 local-variables…
This would be a nice 2 have feature.

I have looked a little at perl6 regexp… above example would then look
sligthly different (rubified perl):

rules(:a=>‘\s\w’, :b=>‘\w+’, :c=>‘\w\s’)
str.gsub!(/ /) { c + b + a }

Readability is improved a little :wink:

···

On Thu, 25 Mar 2004 12:29:50 +0900, Tanaka Akira wrote:

In article 87hdweuzit.fsf@serein.a02.aist.go.jp,
Tanaka Akira akr@m17n.org writes:

str.gsub!(/(\s\w)(\w+)(\w\s)/) do |m|
m[3] + m[2] + m[1]
end

I think a regexp with named capture should binds local variables.
It makes possible to describe your example as follows.

str.gsub!(/(?\s\w)(?\w+)(?\w\s)/) { a + b + c }

Oops. It should be:

str.gsub!(/(?\s\w)(?\w+)(?\w\s)/) { c + b + a }


Simon Strandgaard

Agree. Has this been submitted as an RCR before?

If not, it may be a good candidate for an RCR.

···

On Wed, 24 Mar 2004 14:29:06 +0000, gabriele renzi wrote:

il Wed, 24 Mar 2004 22:48:29 +0900, Tanaka Akira akr@m17n.org ha
scritto::

BTW: Why is ‘m’ of class String. It would be nice if it were
an instance of MatchData. If it had been a MatchData object,
then the following piece would have worked.

str.gsub!(/(\s\w)(\w+)(\w\s)/) do |m|
m[3] + m[2] + m[1]
end

following suggestion from flgr on #ruby-lang it would be nice to have
gsub yielding a MatchData with to_str defined to still allow stuff
like

str.gsub(rgx) do |m|
‘str’+m
end


Simon Strandgaard