Tuesday, September 3, 2013

Groovier way to swap values : Groovy

Before making swapping fashionable, classy and exciting, or in other word “Groovier”.

Let see what we do with our traditional Java to swap 2 values. If we use Java way, we need a method that perform 3 step process of swapping the value including declaration of additional variable.

In Java, what we do :

int a=1, b=2, temp;

temp=a;
a=b;
b=temp;
println “a=${a}, b=${b}”

//Output : a=2, b=1

In Groovy, using closure make it more simpler :

def a=1, b=2;
def swap = {x,y → a=y; b=x;}
swap(a,b)
println “a=${a}, b=${b}”

//Output : a=2, b=1

Naaaaah! But still it's not classy or cool enough to be Groovier. Let go more Groovy like real real Groovy.



Being more Groovier, Aha! getting more excited to see magic and power of a Groovy :

def a=1, b=2;
(a,b)=[b,a]

//Output : a=2, b=1

Whoa! Wat was that do I just swap 2 values (a,b)=[b,a] and done all in single line. :D

So are you still on 80's, 90's coding style or planning to join 21st Century... ;)

Hope it helps! ;)

Sunday, September 1, 2013

Intro : Expression that say Hi.....

Expression undefined,
Running back of my head,
Each word defining some expression,
and making a pile of a stack,
Some words are beautiful, 
Some make smile,
Some make memories come alive,
Some help in sorrow, 
Some help in pain,
Some make parties live and heart live again,
Some words in prayer make people come alive,
Some words makes people die,
Some words make beautiful memories that's hard to built,
Some words just die in guilt,
and some words mend all the life tilt...

Bunch of words are there to say,
It not hard to put together when heart says,
Just trying to expressing my thoughts in words, hope you stay :P

I am working as an Software Engineer being writing the code,
Don't mind if my language above get bit odd... :D
Working on Groovy/Grails, still lot to explore,
I will be writing about tech, poem, fun and lot more.

Love to listen music, like to watch movies,
In sport formula 1 watching is one of my hobbies,
I don't drink and I don't smoke, 
In my school dayz I liked to watch different strokes,
I am vegetarian it's not hard, :D
In morning cup of coffee is a good way to start.

Hope my blogs play some part, 
some resolve your queries,
and some are fun to start....

This is my intro, expressed in words,
Just trying to make my first blog a little bit fun! <3

Hi to all and have fun!!!!