Tuesday, January 27, 2009

Part 4: Thoughts of “How we do?” - A Story

A family arranged a trip. They were going by a van. Van was driven by a young driver, next to him a young family member. In the next row, father, mother and their child around 10 years old boy were seated. In the last row grandfather and grandmother were there.

On the way, a traffic signal, it is turned to red. So driver stopped the van. Now the little boy prompt a question “Why you stopped the van?” “The traffic signal is red” driver replied. He asked more “Why we have to stop if signal is red?” for that the young family member replied “If not police man will charge us”

The boy was not satisfied with that answer; He turned his head to back. Then grandfather tried to answer “We have to give way to others before we take”, “There should be a common rule to control”, “you have to wait for your chance”. While grandfather was continuing with his answer, boy had turned his head to his father, because he couldn’t understand those answer. Then father explained, in a junction, if all people try to go, then there will be no coordination. So we have to divide time between us and move one by one. For that there should a person or signal to indicate the time change. And finally if someone violating those rules, there should be police man or someone to check and punish.

After father’s explanation boy was fine. Let stop the story there, in the story, you may have noticed three different answers for one question “Why we have to stop?”

All three answers are right and related to same question. First answer which was from the young man, is talking about immediate input/output of the problem. This is a kind of technician mode of thinking. It is without thinking about others, just thinking how to kindle the present situation according to present observation. Or they may have trained to understand the situation and react according to that.

Second answer, the grandfather’s answer which is more conceptual, no worries about how to design. Scientists used to tell thing like this. More like theories, speaking in an ideal situation.

Final answer, that took care of design aspect, and explained how these are made into a practical working solution. This is an engineer mode of thinking, explained and analyzed the design.

Even though I have put different modes into different people, it doesn’t mean those are owned by only them. All we have those three modes of thinking with us. For each problem in our life, we react or understand things in one or some of the above modes. For every problem, the time to find a solution, the understanding or knowledge we have about the area of the problem and the role we play to solve the problem are decide the way in which we going to handle. In case, if we couldn’t find a solution with one mode, we may have to switch to another different mode as well.

So, it is important of understand these different mode of thinking, choose one or more and switch between them to solve our problems. It is nothing new, we all know this, but just to get to know and organize into you mind. 

Monday, January 19, 2009

Bits – Eclipse, Java.

In most of our programs, we used to start with hardcode string values and debug or test. If that work fine only we used to move to re-factor the code into more general program. I think that is easy also, because at first we don’t need to worry about other than the logics and necessary API calls. Here is a way to easily construct the strings with eclipse which I normally use when I am writing in Java.
Say for example I want to print some thing like this: “Hello user_name, you are user_age years old”, where user_name and user_age suppose to enter by the user from command prompt.

We will start with following:
System.out.println(“Hello Nimalan, you are 25 years old.”);//hardcode strings
We have to end with this:
System.out.println(“Hello ” + args[0] + “, you are ” + args[1] + “ years old.”);

So, in between the above string we have to put quotation markers and plus signs if we go and edit directly. But with out doing that try out following: 

First move the curser before N of Nimalan and press enter. Eclipse will add necessary quotation marks and plug signs for you. You will get like this: 
System.out.println(“Hello ”+
                                           “Nimalan, you are 25 years old”);
Now do the same after n of Nimalan then you will get following:
System.out.println(“Hello ”+
                                         “Nimalan” + 
                                         “, you are 25 years old”);
Ok now you can replace the “Nimalan” with args[0]. Can’t you do the same for 25 too?
This is just a small example, but this will be very useful in changing hardcode strings into variables, constants or into properties files. Enjoy! :).