Thursday, September 27, 2007

Lazy Initialization Complacency Syndrome

I and a friend of mine were debugging her code for a problem and I couldn't crack it at first. She later debugged it and asked me to crack it and when I did, I was kicking myself. Decided to blog it for others' benefit :)

The code snippet is something like below:


public void addToMap(Object key, Object value)
{
    if(member_map == null)
    {
        member_map = new HashMap<Object, Object> ();
    }
    else
    {
        member_map.put(key, value);
    }
}


It simply lazy-initializes a map that is a class member variable and adds the key-value pair to the map. We tested it with 2 records fetched from a database table and tried to print the contents. We expected two records, but only the last record was stored onto the map and this kept us guessing for a long time.

The problem here is in the if-else part. For the first record, the map is null and it gets lazy-initialized. And the 'put' call was in the else loop, so the first record never got stored!


Three lessons

1. Do not else-ify lazy-initialization: When you lazy-initialize, put the null check in if condition, but do not add an else to it. The code should have been:


public void addToMap(Object key, Object value)
{
    if(member_map == null)
    {
        member_map = new HashMap<Object, Object> ();
    }
    // No "else"
    member_map.put(key, value);
}

2. The importance of quantitative and qualitative test data: What we did was a typical case of testing with insufficient data. We shouldn't have tested only with two records, we should have tested with more numbers. That way, the problem would have been obvious.

3. Thinking out-of-box: We couldn't crack it coz d problem was in the perception with which we thought about it. It wasn't that only the last record was stored, rather it was that the first record was NOT stored.

And I thought I could wash away the sin of not cracking it only by spreading the lesson, hence the blog :)

Friday, September 21, 2007

Tears of solitude

I sit by the window,
Transparent as the glass,
The black blanket of sky echoing my thought,
Storm across the ocean raging into my mind,
Breaking the silence as she broke my heart.

I sit by the window,
Oblivious to the blinding pain, the cut wrist,
Perspicacity dwindling with every passing second,
Perception no more a clear thought, there I see,
The soft lips and the stone heart blend,
Open hands and curved lips calling me.

I sit by the window,
Not a word spoken, no gratitude expressed,
And I let her go because the wind can’t stay,
Though it leaves behind wounds that hurt,
Phantasms that drift, anger that kills,
Eyes of tears and broken windmills.

I sit by the window,
No hands to hold, no smiles to cherish,
No breath to kiss, no love to live,
Last of mortality leaving the heaving lungs,
A desperate tear clinging to desolate eyes,
I realize dying moments are the blissful ones ..
At last the storm has swelled to its possible high,
I look out the glass one last time,
Tears of solitude pouring from the sky.

Friday, September 14, 2007

Govindha Bhavan

A mild afternoon, rather lazy, one of those times you do not want to flaunt your money on a restuarant like Red-e or save too much in a kaiyendhi bhavan, you would rather settle for a mess (not chaos, this is a south-indian version of a fast-food center that specifically serves meals and some limited tiffin items), and you know you are living in an area that is referred to as "The Bachelors' Paradise" - There is an abundance of such fast food chains/lodges/restuarants/hotels and you start thinking of where to get a modest meal. It was this kinda day, and I was wondering where to satisfy my mild hunger. And that's when I remembered, there was one place I hadn't visited for a long time. Amidst all the hustle bustle of a thickly populated shore, named Triplicane, there is one mess that has been standing humble and silent for a long time, and it has fed thousands and thousands of hungry stomach and not-so-rich pockets till date.

It is simply named "Govindha Bhavan" - What a name! Sounds simple to the common man's ears, but still has a rich legend, and those who have feasted themselves to a hearty meal here will not refuse the treat they have subjected their taste buds to - repeatedly.


I remember eating in Govindha Bhavan since my school days - Those days when you wear shorts and look that age. It dates back to about 15 years, as a 10 year old, I remember holding my father's hand and walking on dim-yet-pleasantly-lit nights towards the door of bliss. Back then, it served food on wooden benches in a house under thatched roof with an open space in the middle that in no way imitates a waiting reception. There were no sofas or cushions to seat the customers, not a TV to entertain the eagerly waiting mind, not an AC to keep things cool. It was plain open to the sky, and people did not mind standing, awaiting their turn. There was a big old radio, that played old film songs when tuned to the city AM channels (there were no big FM stations then). I also remember the corner that had a leaking tap, a bucket and a mug that is supposed to be the washbasin.

All these lack of sophistication never really mattered to the minds that frequented this haven. The blend of sambar and rice mixed together to form a mound is a smell that your nostrils will never ever forget once they have smelt it. And lo! The poriyal and kootu that are supposed to be the side dishes actually become the main dishes, served unlimited. The rasam is one of the best you can ever drink and the grand finale with thick curd, more and more-mulagai with elumichampazha oorugai (lemon pickle) is just the actual combination named elixir.

There was only one better and more famous mess named Mithra Bhavan that was the topmost favourite of almost all bachelors who lived in Triplicane then. But all good things must come to an end and this closed down, only to make Govindha Bhavan the most sought after mess. The looks have changed now, the mess has been shifted to a building two blocks away and given a fast-food look. The management might have changed, back then it was managed by a family, not a management, so the food tasted closer to home. It still serves a limited meal for Rs.20 (roughly half-a-dollar!). The cuisine has been expanded to chinese, north indian and it now also serves tiffin items in the evening in addition to plain rice.

Well, I was all nostalgic when I gulped down my plate of rice and came out of these memories only after I had finished it clean. And then I thought I owed a blog to the family that once served food to the hungry stomach of many bachelors of Triplicane.

Labels: , , ,

Thursday, September 13, 2007

Sravan Pens ..

It is easy to lose love than to find it; What is difficult is to find it again!

They say Time and Tide wait for none - Tide doesn't wait for anyone, yes, but for time, it is man who doesn't wait.

Object-Orientation is like a mild evening kiss! Do not overdo, keep it clean and simple; you are conceptualizing, not having sex.

Love is all about getting used to a person; Initially, you want to get used, and later, you don't want to not get used.

Love is when "You Idiot!" becomes "My Idiot!".

Shall keep adding more as I come up with ..

Sunday, September 09, 2007

I have come to understand ..

I have come to understand ..

- That the more you love someone, the more they hurt you.
- That they hurt you, because only they can hurt you.
- That it is possible to lose love over someone if you really want to.
- That tongues not only kiss, but also slash, cut, bleed and hurt.
- That people judge you wrong by one action even if they had judged you right by thousands.
- That all it takes is a second to bring down dreams built over years.
- That every rose comes with its share of thorns.
- That a bleeding heart is heavy, even for a strong mind with reason.
- That life is unfair and you dont get all you deserve.
- That time kills.

- That love is all about getting used to a person.
- That it is a sorry that heals the hurt and not beer.
- That the key to your heart is yourself : you can't get hurt unless you want to.
- That it is sometimes good to let go.
- That sweet butter separately is better than bitter taste together.
- That it is only your conscience to which you are accountable.
- That it takes years to build a dream and patience to keep them intact.
- That thorns are what that make the rose worth it.
- That a bleeding heart still beats, for life is to live.
- That time spent with friends laughing is better than time spent waiting in vain.
- That there is a child in everyone of us: so it is OK to cry.
- That time heals.

To the known unknown ..




Doubts that rise in thy heart,
Shall be overcome by my love.
And the days shan't do us apart,
Though shadows cover the dove.

The same beach will behold us,
In the face of the dawning dew,
Hand in hand, I will say thus,
With all my soul, I love you!