Monday, February 8, 2010

Beware of the datatype char

I had the most unexpected and weirdest bug encountered recently, and this is probably the strongest argument to have a consistent testing (and sometimes even development) environment!

In our development environment, we are using a database schema that had two fields, status and reason, as varchar of 2 characters. This means that both fields would be up to 2 characters for storage.

And on the test, staging, production, we actually have the fields defined as char of 2 characters. This means that both fields would be using 2 characters for storage, even if it is a single character.

They are different database products, and me not being a database expert, declined to comment on the difference. Perhaps one of them did support varchar. Or maybe the other was more efficient with char. In any case, it sounded like it would still work. After all, the difference ought to be just on storage.

And I was so wrong. We had weir cases where some comparisons of the returned value failed.

On closer inspection, a value of 'A' from the database was in fact, 'A '! It was padded with whitespaces behind!

That took a while to find out, though fixing was easy. I'm gonna be careful about char from now on.

Friday, February 5, 2010

Meeting: Focus on problems the right way

When working on a particular problem, there are many times when we will be slapped with a particular restriction that prevents us from progressing forward in an ideal way.

When we looked at this from the outside, we are able to rationally decide that the logical solution here, is to work around the restriction, such that we are still able to progress forward, even if it is slower. Or sometimes, suggest to get rid of the restriction.

Yet, when we are part of the working team, we stumble, running around in circles, not going anywhere.

Imagine this scenario. You are in a meeting. You encounter a restriction. You report this to the others in the team. All you get is constant grilling on why this happen. And then asking for a solution. Then various brainstorming of solutions. Which many would not make sense, or unachievable. And then the meeting end without even a resolution. And then come the next meeting, and the restriction is reported again. And then comes the same round, and some finger pointing and blaming game.

This is highly destructive to the team dynamics, as restrictions or problems might go unmentioned simply because.. mentioning it does not help at all. Stabbing begin as people try to shift the focus to other people's problem than one's own. The grilling lowers a person's confidence. And of course, most importantly, nothing gets done. Meeting is essentially useless.

One of the critical use of meeting is to bring everyone up to date with what's happening in the team, and harnass the collective intelligence and authority of the team to resolve stumbling blocks of the project. And the above scenario does not do any of those.

A strong project manager is essential, to groom the right culture for meetings.

When face with a restriction, all the team need to know is, how the restriction would affect solving the problem. A restriction is not the problem.

Remember, the member had never intended for the restriction to be there. It was not his fault. It is a problem, and not HIS problem.

And lastly, but most importantly, a mindset shift. Stop focusing on what cannot be done (the restriction). Focus on what could be done. Review your available options. And how those options could help to work around the restrictions or solve the problem.

Look into ways to remove the restriction, or if impossible, work around the restrictions. If need be, change or review the original solution to the problem. Change the original solution if all else fails.

This does not only apply to work, but in life as well. Sometimes we are so struck with what we cannot do, we do not progress, and forget about what we could do instead.

Be positive when faced with problems or restrictions. Focus on what we can do, not what we cannot.

Monday, February 1, 2010

$200 is a lot

I recently was asked on how much pay raise I would want, after checking out the market rate and thinking about it I figured $200 should be a good amount.

It sounded little, but the more I think about it, the more it seemed to be alot.

After CPF deduction I would be taking home $160. That's more than my lunch budget for a month during work which is about 22 x $5. And it's my ezlink transport allowance for two months.

And that's about three months worth of phone bill, some 120 iPhone $0.99 applications. 8 movie tickets pair. 40 slice of cakes I could share with my girlfriend.

Put into such a perspective it does seem alot. Though I would like to draw an emphasis that if spent on basic necesscities one could survive quite a while on these minor increments. It's the desire of the luxuries that made such increments seemed very little. Notice how many pair of movie tickets one could get. That's not including the popcorns!

Now, and so here I inject a slight persuasion. Every christian should tithe 10% of their income. For that increment it would be just $20. When measured in such an amount, what we give to God seemed negliable. It's only when you start thinking it as $200 of $2000 do you feel it is alot.

But if you are not a Christian, you could still give such a negliable amount to some chairty. If ten of us do this, it should be able to fill someone's stomach for lunch out there.

