Groovy Rocked My World!

April 28, 2007

Regardless of the aspect of life, trying to ensure that you take advantage of all the opportunities that knock on your door is next to impossible (especially if you are caught up killing spam all day). I consider myself remarkably diligent at staying on the leading (bleeding?) edge of the technology curve. However, like everyone else, I too have blinders. Today, I learned what my blinders have been hiding from me: Groovy. After sitting through an introduction to Groovy given by Scott Davis at the No Fluff, Just Stuff conference, I am experiencing a paradigm shift. My eyes are revealing to me Wavy Gravy. Where have I been??? During the talk, I had to delete all the gibberish from the screen that my jaw had pounded out when it dropped onto my keyboard. I should have listened to James Strachan back in 2004 when he nonchalantly dropped me the hint, "Groovy is just so...groooovy." Since Groovy only hit 1.0 this past December, I certainly haven't missed the boat, so I'm not going to beat myself over it. But, I do need to jump into now without delay.

If Ruby makes you happy, then Groovy makes you sexy, baby! The Groovy syntax is so concise, readable, and logical that you have to wonder why you would torture yourself with native Java syntax ever again. I like how Scott Davis mediates this debate. "You should use the right tool for the job. When Groovy is appropriate, use Groovy. When Java is appropriate, use Java." Makes sense. You certainly would not want to implement Hibernate in Groovy. You could, however, write application code that uses Hibernate in Groovy. Beautiful. I can already think of a number of other possibilities for using Groovy. Unit tests implemented in Groovy are already a well-paved path, especially given that GroovyTestCase is part of the core language. JSF components written in Groovy are another terrific possibility, and would make component development much easier to stomach. My favorite idea, though, is to use Groovy to create Maven 2 plugins. For that, I can think of a perfectly fitting name: Groovy Mojo!

One of the reasons that my first impression of Groovy is leaving such a strong impression can be attributed to my programming background. I started out my programming career at Border's. No, really! I would move from one shelf to another picking up the next language that enticed me. At that time I was working on my P.H.D. (sort of) at USCB. I woke up one morning and realized that I was a software developer in a Material Science graduate student's shoes. So, I went out and found a job as a web developer. I spent the next 5 years developing in scripting languages, which included PHP, Perl, and JavaScript. I even created a couple of my own open source projects built using these languages. There is no doubt that I was committed to them. During those years, I was almost militant in my disdain for Java. Then, I woke up one morning and realized that Java wasn't all bad, which I attribute entirely to Struts. I had seen the light! But even after handing my career over to Java, I never really turned my back on scripting. I will admit, though, that I have to hide my affinity for scripting languages while trying to evangelize Java. I feel guilty every time I smile when writing JavaScript code based on Prototype. Thanks to Groovy, I no longer have to live in shame! Finally, there is a happy medium. Finally, I can do all the cool things I did with PHP and still take advantage of all the great engineering investment in Java. I can deploy the Groovy code to a JavaEE container and get all of its benefits as well.

So what do I think is so sexy about Groovy? From just a very brief exposure, I picked up on...

  • transparent generation of getter and setter methods
  • named arguments (param:"value") for methods
  • groovysh interactive interpreter (similar to Ruby's and Python's interactive shell)
  • multi-line, HEREDOC style strings using """
  • variable interpolation (EL expressions) in strings
  • system commands executed directly from a string
  • and the list goes on...

Understand that the breadth of Groovy's strengths is wider than just the syntax. The killer feature is the two-way communication and integration between Groovy and Java. This language isn't a one off like BeanShell, Jython, or Rhino. You can start using this today where ever you use Java. Spring 2.0 even let's you use Groovy script files, read from the classpath, as beans that can be injected into other beans. Groovy can be compiled to Java bytecode and run just like any other compiled Java code (a very grooovy CAFEBABE). I can see myself converting all my little shell scripts into Groovy. I can see myself writing my unit tests in Groovy. I cannot wait to get started. Hold the boat!

Posted at 01:03 AM in Java | Permalink Icon Permalink | Comment Icon Comments (3)

Broken Access Keys in Firefox 2.0

April 06, 2007

At least, that was the title of an e-mail that I received from one of our product managers yesterday. Of course, I couldn't believe that this was true, so I immediately decided to do some digging. As it turns out, access keys in Firefox 2.0 are not really "broken", they have just changed. You just need to know the trick for using them, or reverting them to the old behavior, and perhaps an understanding of why the Firefox team made the switch.

For those of you who are not familiar with access keys, they are a browser feature that map sequences of keystrokes to HTML page elements so that those elements can be focused and activated using only the keyboard. An example would be associating the letter "S" with the primary submit button on the page. Typically, this feature is activated by pressing the Alt modifier key in combination with the character assigned to the page element. In the example, the user would press Alt+S, which would move the cursor to the submit button and activate it as if it were clicked.

However, the problem with this convention is that it allows the access keys to conflict with the reserved keystroke combinations that are used to control functions in either the browser or the operating system. Therefore, the Firefox team instrumented a new default for access keys in Firefox 2.0. Instead of being triggered by the Alt modifier key, access keys in Firefox 2.0 are now activated using the Shift+Alt combination modifier in conjunction with the character key. That means that you now have to hold down not just two, but three keys to make them work! If you don't like the new gymnastics that your fingers have to perform, then, like most features in Firefox, you can change the setting to make it work the way it used to back in version 1.5.

Below is a list of instructions for making the change. I will go slow so that everyone can follow along.

  1. Open a new browser window or tab in Firefox 2.0.
  2. Type about:config in the location bar.
  3. Press enter. This will bring up a configuration window with a text input above it named Filter.
  4. Type ui.key.contentAccess into the Filter input box.
  5. The filter will narrow down the list of "Preference Names" to the single line item of interest.
  6. Right-click your mouse button on this line-item to bring up a small drop-down menu and then select Modify from that drop down menu.
  7. Enter a value of 4 in the prompt that appears and press OK.
  8. You're all done! Close that window or tab and you will be back to Firefox 1.5 behavior for access keys.

Firefox access key preference

To find additional information about this setting, please see the ui.key.contentAccess wiki page on the MozillaZine site.

Posted at 06:00 PM in Usability | Permalink Icon Permalink | Comment Icon What, no comments?