Your Thoughts on the Groovy Scripting Language?
lelitsch asks: "Does anyone have first hand experience with Groovy?
I am just coming off implementing a Plone-based intranet CMS and got hooked on scripting languages and Python all over again. Since most of my projects in the near future are going to be in Java or have large Java components, I was wondering if it's time to trade Jython--which seems to be falling further behind the Python release cycle--for something else. Groovy sounds like a fun thing to look at, but it seems a bit new and thin. Also, what are other languages (JRuby and Rhino, for example) you have used to script in Java?"
It's a pretty Groovy language. I still prefer Object Cobol though.
Who cares if Jython is a little behind CPython if it already has all the features you need at this point? When I do work with CPython, I work from a relatively old edition of O'Reilly's Python in a Nutshell as reference, and find that the language at version 2.0 already does everything I need it to. While features added at 2.2 and 2.4 are undoubtedly useful for certain audiences, the language itself was complete for most purposes some time ago, and Jython should serve most people fine.
Seriously... it runs on top of Java.
I also have been enjoying scripting languages, mostly Ruby. JRuby is still in active development, contrary to belief, and they have versions of IRB running with it.
.NET apps at an upcoming Code Camp in St. Louis.
.NET, or in Java (not that Ruby is the only one that can do that)
I'm giving a presentation on using Ruby for scriptable
I haven't played much with Groovy, but I like the idea of Ruby in that I can write scripts that will run standalone, in
Random Musings
From what I've seen, Groovy's a half-baked programming language and unfinished product. See this criticism for a start.
If you want to do embedded scripting in Java, I suggest Bean Shell instead. As a library, Bean Shell is about 280K, Groovy is about 1.7M. And Bean Shell has been around for a lot longer.
I'd like to see Sun add closures and better support for lists/maps in Java itself (e.g. a map function). I'm hoping that pressure from Ruby will make the language grow. C# already made them change their mind about Generics.
n/t
See my journal for slashdot ID's by year. Mine created in 2005. http://slashdot.org/journal/289875/slashdot-ids-by-year
I think you always need a reason before you try something new and unproven. If it is an enterprise app, why? Is there a feature that Python et al. does not do? If you have no experience with it, and no good reason to switch - Why bother?
"Sure there's porn and piracy on the Web but there's probably a downside too."
I wanted to use Drools and Groovy a while back to set up the variable pricing for a tollway. But who on earth is going to put that kind of system in the hands of technology named Drools and Groovy? No one wants to sound like an idiot going to their boss to suggest using anything with those names. Digital started off as Digital Intergalatic Research but quickly realized that suits don't use products that they feel stupid saying. A pun here or there is ok but there is a limit and I think Groovy, no matter what the technical benefits, has stepped over that line and can never be taken seriously. At least the Java community for the most part has gotten over the coffee metaphors when naming new products.
for lightness and performance. At least as far as scripting languages go. I can't say I'm a fan of Java but if you insist:
There is Java/Lua integration in the form of JLua and LuaJava. Possibly other tools as well.
The ratio of people to cake is too big
it's groovy?
Seriously, who would choose to use this over an existing and popular scripting language? Given than Jython and JRuby exist, and Groovy doesn't offer much that they don't, what is the point other than to be deliberately obscure?
YASL
1. Bad signature
2. ?????
3. Profit
If I'm going to the trouble of writing a new language, I have to have some motivation. What is it about existing languages that makes it necessary to create a new one. What is it supposed to do differently?
What I got from tfa was something like: "It's a scripting language and it's kinda more like java than the other scripting languages or something like that."
I started to use Python when I was looking for a cross-platform language to replace visual basic/qbasic. There was an article on Slashdot about developers at Sun who found that java didn't work very well in their programming environment. They suggested a couple of alternatives and Python was one. I had considered java but with Python I was much more productive. I wonder if that would be true for Groovy.
My first reaction to what I saw in tfa was: "Oh goodie, it should be fairly easy to write obfuscated code." Not much of a recommendation.
Anyway, if anyone groks why this language was created, I'm curious.
There is JScheme, and Kawa.
Weapons of Mass Analysis
other than ocaml and ruby are totally insane. I mean, I can code in java or c just fine, but it makes me want to pull my hair out, and all decent normal people must feel the same way.
I've used Java a long time, and when I got tired of the hoopla about how scripting languages are so much better than strongly typed languages, I thought Groovy would be a good choice, since "Groovy is an agile dynamic language for the Java Platform with many features that inspired languages like Python, Ruby and Smalltalk, making them available to Java developers using a Java-like syntax." So, I set out to develop a small (internal) project, but after a couple weeks I got tired of the clunky syntax (not to mention the sparse documentation) -- I just couldn't express myself. A few months later I came back and reimplemented the project in Ruby in a fraction of the time, much more clearly and concisely. Now I 'get' what scripting languages are all about.
My (anonymous) $0.02: go with the real scripting languages (Perl, Ruby, PHP, Python, etc.).
Simply put, Java is a language to write programs and scripts connect programs.
If I want to script from a Java program, I call ascript using Runtime.getRuntime().exec(cmd). The de-facto scripting languages are Bourne shell or Perl. Most scripters can read/maintain these. Only very reluctantly I will write scripts in any other language than these. As a very strict rule, anything I cannot do in Bourne, I do in Perl.
What makes Java very unsuitable for scripting is the absence of a Posix package. Setting ownership and mode of a file is a pain. Don't even think about hard and symbolic llinks, let alone Unix devices.
I hadn't the slightest objection to his spending his time planning massacres for the bourgeoisie... (P.G. Wodehouse)
I use Sleep, a perl-like scripting language for java which is extremely easy (and fun) to embed and extend.
Hecl: http://www.hecl.org/
it is perhaps less general-purpose than the poster might want, but I have different design considerations in mind:
Small, flexible, very dynamic, and concise - in other words, I want it to be a complement to Java, rather than simply a scriptable Java, ala Beanshell. This means that perhaps you wouldn't want to write the entire app in Hecl, but on the other hand, as a language to write quick extensions with, perhaps it's a bit faster/easier to work with.
The most interesting feature at this point is that Hecl is small enough to run on Java-enabled cell phones, even pretty basic ones like my Nokia 3100, which only accepts Java stuff - no symbian. This means that you can code apps with no recompiling, and also make them very dynamic (you could make an app that downloads code, stores it and runs it as needs be).
Also, for the folks who like this stuff, Hecl is still young, so there's lots of room to fiddle with the language itself, and learn about how a scripting language is built.
Astute observers will note that Hecl is similar to Jacl, but like the poster complaining about Jython getting a little bit out of date... it always seemed like a bit of a losing proposition to me to do a copy of a language in Java, because you miss out, if nothing else, on a *lot* of libraries, and the JRuby/Python/Tcl implementations have always seemed to be playing catch-up.
http://www.welton.it/davidw/
I have looked at Groovy but it does not seem stable enough to use in enterprise apps. However GNUStep for server side development is very solid platform. Objective-C, the language of GNU Step, is very good at talking with Ruby and Python.
My money is that there will be alot of attention passed to GNUStep in the near future as a condender on server side and even client x-platform side app development.
My Ideal web/app server is Free BSD + GNUStep + Ruby and/or Python.
JsD
Come on, there was a beta version of Generics floating around (that worked in 1.4) before C# was even out. The guys adding Generics wanted to add it much sooner (even in 1.3 I think) but there was too much contention in the community about how best to add it.
Java was a little slower actually getting it in, but that's because they had a lot of legacy code to consider and how to make generics that would be useful even with older libraries. In no way was Java actually pressured to include Generics just becasue C# had it, they faced a lot more pressure from a world of developers wanting something like generics from 1.0 on.
"There is more worth loving than we have strength to love." - Brian Jay Stanley
There is a really nice Scheme interpreter on the JVM called SISC:
http://sisc.sourceforge.net/
IMNSHO Scheme is so much nicer than Python et al that there's not even a decision to be made here as far as dynamic languages on the JVM.
There's also Scala, which is another statically typed language on the JVM. It is SORT of like Java, and can use Java classes natively, but is about 20 times more pleasant to use than Java (if you're into higher-order functions and pattern matching and that kind of thing... but then, everyone should be into that stuff). Anyway, Scala isn't a scripting language, but depending on what you're planning on doing, using it may persuade you that you didn't actually need a scripting language, you just needed a language that wasn't painful to use like Java is.
Scala:
http://scala.epfl.ch/
I am wondering if Groovy is not dead. For example see this:
http://jira.codehaus.org/browse/GROOVY-1194
This bug is pretty serious and it was filed 4 months ago. No reaction so far.
With the advent of Java, a lot of young programmers finally saw a way of running their OS-specific programs on other platforms. Unfortunately, the limitation was that a Java VM had to be ported to the platform that they wanted to run their code upon. This Java VM was written in C or C++. Sadly, the distraught Java programmer could not contribute to the effort to port the Java VM to their favorite platforom because they did not understand the intricacies of such things as memory management. Thus, their code did not run on their favorite platform.
These programmers, being passionate about their art, resolved to learn the skillz they needed to port the Java VM to their favorite platform. As they learned the necessary knowledge to run their code, realized that they could have gotten their code to run on any platform much more easily if they wrote it in a compiled-to-machine-code language. These programmers are no longer Java programmers.
Why write code in a scripting language that runs on fewer platforms than other scripting languages? The main advantage of a scripting language is (arguably) the ability to run your code on multiple platforms. A scripting language should be ubiquitous; tying your code to both a compiler that some guy created and the Java VM is not a good idea(tm).
Nice is another JVM-based language that could do with a mention. It puts more emphasis on programming correctness than Groovy, including features such as pre-conditions and post-conditions and safety from NullPointerExceptions. According to the Computer Language shootout, it compares favourably to Java in terms of speed and efficiency, whilst Groovy somehow manages to be several hundred times slower in places.
We use judoscript at work. It lets us call java classes from a scripting language.
Not to flame, but why would _anyone_ in their right mind try to run a script inside java, of all things ! To my mind, if I want to be absurd, I would say this doesn't go far enough; why doesn't anyone invent a machine virtualisation layer inside said scripting language ? But all absurdity aside - I know java isn't up to scratch; it's a young language and its libraries aren't standardised, all-encompassing as they should be, and as they are in C or perl. But to get over this limitation by implementing a scripting language inside it is a bit rich; what, do you people _eat_ cpu-cycles for lunch or something ? Why isn't the time invested in producing said scripting language not instead invested in writing usefull libraries ? This just sounds like another tech that's written because you guys didn't stop to think whether you should, you only though that you could.
After a few months we were at abt. 85% done and then the shit hit the fan. I walked into the development room and then I heard this strange computer voice saying:
"Who the fuck are you?"
And I said, "I'm Cerberusss, and who the fuck are YOU?"
Computer: "I'll tell you who the fuck I am. I'm GroOOOOovy! Punch the green button!!"
At that point, I was shitting in my pants so I walked to my terminal and said: "OK, I'm punching the green button!" but instead, I punched the RED button.
The strange computer voice: "NooOOOOoooo You shouldn't!... have TOUched... the red.... buttonnnnn...."
Needless to say, I never went back to Groovy.
8 of 13 people found this answer helpful. Did you?
I wouldn't get too caught up in learning every dinky scripting language out there.. if you want to invest time learning a new language learn a primary language.. maybe a cool one like Haskel or Ocaml.
The ultimate "scripting" language is of course.. bash... or zsh. As long as you don't need to do too much math, you can do fairly complicated things in bash and do it *fast* by virtue of the fact that everything you do just launches a native binary, usually written in c, that's specialized for performing whatever task you are doing. Shell scripts also make it easy to do some parallelism via pipes.
Also, just launching the environment for a lot of other interpreted languages (java esp) takes longer than many bash scripts run.
Of course bash is oriented towards handling text files and has lots of limitations outside of that field (basic math operations require launching bc and storing results as strings in environment variables) but if you primarily do text manipulation, you can probably do it pretty darn fast and easy with bash.
I don't know Ruby, so I will use perl's map function as an example.
In Perl:
map { $_ * 2 } @arr;
In Java:
for( Integer key : arr ) { key *=2; }
Now exactly, what would be the benefit of having a map function in Java, aside from obfuscating things? Everything in Java is already a pointer so operations inside your for() loop are already altering the objects in the array or collection.
Intergalactic Digital Research (not DIR) was the original name of Digital Research (who sold CP/M and DR DOS) not Digital Equipment Corporation (selling the scrummy VAX minicomputers)
At least it uses brackets instead of depending on indentation .
Copyright infringement is "piracy" in the same way DRM is "consumer rape"
http://www.pythonthreads.com/news/latest/there-s-n o-compelling-reason-to-choose-groovy-over-jython.. html
I just saw this yesterday. Guillaume Laforge the project manager for Groovy
said if you already know python stick with jython if you don't have a reason to change.
I've used the rhino implementation of javascript as the basis for a scripting engine in a number of projects now. Javascript is lightweight, supports many useful idioms, and with rhino, integrates well with existing apps. Exposing your APIs to a scripting layer is pretty simple.
What particularly attracted me to rhino (apart from being a bit of a js nut) was the security model. That is to say, it has one, and it's pretty well worked out. It's typically nontrivial to add sandboxed scripting support to an application that integrates with the application's model of user permissions*: if you look around, you'll find lots of examples of various scripting languages being plumbed into applications, but typically the scripting layer is available to "admins only" due to these kinds of security concerns.
* even in java, which already has a semi-decent security model**
** It's a lot of work getting security providers to stack properly. Layering application-domain runtime security over an application running inside a container with its own security provider is barely doable.
If you do Java, Groovy and BeanShell (or DynamicJava) are the two scripting languages of your choice.
Main reason: the syntax and the class library of both scriptiing languages is: Java. Further more both languages allow you to type your variables (but as in most scripting languages types are optional, while Jython is always typeless --- and besides the wiered syntax of python, the main reason I don't use it: its variables are dynamic typed)
Groovy has disadvantages however. When groovy was "young" it was a very cool language. But then they descided to put up a JSR. During that they changed the syntax for lots of constructs, and not to the good but to the bad imho, now I don't really like it anymore as the reading of source code hurts my eyes, bah!
However for ppl who are not somewhat familiar to the old syntax Groovy might be perfect for you, so give it a try!
angel'o'sphere
Cost free eBook I read (by iBook/Kobo/Amazon/ObookO/Gutenberg etc.): "The Green Odyssey" by Philip Jose Farmer.
With the advent of each new scripting language the old ones seems to go to dust Take for example perl Perl is such a powerful language indeed but now it has taken a backseat and Php rules ! If a system can be put in place where new scripting languages like ruby php etc can take advantage of old languages and somehow integrate into them and old languages can still be used. Yes it will be an Utopian world !
Chris ,
Php Programmers.
Jacl is a fantastic scripting language for Java:. html
http://tcljava.sourceforge.net/docs/website/index
I also enjoy just using Javascript for this kind of thing. See the Rhino project:
http://www.mozilla.org/rhino/
MORTAR COMBAT!
For something different, you'll find SISC brings actual new expressability to the Java platform, rather than just scripting the same old stuff. This lets you do radically different things, as demonstrated by SISCweb, which allows you to write web applications without dealing with the stateless, page-centric nature of HTTP.
Plus, you'll learn Scheme, which will make you a better programmer.
I have been using it on a project for 9 months now it has been great to use. I haven't used Jython but I it's the only scripting language I've seen besides Rexx that defaults to using BigDecimal for numbers. Contrary to what many people write, it's not dead. My experience is that bugs get fixed relatively quickly. The project is definately moving closer to a 1.0 release. Most of the bugs that I've seen have been corner cases that don't affect 99% of what we do. Just my experience.
A language doesn't have to be updated every 20 seconds to be good. If you started off working in JPython, I don't understand why you would switch it out for a less supported, and less developed language. Python has been kicking around for a while, enough time that they got most of the major kinks out long ago, so I don't think "falling behind in the development cycle" is as crucial as you might think it is. Why not stay with what works unless you specifically REQUIRE the new version's functionality? People are too quick to be trendy with languages...
Judges and senates have been bought for gold; Esteem and love were never to be sold.
Was there a missing "not"? I mean there are surely Java programs than can be run in Groovy wihtout change, but there are also Ruby programs that can be run in Groovy without change. If you insist on typing then you maybe better use nice or scala. The core of Groovy is dynamic and with that it differs in essential parts to Java. Just because there is a much syntax in common doesn't mean that Groovy is Java
The sense I get is that there is a world of people reconciled to Java, and a world of people who have issues with it and want something else -- see RMS recent and recurring remarks about how Java hurts FOSS everywhere, everytime (or is it that other dude who has issues with Java numeric processing?).
I don't have to get in on the pissing context of t'is, t'ain't regarding whether to go with the Java or the anything-but-Java camps. On the other the divide is real. What I am wondering is if CPython is more in the anything-but-Java camp culturally, and hence the preference is to have people write Python extension modules in . . . C! I got a sense that jpype and that other thing that preceded it are not active, enthusiastically supported, or very complete.
On the other hand, if someone comes up with a good JNI bridge, you can use Java extension modules in Python as an option -- Jython is pretty much restricted to Java for extension modules. Hey, there is even a good ActiveX bridge in Python (actually two of them I know about), and ActiveX is as Microsoft-lock-in non-FOSS-friendly as it gets, and people didn't have to hold their noses to do it. But with Java, I get the sense that the enthusiasm is not quite there for a Java bridge.
To me, the advantage of scripting languages is that you can rapidly assemble applications from highly-functional components, components that aren't written in that scripting language, for legacy reasons or for performance reasons, and then you can interact with that application to do exploratory data analysis (for my work in signal processing) from a command prompt or can write a script to automate more complex analyses.
I believe I have seen a demo of an application written in Jython that uses Java Swing to produce a graphical scratchpad doodle area to make drawings, and then it has a text window with a Jython command prompt that you can do things to the scratchpad -- change the colors, erase, print, invert the picture, etc. Yes, you could interact with such an application by adding a menu, but the command prompt has access to component classes of the application and their methods to do exploratory analysis, testing, debugging, etc. The idea is that the application is written in Jython -- that way every GUI widget is a Jython object that you can poke at from the command prompt. On the other hand, the widgets themselves are Java Swing widgets -- either standard ones or new ones implemented using Java classes.
Matlab allows you to do this with ActiveX controls -- so does Python using the PyCrust/PyShell feature of wxPython. Matlab allows you to do this with Java Swing controls -- so does Jython (they tell me). There isn't a free thing that allows me to do both, but my druthers are to look to the future and develop my custom widgets in Java and use a Java/Jython type scripting language. RMS tells us not to do Java, but aside from ActiveX, aside from Java Swing, what out there allows you to develop custom widgets (not standard widgets -- everyone has that) and script them? Mono/.NET? What out there even hosts a .NET control apart from .NET -- Matlab doesn't, Python doesn't.
If you are interested in JVM languages, you might as well look at Pnuts. It runs roughly as fast as Lua.