Friday, January 29, 2010

Blog Readership

I recently began syndicating my blog posts into facebook. I'm not entirely sure if it is a good or bad idea.

The pro of syndication, is of course, that my social group on facebook gets to read what I write.

But sometimes i wonder, as not all my posts have them as the target audience. Some of them are rather heavy in technical details. Well to the uninterested they are just irrelevant blabbering.

On the other hand, this actually drives readership from my blog itself on blogger. Though I have to wonder. Who reads them anyway? Who am I writing to?

Well honestly, it doesn't matter too much. I love to write. I enjoy long, blabbering posts. Rambling on and on. Sometimes it discourages me, thinking no one reads them. So, in the early days, I probably do targetted writing. I write technical blog posts. Hoping they get index by google and have visitors.

But I stopped that. Technical blog posts are really hard to write. They take a lot of time and effort.

I realized that I just loved to express myself. I am slowly getting used to rambling in this sense. And my blog posts have been changing from technical to including opinions, and hope that soon they might even include personal and spritually.

The content might scare readers off. But I ask myself. Who am I writing for? Not the readers. Those are bonus. I write to express myself.

At times I wonder if I should seperate my blog posts. Perhaps my blog could contain everything, and facebook would be more social blog posts. I wonder if linkedin has blog syndication. Perhaps use posterous to control where my blog goes. But then again, being seen as a more regular blogger seemed to outweigh such benefits. If the technical blog was not updated for a long time, reader might felt it dead and ignored it. Might as well post everything and let the reader do their own sifting. Perhaps technical readers might be interested in non technical posts too.

I also pondered on posting links to my blog entries, instead of full syndication. But that's like shutting off the bulk of the readers, who might just happened on your update on facebook but do not wish to read furthur if they had to be brought elsewhere. Better to slam the post right in their face. Maybe I could link it on Twitter, but that's due to te nature of the platform.

Of all I'm curious on who my readers are, who either accidentally read my posts, or actually follow them. I signed up with google analytics, but those stats seemed to indicate that they found my posts via google, when they were looking for programming topics.

I also uses feedburner, and I seriously wonder who those 60+ subscribers are.

It comforts me vaguely that people read what I write.

Even if that person might be a bot or spider.

Monday, January 25, 2010

iPhone multi-tasking

As long as the iPhone had been out, we had been wishing for multi-tasking. Well, at least those of us overly-geeky enough to have a certain need to be satisfied. Most consumer would probably care less about it.

But there are at least two main cases which I can see multi-tasking can be helpful. Or rather, the proper term to use for this is background processing. Having the 'application' run in the background.

There are a few radio applications in the App Store (though sadly we don't have anything like Shazam or Pandora in Singapore). We really really would like a way to have the radio music carry on playing, just like iPod, even when the application is 'closed'. Imagine an SMS come in, and you launch the SMS. Your music that was previously playing would stop, because the application is considered to be closed! Surely, there must be a better approach.

Well, Apple surely could allow a simple new API call to allow application to register their music for background playing. And at any one time only a single stream of music (and associated application) could use it. And it would carry on playing even after the application is closed. Not too much to ask for, is it?

Another case is data download. Sure, Apple argued that Push Notifications is a more elegant solution. But when I use the in-built Safari browser, I really want to like, open up multiple pages, wait for them to finish loading, and read them one by one. From what I feel or observed, when I switch to a different page, the old page stops loading. And sometimes the memory gets swapped out.

You would argue that people only need to read one page at a time. Sure, that's what I'm doing. But as I read, I want to be able to go to the next page immediately, without waiting for the page to be downloaded. The download should happen in the background, and if I am on a computer, that's what I am doing. Opening the new page in the background so that I can read it next. Erm, yes, I have a slow ISP (or rather not fast enough). I could go blame them too...

So, beside Safari browser, another case which I might need background data download is my rss reader with Google Reader, using byline. Byline helps to cache the web page offline for quick read, and I set it up to do that for new items. But, as far as I know, this does not have push notifications, and it probably does not make sense too. I do not need byline to keep notifying me of all the news every second. It should behave like the manual fetch settings for my email accounts. Check every, say, 15 mins and download new content.

Could Apple not come up with a restrictive API for that? Queue an app to connect to the internet to download new content? It's technically possible, but because of battery drain and user experience, they are not doing that.

Maybe they could move the responsiblity to the consumers. Just like how applications ask to enable push notifications and GPS location checks, ask to enable background processing too. Let them know that it will affect battery power. Give background processes much lower priority so that they do not affect the running exclusive apps.

It's really very troublesome to do manual download of content, or open an app just to listen to music. When I launch an application, I want it to be ready for my use. Immediately. Not having it stay opened so that it can be in the process of 'getting ready to be used'.

Friday, January 22, 2010

Code comments

I used to have a rather strong stance on comments in code. Mostly in the form of avoiding them. I believe that the code IS the comment. If you had written clear code, you had no need to write comments. They would just be clutter in the most cases.

I still believe in what I just said, but recently, I had began writing more and more comments in my code.

That's because that despite clear code, sometimes it's useful to explain, in the code, why some things are done in some way.

To the coder (person who wrote the code), everything is clear. He might write two loops over the same list of objects, modifying them in different ways. He might have done that to keep the objects in a consistent state, to finish one set of operations before another.

Now, sometime later (or maybe just days), someone came along and notice this code. Why did the coder not merge both operations in a single loop? That would help in performance. He did not ask the coder, as the coder was unavailable. So he made the changes, run some basic tests, and check the code in.

And then a whole set of bugs appeared in the next few days.

This could have been avoided if the coder had commented in the code why he seperated the operations as two loops.

It is the same way in documentations. Rather than document just how things work, the documentation should explain why things work this way, why an approach was chosen, and why others might be discarded.

Anyone can figure out how things work, or how the code flow. But it is the why that is many a times missing. And we definitely need to document them in, both in code and doumentations.

Tuesday, January 19, 2010

Haiti earthquakes - my thoughts on Singapore's reaction

It was with great disappointment that I learnt that the Singapore government pledged only USD $50000 as aid to the Haiti who were just recently struck by a 7.0 earthquake on 12 Jan 2009. It was a terrible disaster, with over 200000 death so far.

The Haiti disaster has so far been described as the worst disaster the United Nation has experienced. Much of the Haitian government were destroyed. No not just the buildings, but the people too. 3 million people were affected, and the country is seriously damaged. The Port-au-Prince is a critical port of the country, where many resources are docked and unloaded to the country. With the port no longer in service due to the damages, many aids were unable to go into the country, with planes hovering around the airport trying to land but there were no space to.

Haiti had been a very poor country, the poorest in the western hemisphere, ranked 149th of the 182 countries registered.

Due to the massive amount of death, they are burying people in mass graves - Digging a big hole and dumping the dead bodies in. There was no time to do proper identification of the dead. Their concern had been to dispose of the bodies quickly to make room for those alive. Which means, a family can never know if a missing family member is dead or alive.

And food is running out of the country, and people are getting violent. The healthy people at least, had began looting. The others? Probably missing a limb or two, or still buried under the rambles.

So, 3 million people affected. USD $50000 of aid. That amounts to USD $0.0017 per person. Even Angelina Jolie and Brad Pitt is donating USD $1 million.

So, what could we do?

Well, we could be here and grumble about how much more the government should do and could do. Make complains and protests. While the haitians are suffering.

Or we could do our part. We could make our own donations or aids. World Vision Singapore is accepting online donations at http://www.worldvision.org.sg/CF-General.php?catID=18. And Singapore Red Cross is taking cheque donations and walk-in donations (refer to http://www.redcross.org.sg/Singapore-Red-Cross-Assists-IFRC-in-channeling-donations-for-relief-in-Haiti.phtml).

The government of Singapore might not be able to do much, but the people of Singapore can. And, if you want to protest against the government, do it positively. Make a donation today, so that the donation from the people of Singapore exceeds the amount the government is pledging. Make it a shame to them, that the people are contributing more to humanitarian cause, than the government is.

When others talk about Singapore, let them not remember about how little the Singapore government had donated, but rather how much the Singapore people did. We represent Singapore, our country. The country do not just belong to the government. The country is not just about the government. You and me make up the country.