Category Archives: Groovy

Nomin – Mapping Java Objects Without the Pain

Many best practices in the Java world involve mapping Java objects to other Java objects. More often than not, this is downright stupid. Both objects are more or less identical, but you have to write a lot of code to map object A to object B. Plus, you have to write the backward mapping, too. It goes without saying that this is a very error-prone task. Not to mention it’s boring as hell, making the task even more error-prone.

This is why I start to roll my eyes every time someone asks me to map objects. Granted, the underlying design pattern has its virtues. Decoupling the front-end code from the back-end code gives you a lot of flexibility. But do you need this flexibility? Even if you do, is it worth the pain?

Mapping objects automatically

Nomin to the rescue. It’s one of those little tools that come in handy. It allows you to write very compact Groovy scripts to map object. Even better, if the attribute names of the objects are identical, Nomin is able to figure out how to map the objects without you help. You don’t have to write a script at all. All you have to do is to invoke Nomin and have it map the objects for you:

NominMapper nomin = new Nomin();
EntityA entityA = nomin.map(entityB, EntityA.class);

Continue reading

Newsflash: Hope for Groovy

Pivotal’s recent announcement to drop both Groovy and Grails shook the Groovy community. The entire Java community, actually. Can we afford to invest in an open source project run by a company? Companies are sold and bought all the time, and the new owner may drop the previous owner’s pet projects without warning. That’s the story of Groovy and Grails.

I can’t help but wonder what that means to other projects. What if management decides to cut costs by releasing a project to freedom? You get the point: this move cost a lot of trust in frameworks run by a company. Any company, actually.

Among other things, the affair shows that open source isn’t a free lunch. Why don’t you support a project you’re fond of? It’s easy: tweet about it, or report a bug. You may even complain about the lousy documentation. That’s not a big deal, but it helps the developers a lot. They learn their documentation is read, and start to improve it.

At least in the case of Groovy, there’s hope. Guillaume Laforge, the public face of Groovy, has found a new job at a company that uses Groovy for their products. He won’t be able to work on Groovy full-time, but still, Guillaumes statement on reddit sounds encouraging:

Of course Groovy lives on! And I’ll still be wearing my Groovy hat on, even if only part time during my day job at Restlet. The project will indeed continue to be developed, with new features, performance improvements, more Java 8 related features, etc. We’re also going to announce in the coming days that the project is joining a foundation, to make the project more resilient!

That’s the second good news, provided it comes true. The Groovy project isn’t going to be homeless, but will be run by a foundation, which hopefully gives it an opportunity to flourish as lively as it did in the past.

Dig deeper

Guillaume Laforge joins Restlet
Let’s make APIs Grooyer
Discussion on reddit on the topic
InfoQ on the future of Groovy
Pivotal’s announcement to drop Groovy and Grails

Groovy’s Tiny O-R-Mapper

Do you like Hibernate or EclipseLink because of it’s simplicity? It’s true, JPA is very simple once you’ve got it up and running, but it’s not the most simple way to access a database. The easiest way to access a database I know is SQLWindows (aka Centura), with Groovy a close second. Native Groovy, that is. I’m not speaking of Grails.

Groovy uses some clever meta-programming to do its magic. The result almost resembles a simple O-R-mapper – although it’s not an O-R-mapper at all.
Continue reading

Java 8’s Optional Type, NullPointerExceptions and the Elvis Operator

Sooner or later every Java programmer is maddened by the notorious NullPointerException. Not only Java programmers, by the way. Probably every JVM programmer is suffering from the problem, and many other languages know similar problems.

What makes the NullPointerException so annoying is the fact is essentially a NotImplementedYetException in disguise.

Continue reading

Java 8 – Catalyst for a Superior Language?

These days I’ve read two language-related stories at Lavalobby. The first story I read matched my own experience on the topic. It has also an refreshingly optimistic air. Obviously, the author believes in progress. The second article also had a lot of ideas matching my experience.

Thing is, both articles contradict each other.

While the first article expects Java 8 to be merely a catalyst giving rise to more innovative languages, the second article insists that Java is here to stay. It the programming world’s lingua franca, and it won’t be replaced by a fancy new language.

Both articles have a point.
Continue reading

JavaFX and GroovyFX: One Program, Two Flavors

Tiles are popular. Picturesque tiles are a part of portuguese and spanish culture since countless1 centuries. Since a couple of years tiles are ubiquitous in our smart phones. My photography site 11pictures.com needed a fresh new design to cope with the always-increasing number of pictures. So what about displaying pictures as colorful azulejos?

To do so, I cobbled together a small JavaFX application. Later I ported it to GroovyFX. Read on to learn about the advantages and disadvantages of either version.
Continue reading

  1. all right: five centuries, if you must know. 🙂

JavaFX and GroovyFX: Two Frameworks You May Have Missed

Like most Java programmers I’ve gradually become a web developer during the last years. In a way, that’s strange: most projects don’t deal with the internet. It’s a pity, too. Browsers used to be dedicated tool for the internet, so it’s hard to meet the demands of an full-blown desktop application. It’s a real pain to integrate Excel sheets seamlessly into a web applications. So what about desktop GUI frameworks? There’s an interesting Java framework you most probably know by name without ever having looked at: JavaFX. It makes for nice-looking GUIs, and it matches Java 8 pretty good. Combine it with GroovyFX to get GUI classes that strongly resemble JSF files. Without suffering from JSF’s inherent complexity.
Continue reading

Groovy Rocks! Most of the Time :)

Let’s have a look at the JSF magician I presented a couple of days ago. Writing this program was a lot of fun. It felt like the Groovy designers had my JSF magician in mind when they invented the Groovy language. It contains a lot of code that make Groovy shine. Or rather, it contains little code that makes Groovy shine: There simply isn’t much code that can shine. Groovy allows for some very compact syntax. When I wrote the predecessor of the JSF magician, I wrote it in Java, and it was a lot more verbose.
Continue reading

A Simple Class Parser

One of my pet projects needs a description of every class in the workspace. It only needs the names of the variables and methods, so a few lines of Groovy code suffice to do the job. The source code shows how elegant and concise source code can be if you use a language that is optimized for the task. Feel free to use the source code if you need it.
Continue reading