The MetaSieve Blog

March 1, 2010

MagicNumbers: Dynamic Time and Byte Calculations for Grails – Using the Meta Object Protocol to add behaviour to Grails at runtime

Filed under: Uncategorized — Tags: , , — Björn Wilmsmann @ 1:00 pm

The March issue of GroovyMag, an online-only magazine for everything Groovy and Grails has been published today.

I’ve contributed an article about the Grails MagicNumbers plugin you might find interesting. Here’s a teaser:

Grails plugin development and Groovy‘s Meta Object Protocol are powerful tools for adding runtime modifications to standard Java classes. Introducing the new Grails MagicNumbers plugin, I’d like to show how metaprogramming in Groovy can be used to make code both more readable and easier to write. The MagicNumbers plugin allows you to write readable code like 3.days or 6.megabytes instead of having to manually calculate the equivalent number of seconds or bytes.

[ … ]

Code like this obviously has several advantages over manually calculating and writing the actual numbers:

  • It is written much more easily.
  • The code is much more readable. You can even show this code to someone who hasn’t any programming experience at all and she will immediately understand its purpose.
  • The code is less error-prone and thus more maintainable.

So, I wanted to have this kind of magic in Grails as well. Fortunately, due to Groovy’s Meta Object Protocol and the Grails plugin framework, this kind of functionality can be added quickly and elegantly.

[ … ]

Read the rest of this article at GroovyMag.

Related links:

Advertisements

Leave a Comment »

No comments yet.

RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Blog at WordPress.com.

%d bloggers like this: