Archive for the 'English' Category


Grails 1.1 is available! 0

Hello!

Good news for today!! I just got @ work and saw in my twitter that Graeme Rocher just updated Grails with the new Version 1.1. This is awesome!!

Here is his twitt: http://twitter.com/graemerocher/status/1305118282
Grails 1.1 release notes: http://www.grails.org/1.1+Release+Notes
Grails 1.1 documentation: http://grails.org/doc/1.1.x/

Some stuff I really liked and I thing will help the day-by-day development:

  • GORM is now independent from Grails
    • Yeah, that is correct, now you can use GORM’s god-blessed-methods in your own groovy project!
  • hasMany associations for primitive types
    • You can use hasMany for primitive types, eg. Strings. Remember that time you had to create one domain class just for encapsulate one string? Now you can have this! :D
  • Global plugins
    • For people that knows Ruby and Rails, this will be like a gem. You install the plugin once with the tag -global and will be available for all apps

Visit the links above and stay tuned!

You can follow me on twitter: http://twitter.com/lucastex
Take care!

The grooviest way to access the last item in a list 1

Hey!

Do you know that groovy provides a fuuny way to access the last item in a list? Let’s say you have the snippet above:

def lista = []
lista << “first item”
lista << “second item”
lista << “third item”

println lista[0] // “first item”
println lista[1] // “second item”
println lista[2] // “third item”

That’s ok hã. If you are using Java and needs to access the last item in this list, what should you do? I bet would be something like this (that is applicable to groovy):

lista.get(lista.size()-1); //Java
lista[lista.size -1] //groovy

I said “applicable” but doing this does not make me feel “groovier”… How about this trick?

lista[-1] //”third item”

That’s it! The indexes inside a list in groovy are “mirrored” backwards, so you can access the “first item from back to front” using the first negative integer! This is applicable to the rest of the entries:

println lista[-1] // “third item”
println lista[-2] // “second item”
println lista[-3] // “first item”

Take care!

[]s,

Web Analytics