|
|
Optimize with a SATA RAID Storage Solution
Range of capacities as low as $1250 per TB. Ideal if you currently rely on servers/disks/JBODs
Page 2 of 2
For some people, it's comforting to know that their investment in a language is protected by its adoption as a standard. This is one of the distinctive promises of Groovy. Since the passage of JSR-241, Groovy is the second standard language for the Java platform (the first being the Java language).
The size of the user base is a second criterion. The larger the user base, the greater the chance of obtaining good support and sustainable development. Groovy's user base is reasonably sized. A good indication is the activity on the mailing lists and the number of related projects.
Attraction is more than strategic considerations, however. Beyond what you can measure is a gut feeling that causes you to enjoy programming or not.
The developers of Groovy are aware of this feeling, and it is carefully considered when deciding upon language features. After all, there is a reason for the name of the language: "A situation or an activity that one enjoys or to which one is especially well suited (found his groove playing bass in a trio). A very pleasurable experience; enjoy oneself (just sitting around, grooving on the music). To be affected with pleasurable excitement. To react or interact harmoniously." [
Someone recently stated that Groovy was, "Java-stylish with a Ruby-esque feeling." We cannot think of a better description. Working with Groovy feels like a partnership between you and the language, rather than a battle to express what is clear in your mind in a way the computer can understand.
Of course, while it's nice to "feel the groove," you still need to pay your bills. In the next section, we'll look at some of the practical advantages Groovy will bring to your professional life.
Depending on your background and experience, you are probably interested in different features of Groovy. It is unlikely that anyone will require every aspect of Groovy in their day-to-day work, just as no one uses the whole of the mammoth framework provided by the Java standard libraries.
This section presents interesting Groovy features and areas of applicability for Java professionals, script programmers, and pragmatic, extreme, and agile programmers. We recognize that developers rarely have just one role within their jobs and may well have to take on each of these identities in turn. However, it is helpful to focus on how Groovy helps in the kinds of situations typically associated with each role.
If you consider yourself a Java professional, you probably have years of experience in Java programming. You know all the important parts of the Java Runtime API and most likely the APIs of a lot of additional Java packages.
But—be honest—there are times when you cannot leverage this knowledge, such as when faced with an everyday task like recursively searching through all files below the current directory. If you're like us, programming such an ad-hoc task in Java is just too much effort.
But as you will learn in this book, with Groovy you can quickly open the console and type: groovy -e "new File('.').eachFileRecurse { println it }" to print all filenames recursively.
Even if Java had an eachFileRecurse method and a matching FileListener interface, you would still need to explicitly create a class, declare a main method, save the code as a file, and compile it, and only then could you run it. For the sake of comparison, let's see what
the Java code would look like, assuming the existence of an appropriate eachFileRecurse method:
public class ListFiles { // JAVA !!
public static void main(String[] args) {
new java.io.File(".").eachFileRecurse(
new FileListener() {
public void onFile (File file) {
System.out.println(file.toString());
}
}
);
}
}
Notice how the intent of the code (printing each file) is obscured by the scaffolding code Java requires you to write in order to end up with a complete program.
Besides command-line availability and code beauty, Groovy allows you to bring dynamic behavior to Java applications, such as through expressing business rules, allowing smart configurations, or even implementing domain specific languages.
You have the options of using static or dynamic types and working with precompiled code or plain Groovy source code with on-demand compiling. As a developer, you can decide where and when you want to put your solution "in stone" and where it needs to be flexible. With Groovy, you have the choice.
This should give you enough safeguards to feel comfortable incorporating Groovy into your projects so you can benefit from its features.
As a script programmer, you may have worked in Perl, Ruby, Python, or other dynamic (non-scripting) languages such as Smalltalk, Lisp, or Dylan.
But the Java platform has an undeniable market share, and it's fairly common that folks like you work with the Java language to make a living. Corporate clients often run a Java standard platform (e.g., Java EE), allowing nothing but Java to be developed and deployed in production. You have no chance of getting your ultraslick scripting solution in there, so you bite the bullet, roll up your sleeves, and dig through endless piles of Java code, thinking all day, "If I only had [your language here], I could replace this whole method with a single line!" We confess to having experienced this kind of frustration.
Groovy can give you relief and bring back the fun of programming by providing advanced language features where you need them: in your daily work. By allowing you to call methods on anything, pass blocks of code around for immediate or later execution, augment existing library code with your own specialized semantics, and use a host of other powerful features, Groovy lets you express yourself clearly and achieve miracles with little code.
Just sneak the groovy-all-*.jar file into your project's classpath, and you're there.
Today, software development is seldom a solitary activity, and your teammates (and your boss) need to know what you are doing with Groovy and what Groovy is about.
If you fall into this category, you probably already have an overloaded bookshelf, a board full of index cards with tasks, and an automated test suite that threatens to turn red at a moment's notice. The next iteration release is close, and there is anything but time to think about Groovy. Even uttering the word makes your pair-programming mate start questioning your state of mind.
One thing that we've learned about being pragmatic, extreme, or agile is that every now and then you have to step back, relax, and assess whether your tools are still sharp enough to cut smoothly. Despite the ever-pressing project schedules, you need to sharpen the saw regularly. In software terms, that means having the knowledge and resources needed and using the right methodology, tools, technologies, and languages for the task at hand.
Groovy will be an invaluable tool in your box for all automation tasks that you are likely to have in your projects. These range from simple build automation, continuous integration, and reporting, up to automated documentation, shipment, and installation. The Groovy automation support leverages the power of existing solutions such as Ant and Maven, while providing a simple and concise language means to control them. Groovy even helps with testing, both at the unit and functional levels, helping us test-driven folks feel right at home.
Hardly any school of programmers applies as much rigor and pays as much attention as we do when it comes to self-describing, intention-revealing code. We feel an almost physical need to remove duplication while striving for simpler solutions. This is where Groovy can help tremendously.
Before Groovy, I used other scripting languages (preferably Ruby) to sketch some design ideas, do a spike—a programming experiment to assess the feasibility of a task—and run a functional prototype. The downside was that I was never sure if what I was writing would also work in Java. Worse, in the end, I had the work of porting it over or redoing it from scratch. With Groovy, I can do all the exploration work directly on my target platform.
The seamless interplay of Groovy and Java opens two dimensions of optimizing code: using Java for code that needs to be optimized for runtime performance, and using Groovy for code that needs to be optimized for flexibility and readability.
Along with all these tangible benefits, there is value in learning Groovy for its own sake. It will open your mind to new solutions, helping you to perceive new concepts when developing software, whichever language you use.
No matter what kind of programmer you are, we hope you are now eager to get some Groovy code under your fingers.
Andrew Glover is the president of Stelligent Incorporated. He actively blogs about software quality at thediscoblog.com and testearly.com.
Dr Paul King is managing director and principal consultant for ASERT, an Australian company specialising in helping its customers leverage emerging technologies. He has provided technical and strategic consulting to hundreds of organizations throughout the U.S. and Asia Pacific and is an active contributor to many open source projects.
As the official Groovy Project Manager and member of the JSR-241 Expert Group standardizing the Groovy Scripting Language, Guillaume Laforge is a passionate Groovy developer. In his professional career, Guillaume is a software architect and open source consultant, working for OCTO Technology, a company focusing on architecture of software and information systems
Jon Skeet is a software engineer and inveterate technological dabbler who happens to specialise in Java and C# development. A recent convert to Groovy, Jon is fanatical about using smarter ways to write cleaner, more readable code.
Archived Discussions (Read only)